diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 40b3f8d76..9bb44ade0 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1028,14 +1028,6 @@ parameters: message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\:\\:\\$root \\(PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS\\\\Root\\) in isset\\(\\) is not nullable\\.$#" count: 1 path: src/PhpSpreadsheet/Shared/OLE.php - - - message: "#^Parameter \\#2 \\$offset of function array_slice expects int, float given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Shared/OLE/PPS.php - - - message: "#^Parameter \\#3 \\$length of function array_slice expects int\\|null, float given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Shared/OLE/PPS.php - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS\\:\\:\\$_data \\(string\\) in isset\\(\\) is not nullable\\.$#" count: 1 @@ -1064,34 +1056,6 @@ parameters: message: "#^Parameter \\#1 \\$No of method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS\\:\\:__construct\\(\\) expects int, null given\\.$#" count: 1 path: src/PhpSpreadsheet/Shared/OLE/PPS/Root.php - - - message: "#^Parameter \\#1 \\$iSBDcnt of method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS\\\\Root\\:\\:saveHeader\\(\\) expects int, float given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Shared/OLE/PPS/Root.php - - - message: "#^Parameter \\#1 \\$iSbdSize of method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS\\\\Root\\:\\:saveBbd\\(\\) expects int, float given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Shared/OLE/PPS/Root.php - - - message: "#^Parameter \\#1 \\$iStBlk of method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS\\\\Root\\:\\:saveBigData\\(\\) expects int, float given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Shared/OLE/PPS/Root.php - - - message: "#^Parameter \\#2 \\$iBBcnt of method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS\\\\Root\\:\\:saveHeader\\(\\) expects int, float given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Shared/OLE/PPS/Root.php - - - message: "#^Parameter \\#2 \\$iBsize of method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS\\\\Root\\:\\:saveBbd\\(\\) expects int, float given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Shared/OLE/PPS/Root.php - - - message: "#^Parameter \\#3 \\$iPPScnt of method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS\\\\Root\\:\\:saveHeader\\(\\) expects int, float given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Shared/OLE/PPS/Root.php - - - message: "#^Parameter \\#3 \\$iPpsCnt of method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS\\\\Root\\:\\:saveBbd\\(\\) expects int, float given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Shared/OLE/PPS/Root.php - message: "#^Parameter \\#4 \\$prev of method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLE\\\\PPS\\:\\:__construct\\(\\) expects int, null given\\.$#" count: 1 @@ -1140,10 +1104,6 @@ parameters: message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\OLERead\\:\\:\\$wrkbook has no type specified\\.$#" count: 1 path: src/PhpSpreadsheet/Shared/OLERead.php - - - message: "#^Strict comparison using \\=\\=\\= between int and null will always evaluate to false\\.$#" - count: 1 - path: src/PhpSpreadsheet/Shared/OLERead.php - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Trend\\\\BestFit\\:\\:calculateGoodnessOfFit\\(\\) has parameter \\$const with no type specified\\.$#" count: 1 @@ -1684,10 +1644,6 @@ parameters: message: "#^Expression on left side of \\?\\? is not nullable\\.$#" count: 1 path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php - - - message: "#^Parameter \\#1 \\$coordinates of static method PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Coordinate\\:\\:indexesFromString\\(\\) expects string, string\\|null given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php - message: "#^Parameter \\#1 \\$string of function strlen expects string, string\\|false given\\.$#" count: 1 diff --git a/src/PhpSpreadsheet/Shared/OLE.php b/src/PhpSpreadsheet/Shared/OLE.php index 5c95d795b..815b1c16c 100644 --- a/src/PhpSpreadsheet/Shared/OLE.php +++ b/src/PhpSpreadsheet/Shared/OLE.php @@ -117,7 +117,7 @@ class OLE public function read($filename) { $fh = fopen($filename, 'rb'); - if (!$fh) { + if ($fh === false) { throw new ReaderException("Can't open file $filename"); } $this->_file_handle = $fh; @@ -349,7 +349,7 @@ class OLE if ($pps->Type == self::OLE_PPS_TYPE_DIR || $pps->Type == self::OLE_PPS_TYPE_ROOT) { $nos = [$pps->DirPps]; $pps->children = []; - while ($nos) { + while (!empty($nos)) { $no = array_pop($nos); if ($no != -1) { $childPps = $this->_list[$no]; diff --git a/src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php b/src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php index ac9fcb004..ee93c05e1 100644 --- a/src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php +++ b/src/PhpSpreadsheet/Shared/OLE/ChainedBlockStream.php @@ -161,7 +161,7 @@ class ChainedBlockStream } elseif ($whence == SEEK_CUR && -$offset <= $this->pos) { $this->pos += $offset; // @phpstan-ignore-next-line - } elseif ($whence == SEEK_END && -$offset <= count($this->data)) { + } elseif ($whence == SEEK_END && -$offset <= count(/** @scrutinizer ignore-type */ $this->data)) { $this->pos = strlen($this->data) + $offset; } else { return false; diff --git a/src/PhpSpreadsheet/Shared/OLE/PPS.php b/src/PhpSpreadsheet/Shared/OLE/PPS.php index 8b9e92a88..d3d86f5a5 100644 --- a/src/PhpSpreadsheet/Shared/OLE/PPS.php +++ b/src/PhpSpreadsheet/Shared/OLE/PPS.php @@ -220,7 +220,7 @@ class PPS $raList[$cnt]->NextPps = 0xFFFFFFFF; $raList[$cnt]->DirPps = self::savePpsSetPnt($raList, @$raList[$cnt]->children, $depth++); } else { - $iPos = floor(count($to_save) / 2); + $iPos = (int) floor(count($to_save) / 2); $aPrev = array_slice($to_save, 0, $iPos); $aNext = array_slice($to_save, $iPos + 1); $cnt = count($raList); diff --git a/src/PhpSpreadsheet/Shared/OLE/PPS/Root.php b/src/PhpSpreadsheet/Shared/OLE/PPS/Root.php index fa92fd5db..3fe8af2ac 100644 --- a/src/PhpSpreadsheet/Shared/OLE/PPS/Root.php +++ b/src/PhpSpreadsheet/Shared/OLE/PPS/Root.php @@ -84,17 +84,17 @@ class Root extends PPS // calculate values for header [$iSBDcnt, $iBBcnt, $iPPScnt] = $this->calcSize($aList); //, $rhInfo); // Save Header - $this->saveHeader($iSBDcnt, $iBBcnt, $iPPScnt); + $this->saveHeader((int) $iSBDcnt, (int) $iBBcnt, (int) $iPPScnt); // Make Small Data string (write SBD) $this->_data = $this->makeSmallData($aList); // Write BB - $this->saveBigData($iSBDcnt, $aList); + $this->saveBigData((int) $iSBDcnt, $aList); // Write PPS $this->savePps($aList); // Write Big Block Depot and BDList and Adding Header informations - $this->saveBbd($iSBDcnt, $iBBcnt, $iPPScnt); + $this->saveBbd((int) $iSBDcnt, (int) $iBBcnt, (int) $iPPScnt); return true; } @@ -110,7 +110,6 @@ class Root extends PPS { // Calculate Basic Setting [$iSBDcnt, $iBBcnt, $iPPScnt] = [0, 0, 0]; - $iSmallLen = 0; $iSBcnt = 0; $iCount = count($raList); for ($i = 0; $i < $iCount; ++$i) { diff --git a/src/PhpSpreadsheet/Shared/OLERead.php b/src/PhpSpreadsheet/Shared/OLERead.php index 91f1d044b..b3e35c505 100644 --- a/src/PhpSpreadsheet/Shared/OLERead.php +++ b/src/PhpSpreadsheet/Shared/OLERead.php @@ -164,7 +164,6 @@ class OLERead $pos += 4 * $bbs; } - $pos = 0; $sbdBlock = $this->sbdStartBlock; $this->smallBlockChain = ''; while ($sbdBlock != -2) { @@ -186,7 +185,7 @@ class OLERead /** * Extract binary stream data. * - * @param int $stream + * @param ?int $stream * * @return null|string */ diff --git a/src/PhpSpreadsheet/Writer/Xls/Workbook.php b/src/PhpSpreadsheet/Writer/Xls/Workbook.php index ccffa181b..fa7349daf 100644 --- a/src/PhpSpreadsheet/Writer/Xls/Workbook.php +++ b/src/PhpSpreadsheet/Writer/Xls/Workbook.php @@ -173,6 +173,9 @@ class Workbook extends BIFFwriter */ private $escher; + /** @var mixed */ + private static $scrutinizerFalse = false; + /** * Class constructor. * @@ -249,7 +252,7 @@ class Workbook extends BIFFwriter $xfWriter->setDiagColor($this->addColor($style->getBorders()->getDiagonal()->getColor()->getRGB())); // Add the number format if it is not a built-in one and not already added - if ($style->getNumberFormat()->getBuiltInFormatCode() === false) { + if ($style->getNumberFormat()->getBuiltInFormatCode() === self::$scrutinizerFalse) { $numberFormatHashCode = $style->getNumberFormat()->getHashCode(); if (isset($this->addedNumberFormats[$numberFormatHashCode])) { @@ -591,7 +594,7 @@ class Workbook extends BIFFwriter // parse formula try { - $error = $this->parser->parse($range); + $this->parser->parse($range); $formulaData = $this->parser->toReversePolish(); // make sure tRef3d is of type tRef3dR (0x3A) @@ -873,7 +876,7 @@ class Workbook extends BIFFwriter // sheet type $st = 0x00; - $grbit = 0x0000; // Visibility and sheet type + //$grbit = 0x0000; // Visibility and sheet type $data = pack('VCC', $offset, $ss, $st); $data .= StringHelper::UTF8toBIFF8UnicodeShort($sheetname); @@ -907,7 +910,7 @@ class Workbook extends BIFFwriter $record = 0x0017; // Record identifier $length = 2 + 6 * $totalReferences; // Number of bytes to follow - $supbook_index = 0; // FIXME: only using internal SUPBOOK record + //$supbook_index = 0; // FIXME: only using internal SUPBOOK record $header = pack('vv', $record, $length); $data = pack('v', $totalReferences); for ($i = 0; $i < $totalReferences; ++$i) { diff --git a/src/PhpSpreadsheet/Writer/Xls/Worksheet.php b/src/PhpSpreadsheet/Writer/Xls/Worksheet.php index 78fda5174..2fef1e36a 100644 --- a/src/PhpSpreadsheet/Writer/Xls/Worksheet.php +++ b/src/PhpSpreadsheet/Writer/Xls/Worksheet.php @@ -1091,7 +1091,6 @@ class Worksheet extends BIFFwriter } $record = 0x01B8; // Record identifier - $length = 0x00000; // Bytes to follow // Strip URL type and change Unix dir separator to Dos style (if needed) // @@ -1127,18 +1126,18 @@ class Worksheet extends BIFFwriter $dir_short = (string) preg_replace('/\\.\\.\\\\/', '', $dir_long) . "\0"; // Store the long dir name as a wchar string (non-null terminated) - $dir_long = $dir_long . "\0"; + //$dir_long = $dir_long . "\0"; // Pack the lengths of the dir strings $dir_short_len = pack('V', strlen($dir_short)); - $dir_long_len = pack('V', strlen($dir_long)); + //$dir_long_len = pack('V', strlen($dir_long)); $stream_len = pack('V', 0); //strlen($dir_long) + 0x06); // Pack the undocumented parts of the hyperlink stream $unknown1 = pack('H*', 'D0C9EA79F9BACE118C8200AA004BA90B02000000'); $unknown2 = pack('H*', '0303000000000000C000000000000046'); $unknown3 = pack('H*', 'FFFFADDE000000000000000000000000000000000000000'); - $unknown4 = pack('v', 0x03); + //$unknown4 = pack('v', 0x03); // Pack the main data stream $data = pack('vvvv', $row1, $row2, $col1, $col2) . @@ -1242,7 +1241,6 @@ class Worksheet extends BIFFwriter $record = 0x023E; // Record identifier $length = 0x0012; - $grbit = 0x00B6; // Option flags $rwTop = 0x0000; // Top row visible in window $colLeft = 0x0000; // Leftmost column visible in window @@ -1605,7 +1603,7 @@ class Worksheet extends BIFFwriter $x = $column - 1; $y = $row - 1; - [$leftMostColumn, $topRow] = Coordinate::indexesFromString($this->phpSheet->getTopLeftCell()); + [$leftMostColumn, $topRow] = Coordinate::indexesFromString($this->phpSheet->getTopLeftCell() ?? ''); //Coordinates are zero-based in xls files $rwTop = $topRow - 1; $colLeft = $leftMostColumn - 1; @@ -1650,7 +1648,6 @@ class Worksheet extends BIFFwriter $iPageStart = 0x01; // Starting page number $iFitWidth = (int) $this->phpSheet->getPageSetup()->getFitToWidth(); // Fit to number of pages wide $iFitHeight = (int) $this->phpSheet->getPageSetup()->getFitToHeight(); // Fit to number of pages high - $grbit = 0x00; // Option flags $iRes = 0x0258; // Print resolution $iVRes = 0x0258; // Vertical print resolution @@ -2433,7 +2430,7 @@ class Worksheet extends BIFFwriter { // Open file. $bmp_fd = @fopen($bitmap, 'rb'); - if (!$bmp_fd) { + if ($bmp_fd === false) { throw new WriterException("Couldn't import $bitmap"); } @@ -2766,7 +2763,7 @@ class Worksheet extends BIFFwriter $rt = 0x088B; // 2 $grbitFrt = 0x0000; // 2 - $reserved = 0x0000000000000000; // 8 + //$reserved = 0x0000000000000000; // 8 $wScalvePLV = $this->phpSheet->getSheetView()->getZoomScale(); // 2 // The options flags that comprise $grbit @@ -2902,8 +2899,8 @@ class Worksheet extends BIFFwriter } // Pattern $bFillStyle = ($conditional->getStyle()->getFill()->getFillType() === null ? 0 : 1); - $bFillColor = ($conditional->getStyle()->getFill()->getStartColor()->getARGB() == null ? 0 : 1); - $bFillColorBg = ($conditional->getStyle()->getFill()->getEndColor()->getARGB() == null ? 0 : 1); + $bFillColor = ($conditional->getStyle()->getFill()->getStartColor()->getARGB() === null ? 0 : 1); + $bFillColorBg = ($conditional->getStyle()->getFill()->getEndColor()->getARGB() === null ? 0 : 1); if ($bFillStyle == 0 || $bFillColor == 0 || $bFillColorBg == 0) { $bFormatFill = 1; } else { @@ -2919,7 +2916,7 @@ class Worksheet extends BIFFwriter || $conditional->getStyle()->getFont()->getSubscript() !== null || $conditional->getStyle()->getFont()->getUnderline() !== null || $conditional->getStyle()->getFont()->getStrikethrough() !== null - || $conditional->getStyle()->getFont()->getColor()->getARGB() != null + || $conditional->getStyle()->getFont()->getColor()->getARGB() !== null ) { $bFormatFont = 1; } else {