Skip to content

Commit 753af27

Browse files
committed
Phpstan Bleeding Edge Part 3: Writer
1 parent c531f5d commit 753af27

File tree

14 files changed

+80
-168
lines changed

14 files changed

+80
-168
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -424,83 +424,3 @@ parameters:
424424
message: "#^Strict comparison using \\!\\=\\= between string and null will always evaluate to true\\.$#"
425425
count: 1
426426
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
427-
428-
-
429-
message: "#^Binary operation \"\\.\\=\" between array\\|string and non\\-falsy\\-string results in an error\\.$#"
430-
count: 1
431-
path: src/PhpSpreadsheet/Writer/Html.php
432-
433-
-
434-
message: "#^Instanceof between PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart and PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Chart will always evaluate to true\\.$#"
435-
count: 1
436-
path: src/PhpSpreadsheet/Writer/Html.php
437-
438-
-
439-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\AutoFilter and null will always evaluate to true\\.$#"
440-
count: 1
441-
path: src/PhpSpreadsheet/Writer/Ods/AutoFilters.php
442-
443-
-
444-
message: "#^Strict comparison using \\!\\=\\= between int and null will always evaluate to true\\.$#"
445-
count: 1
446-
path: src/PhpSpreadsheet/Writer/Ods/Content.php
447-
448-
-
449-
message: "#^Parameter \\#1 \\$image of callable passed to call_user_func\\(\\) expects GdImage, GdImage\\|null given\\.$#"
450-
count: 1
451-
path: src/PhpSpreadsheet/Writer/Xls.php
452-
453-
-
454-
message: "#^Static property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\BIFFwriter\\:\\:\\$byteOrder \\(int\\|null\\) is never assigned null so it can be removed from the property type\\.$#"
455-
count: 1
456-
path: src/PhpSpreadsheet/Writer/Xls/BIFFwriter.php
457-
458-
-
459-
message: "#^Call to function is_string\\(\\) with string will always evaluate to true\\.$#"
460-
count: 3
461-
path: src/PhpSpreadsheet/Writer/Xls/CellDataValidation.php
462-
463-
-
464-
message: "#^PHPDoc tag @var with type float\\|int\\|string is not subtype of native type mixed\\.$#"
465-
count: 1
466-
path: src/PhpSpreadsheet/Writer/Xls/ConditionalHelper.php
467-
468-
-
469-
message: "#^Call to function is_string\\(\\) with string will always evaluate to true\\.$#"
470-
count: 1
471-
path: src/PhpSpreadsheet/Writer/Xls/Style/CellBorder.php
472-
473-
-
474-
message: "#^PHPDoc tag @var with type callable is not subtype of native type string\\.$#"
475-
count: 1
476-
path: src/PhpSpreadsheet/Writer/Xlsx.php
477-
478-
-
479-
message: "#^PHPDoc tag @var with type string is not subtype of native type non\\-empty\\-array\\|non\\-falsy\\-string\\.$#"
480-
count: 1
481-
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
482-
483-
-
484-
message: "#^Parameter &\\$plotGroupingType by\\-ref type of method PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xlsx\\\\Chart\\:\\:writePlotGroup\\(\\) expects string, string\\|null given\\.$#"
485-
count: 1
486-
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
487-
488-
-
489-
message: "#^Strict comparison using \\!\\=\\= between array\\|PhpOffice\\\\PhpSpreadsheet\\\\RichText\\\\RichText\\|string and null will always evaluate to true\\.$#"
490-
count: 3
491-
path: src/PhpSpreadsheet/Writer/Xlsx/Chart.php
492-
493-
-
494-
message: "#^Call to function is_array\\(\\) with array\\<string\\> will always evaluate to true\\.$#"
495-
count: 1
496-
path: src/PhpSpreadsheet/Writer/Xlsx/StringTable.php
497-
498-
-
499-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\RichText\\\\RichText and null will always evaluate to true\\.$#"
500-
count: 1
501-
path: src/PhpSpreadsheet/Writer/Xlsx/StringTable.php
502-
503-
-
504-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\ConditionalFormatting\\\\ConditionalFormatValueObject and null will always evaluate to true\\.$#"
505-
count: 2
506-
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php

src/PhpSpreadsheet/Worksheet/MemoryDrawing.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class MemoryDrawing extends BaseDrawing
3333

3434
/**
3535
* Rendering function.
36+
*
37+
* @var callable-string
3638
*/
3739
private string $renderingFunction;
3840

@@ -161,6 +163,7 @@ public static function fromString(string $imageString): self
161163
return $drawing;
162164
}
163165

