diff --git a/src/PhpSpreadsheet/Calculation/TextData/Replace.php b/src/PhpSpreadsheet/Calculation/TextData/Replace.php index 1515864659..3c9bed539e 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Replace.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Replace.php @@ -113,6 +113,6 @@ private static function executeSubstitution(string $text, string $fromText, stri --$instance; } - return Functions::scalar(self::REPLACE($text, ++$pos, StringHelper::countCharacters($fromText), $toText)); + return (string) Functions::scalar(self::REPLACE($text, ++$pos, StringHelper::countCharacters($fromText), $toText)); } } diff --git a/src/PhpSpreadsheet/Chart/Layout.php b/src/PhpSpreadsheet/Chart/Layout.php index f64f53319b..2b2175fe69 100644 --- a/src/PhpSpreadsheet/Chart/Layout.php +++ b/src/PhpSpreadsheet/Chart/Layout.php @@ -486,9 +486,9 @@ public function setLabelFontColor(?ChartColor $chartColor): self { if ($this->labelFont === null) { $this->labelFont = new Font(); - $this->labelFont->setSize(null, true); + $this->labelFont->/** @scrutinizer ignore-call */ setSize(null, true); } - $this->labelFont->setChartColorFromObject($chartColor); + $this->labelFont->/** @scrutinizer ignore-call */ setChartColorFromObject($chartColor); return $this; } diff --git a/src/PhpSpreadsheet/Helper/Downloader.php b/src/PhpSpreadsheet/Helper/Downloader.php index 4e98c7925c..4eafe0238c 100644 --- a/src/PhpSpreadsheet/Helper/Downloader.php +++ b/src/PhpSpreadsheet/Helper/Downloader.php @@ -40,10 +40,11 @@ public function __construct(string $folder, string $filename, ?string $filetype } $filetype ??= pathinfo($filename, PATHINFO_EXTENSION); - if (array_key_exists(strtolower($filetype), self::CONTENT_TYPES) === false) { + $filetypeLower = strtolower(/** @scrutinizer ignore-type */ $filetype); + if (array_key_exists($filetypeLower, self::CONTENT_TYPES) === false) { throw new Exception("Invalid filetype: {$filetype} cannot be downloaded"); } - $this->filetype = strtolower($filetype); + $this->filetype = $filetypeLower; } public function download(): void diff --git a/src/PhpSpreadsheet/Helper/Sample.php b/src/PhpSpreadsheet/Helper/Sample.php index fb40dd884e..d632635073 100644 --- a/src/PhpSpreadsheet/Helper/Sample.php +++ b/src/PhpSpreadsheet/Helper/Sample.php @@ -132,7 +132,7 @@ public function write(Spreadsheet $spreadsheet, $filename, array $writers = ['Xl $this->logWrite($writer, $path, /** @scrutinizer ignore-type */ $callStartTime); if ($this->isCli() === false) { // @codeCoverageIgnoreStart - echo 'Download ' . basename($path) . '
'; + echo 'Download ' . basename($path) . '
'; // @codeCoverageIgnoreEnd } } diff --git a/src/PhpSpreadsheet/IOFactory.php b/src/PhpSpreadsheet/IOFactory.php index 454b2aae40..ace60f381a 100644 --- a/src/PhpSpreadsheet/IOFactory.php +++ b/src/PhpSpreadsheet/IOFactory.php @@ -146,7 +146,7 @@ public static function createReaderForFile(string $filename, ?array $readers = n // First, lucky guess by inspecting file extension $guessedReader = self::getReaderTypeFromExtension($filename); - if (($guessedReader !== null) && array_key_exists($guessedReader, $testReaders)) { + if (array_key_exists($guessedReader, $testReaders)) { $reader = self::createReader($guessedReader); // Let's see if we are lucky @@ -173,11 +173,11 @@ public static function createReaderForFile(string $filename, ?array $readers = n /** * Guess a reader type from the file extension, if any. */ - private static function getReaderTypeFromExtension(string $filename): ?string + private static function getReaderTypeFromExtension(string $filename): string { $pathinfo = pathinfo($filename); if (!isset($pathinfo['extension'])) { - return null; + return ''; } return match (strtolower($pathinfo['extension'])) { @@ -205,8 +205,8 @@ private static function getReaderTypeFromExtension(string $filename): ?string // Do nothing // We must not try to use CSV reader since it loads // all files including Excel files etc. - 'csv' => null, - default => null, + 'csv' => '', + default => '', }; } diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index 7f29194d9d..d1aa64cb49 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -498,7 +498,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet $rels = $this->loadZip(self::INITIAL_FILE, Namespaces::RELATIONSHIPS); $propertyReader = new PropertyReader($this->getSecurityScannerOrThrow(), $excel->getProperties()); - $chartDetails = []; + $charts = $chartDetails = []; foreach ($rels->Relationship as $relx) { $rel = self::getAttributes($relx); $relTarget = (string) $rel['Target']; diff --git a/src/PhpSpreadsheet/Shared/Drawing.php b/src/PhpSpreadsheet/Shared/Drawing.php index edaad86153..eba152cd53 100644 --- a/src/PhpSpreadsheet/Shared/Drawing.php +++ b/src/PhpSpreadsheet/Shared/Drawing.php @@ -166,7 +166,7 @@ public static function angleToDegrees($angle): int public static function imagecreatefrombmp($bmpFilename): GdImage { $retVal = @imagecreatefrombmp($bmpFilename); - if ($retVal === false) { + if (!($retVal instanceof GdImage)) { throw new ReaderException("Unable to create image from $bmpFilename"); } diff --git a/src/PhpSpreadsheet/Style/ConditionalFormatting/CellMatcher.php b/src/PhpSpreadsheet/Style/ConditionalFormatting/CellMatcher.php index 3c815e4ac7..08671d9b09 100644 --- a/src/PhpSpreadsheet/Style/ConditionalFormatting/CellMatcher.php +++ b/src/PhpSpreadsheet/Style/ConditionalFormatting/CellMatcher.php @@ -262,7 +262,7 @@ protected function processDuplicatesComparison(Conditional $conditional): bool self::COMPARISON_DUPLICATES_OPERATORS[$conditional->getConditionType()], $worksheetName, $this->conditionalRange, - $this->cellConditionCheck($this->cell->getCalculatedValue()) + $this->cellConditionCheck(/** @scrutinizer ignore-type */ $this->cell->getCalculatedValue()) ); return $this->evaluateExpression($expression); diff --git a/src/PhpSpreadsheet/Worksheet/BaseDrawing.php b/src/PhpSpreadsheet/Worksheet/BaseDrawing.php index f25b050656..fa82ef6a5c 100644 --- a/src/PhpSpreadsheet/Worksheet/BaseDrawing.php +++ b/src/PhpSpreadsheet/Worksheet/BaseDrawing.php @@ -214,8 +214,8 @@ public function setWorksheet(?Worksheet $worksheet = null, bool $overrideOld = f // Add drawing to \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet if ($worksheet !== null) { $this->worksheet = $worksheet; - $this->worksheet->getCell($this->coordinates); - $this->worksheet->getDrawingCollection()->append($this); + $worksheet->getCell($this->coordinates); + $worksheet->getDrawingCollection()->append($this); } } else { if ($overrideOld) { diff --git a/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php b/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php index 817816b191..b391035300 100644 --- a/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php +++ b/src/PhpSpreadsheet/Worksheet/MemoryDrawing.php @@ -63,8 +63,9 @@ public function __construct() public function __destruct() { if ($this->imageResource) { - @imagedestroy($this->imageResource); - $this->imageResource = null; + $nullValue = null; + $rc = @imagedestroy($this->imageResource); + $this->imageResource = $rc ? null : $nullValue; } $this->worksheet = null; } @@ -156,7 +157,7 @@ public static function fromString(string $imageString): self $renderingFunction = self::identifyRenderingFunction($mimeType); $drawing = new self(); - $drawing->setImageResource($gdImage); + $drawing->setImageResource(/** @scrutinizer ignore-type */ $gdImage); $drawing->setRenderingFunction($renderingFunction); $drawing->setMimeType($mimeType); diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php b/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php index 6c01911c4e..23904ef237 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php @@ -1311,15 +1311,14 @@ private function writeCellFormula(XMLWriter $objWriter, string $cellValue, Cell $objWriter->endElement(); } else { $objWriter->writeElement('f', FunctionPrefix::addFunctionPrefixStripEquals($cellValue)); - self::writeElementIf( - $objWriter, - $this->getParentWriter()->getOffice2003Compatibility() === false + if ( + $calculatedValue !== null + && !is_array($calculatedValue) + && $this->getParentWriter()->getOffice2003Compatibility() === false && $this->getParentWriter()->getPreCalculateFormulas() - && $calculatedValue !== null, - 'v', - (!is_array($calculatedValue) && !str_starts_with($calculatedValue ?? '', '#')) - ? StringHelper::formatNumber($calculatedValue) : '0' - ); + ) { + $objWriter->writeElement('v', StringHelper::formatNumber($calculatedValue)); + } } }