diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 2eb5ad49a..954ac8cbf 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -595,71 +595,6 @@ parameters: count: 1 path: src/PhpSpreadsheet/Shared/Trend/Trend.php - - - message: "#^Cannot use array destructuring on array\\|false\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls.php - - - - message: "#^Offset 'endCoordinates' does not exist on array\\|null\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls.php - - - - message: "#^Offset 'endOffsetX' does not exist on array\\|null\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls.php - - - - message: "#^Offset 'endOffsetY' does not exist on array\\|null\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls.php - - - - message: "#^Offset 'startCoordinates' does not exist on array\\|null\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls.php - - - - message: "#^Offset 'startOffsetX' does not exist on array\\|null\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls.php - - - - message: "#^Offset 'startOffsetY' does not exist on array\\|null\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls.php - - - - message: "#^Parameter \\#1 \\$blipType of method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Escher\\\\DggContainer\\\\BstoreContainer\\\\BSE\\:\\:setBlipType\\(\\) expects int, int\\|null given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls.php - - - - message: "#^Parameter \\#1 \\$data of method PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\Escher\\\\DggContainer\\\\BstoreContainer\\\\BSE\\\\Blip\\:\\:setData\\(\\) expects string, string\\|false given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\:\\:\\$documentSummaryInformation \\(string\\) in isset\\(\\) is not nullable\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\:\\:\\$summaryInformation \\(string\\) in isset\\(\\) is not nullable\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\BIFFwriter\\:\\:writeEof\\(\\) has no return type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls/BIFFwriter.php - - - - message: "#^Static property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\BIFFwriter\\:\\:\\$byteOrder \\(int\\) in isset\\(\\) is not nullable\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls/BIFFwriter.php - - message: "#^Elseif condition is always true\\.$#" count: 1 @@ -680,41 +615,6 @@ parameters: count: 1 path: src/PhpSpreadsheet/Writer/Xls/Escher.php - - - message: "#^Cannot access offset 'encoding' on array\\|false\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls/Workbook.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Workbook\\:\\:writeAllDefinedNamesBiff8\\(\\) has no return type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls/Workbook.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Workbook\\:\\:writeExternalsheetBiff8\\(\\) has no return type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls/Workbook.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Workbook\\:\\:writeMsoDrawingGroup\\(\\) has no return type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls/Workbook.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Workbook\\:\\:writeSupbookInternal\\(\\) has no return type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls/Workbook.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Workbook\\:\\:\\$biffSize is never read, only written\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls/Workbook.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Workbook\\:\\:\\$colors has no type specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls/Workbook.php - - message: "#^Cannot access offset 'comp' on array\\|false\\.$#" count: 1 @@ -814,13 +714,3 @@ parameters: message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Worksheet\\:\\:\\$xlsStringMaxLength is never read, only written\\.$#" count: 1 path: src/PhpSpreadsheet/Writer/Xls/Worksheet.php - - - - message: "#^Parameter \\#1 \\$textRotation of static method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Xf\\:\\:mapTextRotation\\(\\) expects int, int\\|null given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls/Xf.php - - - - message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Xf\\:\\:\\$diag is never read, only written\\.$#" - count: 1 - path: src/PhpSpreadsheet/Writer/Xls/Xf.php diff --git a/src/PhpSpreadsheet/Writer/Xls.php b/src/PhpSpreadsheet/Writer/Xls.php index dd36eec92..33a404d42 100644 --- a/src/PhpSpreadsheet/Writer/Xls.php +++ b/src/PhpSpreadsheet/Writer/Xls.php @@ -201,14 +201,14 @@ class Xls extends BaseWriter $this->documentSummaryInformation = $this->writeDocumentSummaryInformation(); // initialize OLE Document Summary Information - if (isset($this->documentSummaryInformation) && !empty($this->documentSummaryInformation)) { + if (!empty($this->documentSummaryInformation)) { $OLE_DocumentSummaryInformation = new File(OLE::ascToUcs(chr(5) . 'DocumentSummaryInformation')); $OLE_DocumentSummaryInformation->append($this->documentSummaryInformation); } $this->summaryInformation = $this->writeSummaryInformation(); // initialize OLE Summary Information - if (isset($this->summaryInformation) && !empty($this->summaryInformation)) { + if (!empty($this->summaryInformation)) { $OLE_SummaryInformation = new File(OLE::ascToUcs(chr(5) . 'SummaryInformation')); $OLE_SummaryInformation->append($this->summaryInformation); } @@ -317,14 +317,16 @@ class Xls extends BaseWriter $twoAnchor = \PhpOffice\PhpSpreadsheet\Shared\Xls::oneAnchor2twoAnchor($sheet, $coordinates, $offsetX, $offsetY, $width, $height); - $spContainer->setStartCoordinates($twoAnchor['startCoordinates']); - $spContainer->setStartOffsetX($twoAnchor['startOffsetX']); - $spContainer->setStartOffsetY($twoAnchor['startOffsetY']); - $spContainer->setEndCoordinates($twoAnchor['endCoordinates']); - $spContainer->setEndOffsetX($twoAnchor['endOffsetX']); - $spContainer->setEndOffsetY($twoAnchor['endOffsetY']); + if (is_array($twoAnchor)) { + $spContainer->setStartCoordinates($twoAnchor['startCoordinates']); + $spContainer->setStartOffsetX($twoAnchor['startOffsetX']); + $spContainer->setStartOffsetY($twoAnchor['startOffsetY']); + $spContainer->setEndCoordinates($twoAnchor['endCoordinates']); + $spContainer->setEndOffsetX($twoAnchor['endOffsetX']); + $spContainer->setEndOffsetY($twoAnchor['endOffsetY']); - $spgrContainer->addChild($spContainer); + $spgrContainer->addChild($spContainer); + } } // AutoFilters @@ -416,7 +418,7 @@ class Xls extends BaseWriter ob_end_clean(); $blip = new Blip(); - $blip->setData($blipData); + $blip->setData("$blipData"); $BSE = new BSE(); $BSE->setBlipType($blipType); @@ -427,11 +429,12 @@ class Xls extends BaseWriter private function processDrawing(BstoreContainer &$bstoreContainer, Drawing $drawing): void { - $blipType = null; + $blipType = 0; $blipData = ''; $filename = $drawing->getPath(); - [$imagesx, $imagesy, $imageFormat] = getimagesize($filename); + $imageSize = getimagesize($filename); + $imageFormat = empty($imageSize) ? 0 : ($imageSize[2] ?? 0); switch ($imageFormat) { case 1: // GIF, not supported by BIFF8, we convert to PNG diff --git a/src/PhpSpreadsheet/Writer/Xls/BIFFwriter.php b/src/PhpSpreadsheet/Writer/Xls/BIFFwriter.php index 4a7e06563..9d961b712 100644 --- a/src/PhpSpreadsheet/Writer/Xls/BIFFwriter.php +++ b/src/PhpSpreadsheet/Writer/Xls/BIFFwriter.php @@ -42,7 +42,7 @@ class BIFFwriter /** * The byte order of this architecture. 0 => little endian, 1 => big endian. * - * @var int + * @var ?int */ private static $byteOrder; @@ -175,7 +175,7 @@ class BIFFwriter /** * Writes Excel EOF record to indicate the end of a BIFF stream. */ - public function writeEof() + public function writeEof(): string { $record = 0x000A; // Record identifier $length = 0x0000; // Number of bytes to follow diff --git a/src/PhpSpreadsheet/Writer/Xls/Workbook.php b/src/PhpSpreadsheet/Writer/Xls/Workbook.php index a46b86d5c..6e9b265dc 100644 --- a/src/PhpSpreadsheet/Writer/Xls/Workbook.php +++ b/src/PhpSpreadsheet/Writer/Xls/Workbook.php @@ -55,13 +55,13 @@ class Workbook extends BIFFwriter private $parser; /** - * The BIFF file size for the workbook. + * The BIFF file size for the workbook. Not currently used. * * @var int * * @see calcSheetOffsets() */ - private $biffSize; + private $biffSize; // @phpstan-ignore-line /** * XF Writers. @@ -163,6 +163,8 @@ class Workbook extends BIFFwriter /** * Color cache. + * + * @var array */ private $colors; @@ -581,7 +583,7 @@ class Workbook extends BIFFwriter * Writes all the DEFINEDNAME records (BIFF8). * So far this is only used for repeating rows/columns (print titles) and print areas. */ - private function writeAllDefinedNamesBiff8() + private function writeAllDefinedNamesBiff8(): string { $chunk = ''; @@ -886,7 +888,7 @@ class Workbook extends BIFFwriter /** * Write Internal SUPBOOK record. */ - private function writeSupbookInternal() + private function writeSupbookInternal(): string { $record = 0x01AE; // Record identifier $length = 0x0004; // Bytes to follow @@ -901,7 +903,7 @@ class Workbook extends BIFFwriter * Writes the Excel BIFF EXTERNSHEET record. These references are used by * formulas. */ - private function writeExternalsheetBiff8() + private function writeExternalsheetBiff8(): string { $totalReferences = count($this->parser->references); $record = 0x0017; // Record identifier @@ -1060,7 +1062,7 @@ class Workbook extends BIFFwriter $headerinfo = unpack('vlength/Cencoding', $string); // currently, this is always 1 = uncompressed - $encoding = $headerinfo['encoding']; + $encoding = $headerinfo['encoding'] ?? 1; // initialize finished writing current $string $finished = false; @@ -1155,7 +1157,7 @@ class Workbook extends BIFFwriter /** * Writes the MSODRAWINGGROUP record if needed. Possibly split using CONTINUE records. */ - private function writeMsoDrawingGroup() + private function writeMsoDrawingGroup(): string { // write the Escher stream if necessary if (isset($this->escher)) { diff --git a/src/PhpSpreadsheet/Writer/Xls/Xf.php b/src/PhpSpreadsheet/Writer/Xls/Xf.php index b2dbc67ac..7ac26665c 100644 --- a/src/PhpSpreadsheet/Writer/Xls/Xf.php +++ b/src/PhpSpreadsheet/Writer/Xls/Xf.php @@ -116,10 +116,7 @@ class Xf */ private $rightBorderColor; - /** - * @var int - */ - private $diag; + //private $diag; // theoretically int, not yet implemented /** * @var int @@ -148,7 +145,7 @@ class Xf $this->foregroundColor = 0x40; $this->backgroundColor = 0x41; - $this->diag = 0; + //$this->diag = 0; $this->bottomBorderColor = 0x40; $this->topBorderColor = 0x40; @@ -254,7 +251,7 @@ class Xf $biff8_options |= (int) $this->style->getAlignment()->getShrinkToFit() << 4; $data = pack('vvvC', $ifnt, $ifmt, $style, $align); - $data .= pack('CCC', self::mapTextRotation($this->style->getAlignment()->getTextRotation()), $biff8_options, $used_attrib); + $data .= pack('CCC', self::mapTextRotation((int) $this->style->getAlignment()->getTextRotation()), $biff8_options, $used_attrib); $data .= pack('VVv', $border1, $border2, $icv); return $header . $data;