Skip to content

Commit 0e8d0bf

Browse files
authored
Merge pull request #4378 from oleibman/stanbleed05
Phpstan Bleeding Edge Part 5: All But Reader
2 parents 6d9c0a4 + 27213ae commit 0e8d0bf

File tree

15 files changed

+60
-237
lines changed

15 files changed

+60
-237
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Call to function is_string\\(\\) with numeric\\-string\\|non\\-empty\\-string will always evaluate to true\\.$#"
5-
count: 1
6-
path: src/PhpSpreadsheet/Cell/AddressHelper.php
7-
8-
-
9-
message: "#^Strict comparison using \\!\\=\\= between int and null will always evaluate to true\\.$#"
10-
count: 1
11-
path: src/PhpSpreadsheet/Cell/Coordinate.php
12-
13-
-
14-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\DataSeriesValues and null will always evaluate to true\\.$#"
15-
count: 3
16-
path: src/PhpSpreadsheet/Chart/DataSeries.php
17-
18-
-
19-
message: "#^Parameter \\#1 \\.\\.\\.\\$arg1 of function max expects non\\-empty\\-array, array given\\.$#"
20-
count: 1
21-
path: src/PhpSpreadsheet/Helper/TextGrid.php
22-
233
-
244
message: "#^Parameter \\#2 \\$contents of static method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Csv\\:\\:guessEncodingTestNoBom\\(\\) expects string, string\\|false given\\.$#"
255
count: 1
@@ -159,113 +139,3 @@ parameters:
159139
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\IReadFilter and null will always evaluate to true\\.$#"
160140
count: 1
161141
path: src/PhpSpreadsheet/Reader/Xml.php
162-
163-
-
164-
message: "#^Strict comparison using \\!\\=\\= between \\(float\\|int\\) and string will always evaluate to true\\.$#"
165-
count: 2
166-
path: src/PhpSpreadsheet/ReferenceHelper.php
167-
168-
-
169-
message: "#^Static property PhpOffice\\\\PhpSpreadsheet\\\\Shared\\\\StringHelper\\:\\:\\$isIconvEnabled \\(bool\\|null\\) is never assigned null so it can be removed from the property type\\.$#"
170-
count: 1
171-
path: src/PhpSpreadsheet/Shared/StringHelper.php
172-
173-
-
174-
message: "#^Strict comparison using \\!\\=\\= between string and null will always evaluate to true\\.$#"
175-
count: 1
176-
path: src/PhpSpreadsheet/Spreadsheet.php
177-
178-
-
179-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Border and null will always evaluate to true\\.$#"
180-
count: 4
181-
path: src/PhpSpreadsheet/Style/ConditionalFormatting/StyleMerger.php
182-
183-
-
184-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Borders and null will always evaluate to true\\.$#"
185-
count: 1
186-
path: src/PhpSpreadsheet/Style/ConditionalFormatting/StyleMerger.php
187-
188-
-
189-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Color and null will always evaluate to true\\.$#"
190-
count: 4
191-
path: src/PhpSpreadsheet/Style/ConditionalFormatting/StyleMerger.php
192-
193-
-
194-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Fill and null will always evaluate to true\\.$#"
195-
count: 1
196-
path: src/PhpSpreadsheet/Style/ConditionalFormatting/StyleMerger.php
197-
198-
-
199-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font and null will always evaluate to true\\.$#"
200-
count: 1
201-
path: src/PhpSpreadsheet/Style/ConditionalFormatting/StyleMerger.php
202-
203-
-
204-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\NumberFormat and null will always evaluate to true\\.$#"
205-
count: 1
206-
path: src/PhpSpreadsheet/Style/ConditionalFormatting/StyleMerger.php
207-
208-
-
209-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell and null will always evaluate to true\\.$#"
210-
count: 2
211-
path: src/PhpSpreadsheet/Style/Style.php
212-
213-
-
214-
message: "#^Call to function is_callable\\(\\) with array\\{'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\AutoFilter', 'dynamicLastMonth'\\|'dynamicLastQuarter'\\|'dynamicLastWeek'\\|'dynamicLastYear'\\|'dynamicNextMonth'\\|'dynamicNextQuarter'\\|'dynamicNextWeek'\\|'dynamicNextYear'\\|'dynamicThisMonth'\\|'dynamicThisQuarter'\\|'dynamicThisWeek'\\|'dynamicThisYear'\\|'dynamicToday'\\|'dynamicTomorrow'\\|'dynamicYearToDate'\\|'dynamicYesterday'\\} will always evaluate to true\\.$#"
215-
count: 1
216-
path: src/PhpSpreadsheet/Worksheet/AutoFilter.php
217-
218-
-
219-
message: "#^Strict comparison using \\!\\=\\= between mixed and null will always evaluate to true\\.$#"
220-
count: 1
221-
path: src/PhpSpreadsheet/Worksheet/AutoFilter.php
222-
223-
-
224-
message: "#^Strict comparison using \\!\\=\\= between string and null will always evaluate to true\\.$#"
225-
count: 2
226-
path: src/PhpSpreadsheet/Worksheet/AutoFilter.php
227-
228-
-
229-
message: "#^Strict comparison using \\!\\=\\= between string and null will always evaluate to true\\.$#"
230-
count: 1
231-
path: src/PhpSpreadsheet/Worksheet/AutoFilter/Column/Rule.php
232-
233-
-
234-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\AutoFilter and null will always evaluate to true\\.$#"
235-
count: 1
236-
path: src/PhpSpreadsheet/Worksheet/AutoFit.php
237-
238-
-
239-
message: "#^Instanceof between PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Table\\\\Column and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Table\\\\Column will always evaluate to true\\.$#"
240-
count: 1
241-
path: src/PhpSpreadsheet/Worksheet/Table.php
242-
243-
-
244-
message: "#^Strict comparison using \\!\\=\\= between string and null will always evaluate to true\\.$#"
245-
count: 2
246-
path: src/PhpSpreadsheet/Worksheet/Table.php
247-
248-
-
249-
message: "#^Instanceof between PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Conditional and PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Conditional will always evaluate to true\\.$#"
250-
count: 1
251-
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
252-
253-
-
254-
message: "#^Instanceof between PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\AutoFilter and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\AutoFilter will always evaluate to true\\.$#"
255-
count: 1
256-
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
257-
258-
-
259-
message: "#^Parameter &\\$hiddenColumns by\\-ref type of method PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet\\:\\:buildNullRow\\(\\) expects array\\<string, bool\\>, array\\<bool\\> given\\.$#"
260-
count: 1
261-
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
262-
263-
-
264-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell and null will always evaluate to true\\.$#"
265-
count: 2
266-
path: src/PhpSpreadsheet/Worksheet/Worksheet.php
267-
268-
-
269-
message: "#^Strict comparison using \\!\\=\\= between string and null will always evaluate to true\\.$#"
270-
count: 1
271-
path: src/PhpSpreadsheet/Worksheet/Worksheet.php