166+
/** @return callable-string */
164167
private static function identifyRenderingFunction(string $mimeType): string
165168
{
166169
return match ($mimeType) {
@@ -261,6 +264,8 @@ public function setImageResource(?GdImage $value): static
261264

262265
/**
263266
* Get rendering function.
267+
*
268+
* @return callable-string
264269
*/
265270
public function getRenderingFunction(): string
266271
{
@@ -270,7 +275,7 @@ public function getRenderingFunction(): string
270275
/**
271276
* Set rendering function.
272277
*
273-
* @param string $value see self::RENDERING_*
278+
* @param callable-string $value see self::RENDERING_*
274279
*
275280
* @return $this
276281
*/

src/PhpSpreadsheet/Writer/Html.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -569,16 +569,14 @@ private function extendRowsAndColumns(Worksheet $worksheet, int &$colMax, int &$
569569
{
570570
if ($this->includeCharts) {
571571
foreach ($worksheet->getChartCollection() as $chart) {
572-
if ($chart instanceof Chart) {
573-
$chartCoordinates = $chart->getTopLeftPosition();
574-
$this->sheetCharts[$chartCoordinates['cell']] = $chart;
575-
$chartTL = Coordinate::indexesFromString($chartCoordinates['cell']);
576-
if ($chartTL[1] > $rowMax) {
577-
$rowMax = $chartTL[1];
578-
}
579-
if ($chartTL[0] > $colMax) {
580-
$colMax = $chartTL[0];
581-
}
572+
$chartCoordinates = $chart->getTopLeftPosition();
573+
$this->sheetCharts[$chartCoordinates['cell']] = $chart;
574+
$chartTL = Coordinate::indexesFromString($chartCoordinates['cell']);
575+
if ($chartTL[1] > $rowMax) {
576+
$rowMax = $chartTL[1];
577+
}
578+
if ($chartTL[0] > $colMax) {
579+
$colMax = $chartTL[0];
582580
}
583581
}
584582
}
@@ -1623,7 +1621,7 @@ private function generateRow(Worksheet $worksheet, array $values, int $row, stri
16231621
// Also apply style from last cell in merge to fix borders -
16241622
// relies on !important for non-none border declarations in createCSSStyleBorder
16251623
$endCellCoord = Coordinate::stringFromColumnIndex($colNum + $colSpan) . ($row + $rowSpan);
1626-
if (!$this->useInlineCss) {
1624+
if (!$this->useInlineCss && is_string($cssClass)) {
16271625
$cssClass .= ' style' . $worksheet->getCell($endCellCoord)->getXfIndex();
16281626
} else {
16291627
$endBorders = $this->spreadsheet->getCellXfByIndex($worksheet->getCell($endCellCoord)->getXfIndex())->getBorders();

src/PhpSpreadsheet/Writer/Ods/AutoFilters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function write(): void
2626
for ($i = 0; $i < $sheetCount; ++$i) {
2727
$worksheet = $this->spreadsheet->getSheet($i);
2828
$autofilter = $worksheet->getAutoFilter();
29-
if ($autofilter !== null && !empty($autofilter->getRange())) {
29+
if (!empty($autofilter->getRange())) {
3030
if ($wrapperWritten === false) {
3131
$this->objWriter->startElement('table:database-ranges');
3232
$wrapperWritten = true;

src/PhpSpreadsheet/Writer/Ods/Content.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ private function writeCells(XMLWriter $objWriter, RowCellIterator $cells): void
200200

201201
// Style XF
202202
$style = $cell->getXfIndex();
203-
if ($style !== null) {
204-
$objWriter->writeAttribute('table:style-name', Style::CELL_STYLE_PREFIX . $style);
205-
}
203+
$objWriter->writeAttribute('table:style-name', Style::CELL_STYLE_PREFIX . $style);
206204

207205
switch ($cell->getDataType()) {
208206
case DataType::TYPE_BOOL:

src/PhpSpreadsheet/Writer/Xls.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ private function processMemoryDrawing(BstoreContainer &$bstoreContainer, MemoryD
392392
}
393393

394394
ob_start();
395-
call_user_func($renderingFunction, $drawing->getImageResource());
395+
call_user_func($renderingFunction, $drawing->getImageResource()); // @phpstan-ignore-line
396396
$blipData = ob_get_contents();
397397
ob_end_clean();
398398

src/PhpSpreadsheet/Writer/Xls/BIFFwriter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class BIFFwriter
4242
/**
4343
* The byte order of this architecture. 0 => little endian, 1 => big endian.
4444
*/
45-
private static ?int $byteOrder;
45+
private static ?int $byteOrder = null;
4646

4747
/**
4848
* The string containing the data of the BIFF stream.

src/PhpSpreadsheet/Writer/Xls/CellDataValidation.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static function type(DataValidation $dataValidation): int
4747
{
4848
$validationType = $dataValidation->getType();
4949

50-
if (is_string($validationType) && array_key_exists($validationType, self::$validationTypeMap)) {
50+
if (array_key_exists($validationType, self::$validationTypeMap)) {
5151
return self::$validationTypeMap[$validationType];
5252
}
5353

@@ -58,7 +58,7 @@ public static function errorStyle(DataValidation $dataValidation): int
5858
{
5959
$errorStyle = $dataValidation->getErrorStyle();
6060

61-
if (is_string($errorStyle) && array_key_exists($errorStyle, self::$errorStyleMap)) {
61+
if (array_key_exists($errorStyle, self::$errorStyleMap)) {
6262
return self::$errorStyleMap[$errorStyle];
6363
}
6464

@@ -69,7 +69,7 @@ public static function operator(DataValidation $dataValidation): int
6969
{
7070
$operator = $dataValidation->getOperator();
7171

72-
if (is_string($operator) && array_key_exists($operator, self::$operatorMap)) {
72+
if (array_key_exists($operator, self::$operatorMap)) {
7373
return self::$operatorMap[$operator];
7474
}
7575

src/PhpSpreadsheet/Writer/Xls/ConditionalHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function processCondition(mixed $condition, string $cellRange): void
3636
} else {
3737
try {
3838
/** @var float|int|string */
39-
$conditionx = $condition;
39+
$conditionx = $condition; // @phpstan-ignore-line
4040
$formula = Wizard\WizardAbstract::reverseAdjustCellRef((string) $conditionx, $cellRange);
4141
$this->parser->parse($formula);
4242
$this->tokens = $this->parser->toReversePolish();

src/PhpSpreadsheet/Writer/Xls/Style/CellBorder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static function style(Border $border): int
3131
{
3232
$borderStyle = $border->getBorderStyle();
3333

34-
if (is_string($borderStyle) && array_key_exists($borderStyle, self::$styleMap)) {
34+
if (array_key_exists($borderStyle, self::$styleMap)) {
3535
return self::$styleMap[$borderStyle];
3636
}
3737

0 commit comments

Comments
 (0)