src/PhpSpreadsheet/Cell/AddressHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static function convertToA1(
5858
$columnReference = (string) $currentColumnNumber;
5959
}
6060
// Bracketed C references are relative to the current column
61-
if (is_string($columnReference) && $columnReference[0] === '[') {
61+
if (is_string($columnReference) && $columnReference[0] === '[') { // @phpstan-ignore-line
6262
$columnReference = $currentColumnNumber + (int) trim($columnReference, '[]');
6363
}
6464
$columnReference = (int) $columnReference;

src/PhpSpreadsheet/Cell/Coordinate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ public static function mergeRangesInCollection(array $coordinateCollection): arr
667667
}
668668
}
669669

670-
if ($rowStart !== null) {
670+
if ($rowStart !== null) { // @phpstan-ignore-line
671671
if ($rowStart == $rowEnd) {
672672
$ranges[] = $hashedValue->col . $rowStart;
673673
} else {

src/PhpSpreadsheet/Chart/DataSeries.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -367,19 +367,13 @@ public function setSmoothLine(bool $smoothLine): static
367367
public function refresh(Worksheet $worksheet): void
368368
{
369369
foreach ($this->plotValues as $plotValues) {
370-
if ($plotValues !== null) {
371-
$plotValues->refresh($worksheet, true);
372-
}
370+
$plotValues->refresh($worksheet, true);
373371
}
374372
foreach ($this->plotLabel as $plotValues) {
375-
if ($plotValues !== null) {
376-
$plotValues->refresh($worksheet, true);
377-
}
373+
$plotValues->refresh($worksheet, true);
378374
}
379375
foreach ($this->plotCategory as $plotValues) {
380-
if ($plotValues !== null) {
381-
$plotValues->refresh($worksheet, false);
382-
}
376+
$plotValues->refresh($worksheet, false);
383377
}
384378
}
385379

src/PhpSpreadsheet/Helper/TextGrid.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ public function render(): string
3535
{
3636
$this->gridDisplay = $this->isCli ? '' : '<pre>';
3737

38-
$maxRow = max($this->rows);
39-
$maxRowLength = mb_strlen((string) $maxRow) + 1;
40-
$columnWidths = $this->getColumnWidths();
41-
42-
$this->renderColumnHeader($maxRowLength, $columnWidths);
43-
$this->renderRows($maxRowLength, $columnWidths);
44-
$this->renderFooter($maxRowLength, $columnWidths);
38+
if (!empty($this->rows)) {
39+
$maxRow = max($this->rows);
40+
$maxRowLength = mb_strlen((string) $maxRow) + 1;
41+
$columnWidths = $this->getColumnWidths();
42+
43+
$this->renderColumnHeader($maxRowLength, $columnWidths);
44+
$this->renderRows($maxRowLength, $columnWidths);
45+
$this->renderFooter($maxRowLength, $columnWidths);
46+
}
4547

4648
$this->gridDisplay .= $this->isCli ? '' : '</pre>';
4749

src/PhpSpreadsheet/ReferenceHelper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,9 +1136,9 @@ private function adjustAutoFilterDelete(int $startCol, int $numberOfColumns, int
11361136

11371137
do {
11381138
$autoFilter->shiftColumn($startColID, $toColID);
1139-
++$startColID;
11401139
++$toColID;
1141-
} while ($startColID !== $endColID);
1140+
++$startColID; // this confuses phpstan into thinking startColID is int/float
1141+
} while ($startColID !== $endColID); // @phpstan-ignore-line
11421142
}
11431143

11441144
private function adjustTable(Worksheet $worksheet, string $beforeCellAddress, int $numberOfColumns): void
@@ -1215,9 +1215,9 @@ private function adjustTableDelete(int $startCol, int $numberOfColumns, int $ran
12151215

12161216
do {
12171217
$table->shiftColumn($startColID, $toColID);
1218-
++$startColID;
12191218
++$toColID;
1220-
} while ($startColID !== $endColID);
1219+
++$startColID; // this confuses phpstan into thinking startColID is int/float
1220+
} while ($startColID !== $endColID); // @phpstan-ignore-line
12211221
}
12221222

12231223
private function duplicateStylesByColumn(Worksheet $worksheet, int $beforeColumn, int $beforeRow, int $highestRow, int $numberOfColumns): void

src/PhpSpreadsheet/Shared/StringHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class StringHelper
3434
/**
3535
* Is iconv extension avalable?
3636
*/
37-
private static ?bool $isIconvEnabled;
37+
private static ?bool $isIconvEnabled = null;
3838

3939
/**
4040
* iconv options.

src/PhpSpreadsheet/Spreadsheet.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,8 @@ public function setHasMacros(bool $hasMacros): void
198198

199199
/**
200200
* Set the macros code.
201-
*
202-
* @param string $macroCode string|null
203201
*/
204-
public function setMacrosCode(string $macroCode): void
202+
public function setMacrosCode(?string $macroCode): void
205203
{
206204
$this->macrosCode = $macroCode;
207205
$this->setHasMacros($macroCode !== null);

src/PhpSpreadsheet/Style/ConditionalFormatting/StyleMerger.php

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,29 @@ public function getStyle(): Style
2424

2525
public function mergeStyle(Style $style): void
2626
{
27-
if ($style->getNumberFormat() !== null && $style->getNumberFormat()->getFormatCode() !== null) {
27+
if ($style->getNumberFormat()->getFormatCode() !== null) {
2828
$this->baseStyle->getNumberFormat()->setFormatCode($style->getNumberFormat()->getFormatCode());
2929
}
30-
31-
if ($style->getFont() !== null) {
32-
$this->mergeFontStyle($this->baseStyle->getFont(), $style->getFont());
33-
}
34-
35-
if ($style->getFill() !== null) {
36-
$this->mergeFillStyle($this->baseStyle->getFill(), $style->getFill());
37-
}
38-
39-
if ($style->getBorders() !== null) {
40-
$this->mergeBordersStyle($this->baseStyle->getBorders(), $style->getBorders());
41-
}
30+
$this->mergeFontStyle($this->baseStyle->getFont(), $style->getFont());
31+
$this->mergeFillStyle($this->baseStyle->getFill(), $style->getFill());
32+
$this->mergeBordersStyle($this->baseStyle->getBorders(), $style->getBorders());
4233
}
4334

4435
protected function mergeFontStyle(Font $baseFontStyle, Font $fontStyle): void
4536
{
4637
if ($fontStyle->getBold() !== null) {
4738
$baseFontStyle->setBold($fontStyle->getBold());
4839
}
49-
5040
if ($fontStyle->getItalic() !== null) {
5141
$baseFontStyle->setItalic($fontStyle->getItalic());
5242
}
53-
5443
if ($fontStyle->getStrikethrough() !== null) {
5544
$baseFontStyle->setStrikethrough($fontStyle->getStrikethrough());
5645
}
57-
5846
if ($fontStyle->getUnderline() !== null) {
5947
$baseFontStyle->setUnderline($fontStyle->getUnderline());
6048
}
61-
62-
if ($fontStyle->getColor() !== null && $fontStyle->getColor()->getARGB() !== null) {
49+
if ($fontStyle->getColor()->getARGB() !== null) {
6350
$baseFontStyle->setColor($fontStyle->getColor());
6451
}
6552
}
@@ -69,46 +56,27 @@ protected function mergeFillStyle(Fill $baseFillStyle, Fill $fillStyle): void
6956
if ($fillStyle->getFillType() !== null) {
7057
$baseFillStyle->setFillType($fillStyle->getFillType());
7158
}
72-
73-
//if ($fillStyle->getRotation() !== null) {
7459
$baseFillStyle->setRotation($fillStyle->getRotation());
75-
//}
76-
77-
if ($fillStyle->getStartColor() !== null && $fillStyle->getStartColor()->getARGB() !== null) {
60+
if ($fillStyle->getStartColor()->getARGB() !== null) {
7861
$baseFillStyle->setStartColor($fillStyle->getStartColor());
7962
}
80-
81-
if ($fillStyle->getEndColor() !== null && $fillStyle->getEndColor()->getARGB() !== null) {
63+
if ($fillStyle->getEndColor()->getARGB() !== null) {
8264
$baseFillStyle->setEndColor($fillStyle->getEndColor());
8365
}
8466
}
8567

8668
protected function mergeBordersStyle(Borders $baseBordersStyle, Borders $bordersStyle): void
8769
{
88-
if ($bordersStyle->getTop() !== null) {
89-
$this->mergeBorderStyle($baseBordersStyle->getTop(), $bordersStyle->getTop());
90-
}
91-
92-
if ($bordersStyle->getBottom() !== null) {
93-
$this->mergeBorderStyle($baseBordersStyle->getBottom(), $bordersStyle->getBottom());
94-
}
95-
96-
if ($bordersStyle->getLeft() !== null) {
97-
$this->mergeBorderStyle($baseBordersStyle->getLeft(), $bordersStyle->getLeft());
98-
}
99-
100-
if ($bordersStyle->getRight() !== null) {
101-
$this->mergeBorderStyle($baseBordersStyle->getRight(), $bordersStyle->getRight());
102-
}
70+
$this->mergeBorderStyle($baseBordersStyle->getTop(), $bordersStyle->getTop());
71+
$this->mergeBorderStyle($baseBordersStyle->getBottom(), $bordersStyle->getBottom());
72+
$this->mergeBorderStyle($baseBordersStyle->getLeft(), $bordersStyle->getLeft());
73+
$this->mergeBorderStyle($baseBordersStyle->getRight(), $bordersStyle->getRight());
10374
}
10475

10576
protected function mergeBorderStyle(Border $baseBorderStyle, Border $borderStyle): void
10677
{
107-
//if ($borderStyle->getBorderStyle() !== null) {
10878
$baseBorderStyle->setBorderStyle($borderStyle->getBorderStyle());
109-
//}
110-
111-
if ($borderStyle->getColor() !== null && $borderStyle->getColor()->getARGB() !== null) {
79+
if ($borderStyle->getColor()->getARGB() !== null) {
11280
$baseBorderStyle->setColor($borderStyle->getColor());
11381
}
11482
}

src/PhpSpreadsheet/Style/Style.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,8 @@ private function getOldXfIndexes(string $selectionType, array $rangeStart, array
501501
$cellIterator = $columnIterator->getCellIterator();
502502
$cellIterator->setIterateOnlyExistingCells(true);
503503
foreach ($cellIterator as $columnCell) {
504-
if ($columnCell !== null) {
505-
$columnCell->getStyle()->applyFromArray($styleArray);
506-
}
504+
$columnCell->getStyle()
505+
->applyFromArray($styleArray);
507506
}
508507
}
509508

@@ -520,9 +519,8 @@ private function getOldXfIndexes(string $selectionType, array $rangeStart, array
520519
$cellIterator = $rowIterator->getCellIterator();
521520
$cellIterator->setIterateOnlyExistingCells(true);
522521
foreach ($cellIterator as $rowCell) {
523-
if ($rowCell !== null) {
524-
$rowCell->getStyle()->applyFromArray($styleArray);
525-
}
522+
$rowCell->getStyle()
523+
->applyFromArray($styleArray);
526524
}
527525
}
528526

0 commit comments

Comments
 (0)