Skip to content

Commit 00e77f1

Browse files
committed
Phpstan Bleeding Edge Last: Reader
1 parent 0e8d0bf commit 00e77f1

File tree

14 files changed

+134
-305
lines changed

14 files changed

+134
-305
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,2 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Parameter \\#2 \\$contents of static method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Csv\\:\\:guessEncodingTestNoBom\\(\\) expects string, string\\|false given\\.$#"
5-
count: 1
6-
path: src/PhpSpreadsheet/Reader/Csv.php
7-
8-
-
9-
message: "#^Call to function is_array\\(\\) with non\\-empty\\-list\\<string\\> will always evaluate to true\\.$#"
10-
count: 1
11-
path: src/PhpSpreadsheet/Reader/Csv/Delimiter.php
12-
13-
-
14-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\IReadFilter and null will always evaluate to true\\.$#"
15-
count: 1
16-
path: src/PhpSpreadsheet/Reader/Gnumeric.php
17-
18-
-
19-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension and null will always evaluate to true\\.$#"
20-
count: 2
21-
path: src/PhpSpreadsheet/Reader/Gnumeric.php
22-
23-
-
24-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension and null will always evaluate to true\\.$#"
25-
count: 2
26-
path: src/PhpSpreadsheet/Reader/Gnumeric.php
27-
28-
-
29-
message: "#^Strict comparison using \\!\\=\\= between SimpleXMLElement and null will always evaluate to true\\.$#"
30-
count: 1
31-
path: src/PhpSpreadsheet/Reader/Gnumeric.php
32-
33-
-
34-
message: "#^Strict comparison using \\!\\=\\= between SimpleXMLElement and null will always evaluate to true\\.$#"
35-
count: 1
36-
path: src/PhpSpreadsheet/Reader/Gnumeric/Properties.php
37-
38-
-
39-
message: "#^Call to function is_string\\(\\) with string will always evaluate to true\\.$#"
40-
count: 1
41-
path: src/PhpSpreadsheet/Reader/Html.php
42-
43-
-
44-
message: "#^Offset 0 on non\\-empty\\-list\\<string\\> in isset\\(\\) always exists and is not nullable\\.$#"
45-
count: 1
46-
path: src/PhpSpreadsheet/Reader/Html.php
47-
48-
-
49-
message: "#^Parameter \\#4 \\$column of method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Html\\:\\:processDomElement\\(\\) expects string, float\\|int\\|string given\\.$#"
50-
count: 1
51-
path: src/PhpSpreadsheet/Reader/Html.php
52-
53-
-
54-
message: "#^Parameter &\\$column by\\-ref type of method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Html\\:\\:processDomElementTable\\(\\) expects string, \\(float\\|int\\|string\\) given\\.$#"
55-
count: 1
56-
path: src/PhpSpreadsheet/Reader/Html.php
57-
58-
-
59-
message: "#^Parameter &\\$column by\\-ref type of method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Html\\:\\:processDomElementThTd\\(\\) expects string, \\(float\\|int\\) given\\.$#"
60-
count: 1
61-
path: src/PhpSpreadsheet/Reader/Html.php
62-
63-
-
64-
message: "#^Parameter &\\$column by\\-ref type of method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Html\\:\\:processDomElementThTd\\(\\) expects string, float\\|int\\|string given\\.$#"
65-
count: 2
66-
path: src/PhpSpreadsheet/Reader/Html.php
67-
68-
-
69-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Ods\\:\\:getXmlName\\(\\) is marked as impure but does not have any side effects\\.$#"
70-
count: 1
71-
path: src/PhpSpreadsheet/Reader/Ods.php
72-
73-
-
74-
message: "#^Strict comparison using \\!\\=\\= between DOMNodeList\\<DOMElement\\> and null will always evaluate to true\\.$#"
75-
count: 1
76-
path: src/PhpSpreadsheet/Reader/Ods.php
77-
78-
-
79-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\IReadFilter and null will always evaluate to true\\.$#"
80-
count: 1
81-
path: src/PhpSpreadsheet/Reader/Ods.php
82-
83-
-
84-
message: "#^Strict comparison using \\!\\=\\= between string and null will always evaluate to true\\.$#"
85-
count: 1
86-
path: src/PhpSpreadsheet/Reader/Ods.php
87-
88-
-
89-
message: "#^Strict comparison using \\!\\=\\= between \\(float\\|int\\) and string will always evaluate to true\\.$#"
90-
count: 1
91-
path: src/PhpSpreadsheet/Reader/Slk.php
92-
93-
-
94-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\IReadFilter and null will always evaluate to true\\.$#"
95-
count: 10
96-
path: src/PhpSpreadsheet/Reader/Xls.php
97-
98-
-
99-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\IReadFilter and null will always evaluate to true\\.$#"
100-
count: 1
101-
path: src/PhpSpreadsheet/Reader/Xls/LoadSpreadsheet.php
102-
103-
-
104-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\IReadFilter and null will always evaluate to true\\.$#"
105-
count: 1
106-
path: src/PhpSpreadsheet/Reader/Xlsx.php
107-
108-
-
109-
message: "#^Strict comparison using \\!\\=\\= between SimpleXMLElement and false will always evaluate to true\\.$#"
110-
count: 1
111-
path: src/PhpSpreadsheet/Reader/Xlsx.php
112-
113-
-
114-
message: "#^Strict comparison using \\!\\=\\= between SimpleXMLElement and null will always evaluate to true\\.$#"
115-
count: 1
116-
path: src/PhpSpreadsheet/Reader/Xlsx.php
117-
118-
-
119-
message: "#^Strict comparison using \\!\\=\\= between mixed and null will always evaluate to true\\.$#"
120-
count: 1
121-
path: src/PhpSpreadsheet/Reader/Xlsx.php
122-
123-
-
124-
message: "#^Strict comparison using \\!\\=\\= between string and false will always evaluate to true\\.$#"
125-
count: 2
126-
path: src/PhpSpreadsheet/Reader/Xlsx.php
127-
128-
-
129-
message: "#^Strict comparison using \\!\\=\\= between SimpleXMLElement and null will always evaluate to true\\.$#"
130-
count: 1
131-
path: src/PhpSpreadsheet/Reader/Xlsx/Hyperlinks.php
132-
133-
-
134-
message: "#^Strict comparison using \\!\\=\\= between mixed and null will always evaluate to true\\.$#"
135-
count: 1
136-
path: src/PhpSpreadsheet/Reader/Xlsx/WorkbookView.php
137-
138-
-
139-
message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\IReadFilter and null will always evaluate to true\\.$#"
140-
count: 1
141-
path: src/PhpSpreadsheet/Reader/Xml.php

src/PhpSpreadsheet/Reader/Csv.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ private static function guessEncodingTestNoBom(string &$encoding, string &$conte
628628
private static function guessEncodingNoBom(string $filename): string
629629
{
630630
$encoding = '';
631-
$contents = file_get_contents($filename);
631+
$contents = (string) file_get_contents($filename);
632632
self::guessEncodingTestNoBom($encoding, $contents, self::UTF32BE_LF, 'UTF-32BE');
633633
self::guessEncodingTestNoBom($encoding, $contents, self::UTF32LE_LF, 'UTF-32LE');
634634
self::guessEncodingTestNoBom($encoding, $contents, self::UTF16BE_LF, 'UTF-16BE');

src/PhpSpreadsheet/Reader/Csv/Delimiter.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ protected function countPotentialDelimiters(): void
5656
protected function countDelimiterValues(string $line, array $delimiterKeys): void
5757
{
5858
$splitString = str_split($line, 1);
59-
if (is_array($splitString)) {
60-
$distribution = array_count_values($splitString);
61-
$countLine = array_intersect_key($distribution, $delimiterKeys);
59+
$distribution = array_count_values($splitString);
60+
$countLine = array_intersect_key($distribution, $delimiterKeys);
6261

63-
foreach (self::POTENTIAL_DELIMETERS as $delimiter) {
64-
$this->counts[$delimiter][] = $countLine[$delimiter] ?? 0;
65-
}
62+
foreach (self::POTENTIAL_DELIMETERS as $delimiter) {
63+
$this->counts[$delimiter][] = $countLine[$delimiter] ?? 0;
6664
}
6765
}
6866

src/PhpSpreadsheet/Reader/Gnumeric.php

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,8 @@ public function loadIntoExisting(string $filename, Spreadsheet $spreadsheet): Sp
302302
$column = Coordinate::stringFromColumnIndex($column + 1);
303303

304304
// Read cell?
305-
if ($this->getReadFilter() !== null) {
306-
if (!$this->getReadFilter()->readCell($column, $row, $worksheetName)) {
307-
continue;
308-
}
305+
if (!$this->getReadFilter()->readCell($column, $row, $worksheetName)) {
306+
continue;
309307
}
310308

311309
$this->loadCell($cell, $worksheetName, $cellAttributes, $column, $row);
@@ -380,32 +378,30 @@ private function processAutofilter(?SimpleXMLElement $sheet): void
380378
{
381379
if ($sheet !== null && isset($sheet->Filters)) {
382380
foreach ($sheet->Filters->Filter as $autofilter) {
383-
if ($autofilter !== null) {
384-
$attributes = $autofilter->attributes();
385-
if (isset($attributes['Area'])) {
386-
$this->spreadsheet->getActiveSheet()->setAutoFilter((string) $attributes['Area']);
387-
}
381+
$attributes = $autofilter->attributes();
382+
if (isset($attributes['Area'])) {
383+
$this->spreadsheet->getActiveSheet()->setAutoFilter((string) $attributes['Area']);
388384
}
389385
}
390386
}
391387
}
392388

393389
private function setColumnWidth(int $whichColumn, float $defaultWidth): void
394390
{
395-
$columnDimension = $this->spreadsheet->getActiveSheet()
396-
->getColumnDimension(Coordinate::stringFromColumnIndex($whichColumn + 1));
397-
if ($columnDimension !== null) {
398-
$columnDimension->setWidth($defaultWidth);
399-
}
391+
$this->spreadsheet->getActiveSheet()
392+
->getColumnDimension(
393+
Coordinate::stringFromColumnIndex($whichColumn + 1)
394+
)
395+
->setWidth($defaultWidth);
400396
}
401397

402398
private function setColumnInvisible(int $whichColumn): void
403399
{
404-
$columnDimension = $this->spreadsheet->getActiveSheet()
405-
->getColumnDimension(Coordinate::stringFromColumnIndex($whichColumn + 1));
406-
if ($columnDimension !== null) {
407-
$columnDimension->setVisible(false);
408-
}
400+
$this->spreadsheet->getActiveSheet()
401+
->getColumnDimension(
402+
Coordinate::stringFromColumnIndex($whichColumn + 1)
403+
)
404+
->setVisible(false);
409405
}
410406

411407
private function processColumnLoop(int $whichColumn, int $maxCol, ?SimpleXMLElement $columnOverride, float $defaultWidth): int
@@ -453,18 +449,18 @@ private function processColumnWidths(?SimpleXMLElement $sheet, int $maxCol): voi
453449

454450
private function setRowHeight(int $whichRow, float $defaultHeight): void
455451
{
456-
$rowDimension = $this->spreadsheet->getActiveSheet()->getRowDimension($whichRow);
457-
if ($rowDimension !== null) {
458-
$rowDimension->setRowHeight($defaultHeight);
459-
}
452+
$this->spreadsheet
453+
->getActiveSheet()
454+
->getRowDimension($whichRow)
455+
->setRowHeight($defaultHeight);
460456
}
461457

462458
private function setRowInvisible(int $whichRow): void
463459
{
464-
$rowDimension = $this->spreadsheet->getActiveSheet()->getRowDimension($whichRow);
465-
if ($rowDimension !== null) {
466-
$rowDimension->setVisible(false);
467-
}
460+
$this->spreadsheet
461+
->getActiveSheet()
462+
->getRowDimension($whichRow)
463+
->setVisible(false);
468464
}
469465

470466
private function processRowLoop(int $whichRow, int $maxRow, ?SimpleXMLElement $rowOverride, float $defaultHeight): int

src/PhpSpreadsheet/Reader/Gnumeric/Properties.php

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -91,32 +91,30 @@ private function docPropertiesMeta(SimpleXMLElement $officePropertyMeta): void
9191
{
9292
$docProps = $this->spreadsheet->getProperties();
9393
foreach ($officePropertyMeta as $propertyName => $propertyValue) {
94-
if ($propertyValue !== null) {
95-
$attributes = $propertyValue->attributes(Gnumeric::NAMESPACE_META);
96-
$propertyValue = trim((string) $propertyValue);
97-
switch ($propertyName) {
98-
case 'keyword':
99-
$docProps->setKeywords($propertyValue);
100-
101-
break;
102-
case 'initial-creator':
103-
$docProps->setCreator($propertyValue);
104-
$docProps->setLastModifiedBy($propertyValue);
105-
106-
break;
107-
case 'creation-date':
108-
$creationDate = $propertyValue;
109-
$docProps->setCreated($creationDate);
110-
111-
break;
112-
case 'user-defined':
113-
if ($attributes) {
114-
[, $attrName] = explode(':', (string) $attributes['name']);
115-
$this->userDefinedProperties($attrName, $propertyValue);
116-
}
117-
118-
break;
119-
}
94+
$attributes = $propertyValue->attributes(Gnumeric::NAMESPACE_META);
95+
$propertyValue = trim((string) $propertyValue);
96+
switch ($propertyName) {
97+
case 'keyword':
98+
$docProps->setKeywords($propertyValue);
99+
100+
break;
101+
case 'initial-creator':
102+
$docProps->setCreator($propertyValue);
103+
$docProps->setLastModifiedBy($propertyValue);
104+
105+
break;
106+
case 'creation-date':
107+
$creationDate = $propertyValue;
108+
$docProps->setCreated($creationDate);
109+
110+
break;
111+
case 'user-defined':
112+
if ($attributes) {
113+
[, $attrName] = explode(':', (string) $attributes['name']);
114+
$this->userDefinedProperties($attrName, $propertyValue);
115+
}
116+
117+
break;
120118
}
121119
}
122120
}

src/PhpSpreadsheet/Reader/Html.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ private function processDomElementTable(Worksheet $sheet, int &$row, string &$co
525525
$this->processDomElement($child, $sheet, $row, $column, $cellContent);
526526
$column = $this->releaseTableStartColumn();
527527
if ($this->tableLevel > 1) {
528-
++$column;
528+
++$column; //* @phpstan-ignore-line
529529
} else {
530530
++$row;
531531
}
@@ -615,9 +615,10 @@ private function processDomElementDataFormat(Worksheet $sheet, int $row, string
615615
private function processDomElementThTd(Worksheet $sheet, int &$row, string &$column, string &$cellContent, DOMElement $child, array &$attributeArray): void
616616
{
617617
while (isset($this->rowspan[$column . $row])) {
618-
++$column;
618+
++$column; //* @phpstan-ignore-line
619619
}
620-
$this->processDomElement($child, $sheet, $row, $column, $cellContent);
620+
//* @phpstan-ignore-next-line
621+
$this->processDomElement($child, $sheet, $row, $column, $cellContent); // ++$column above confuses Phpstan
621622

622623
// apply inline style
623624
$this->applyInlineStyle($sheet, $row, $column, $attributeArray);
@@ -642,7 +643,8 @@ private function processDomElementThTd(Worksheet $sheet, int &$row, string &$col
642643
$this->rowspan[$value] = true;
643644
}
644645
$sheet->mergeCells($range);
645-
$column = $columnTo;
646+
//* @phpstan-ignore-next-line
647+
$column = $columnTo; // ++$columnTo above confuses phpstan
646648
} elseif (isset($attributeArray['rowspan'])) {
647649
//create merging rowspan
648650
$range = $column . $row . ':' . $column . ($row + (int) $attributeArray['rowspan'] - 1);
@@ -657,7 +659,8 @@ private function processDomElementThTd(Worksheet $sheet, int &$row, string &$col
657659
++$columnTo;
658660
}
659661
$sheet->mergeCells($column . $row . ':' . $columnTo . $row);
660-
$column = $columnTo;
662+
//* @phpstan-ignore-next-line
663+
$column = $columnTo; // ++$columnTo above confuses phpstan
661664
}
662665

663666
++$column;
@@ -671,10 +674,8 @@ protected function processDomElement(DOMNode $element, Worksheet $sheet, int &$r
671674
if ($domText === "\u{a0}") {
672675
$domText = '';
673676
}
674-
if (is_string($cellContent)) {
675-
// simply append the text if the cell content is a plain text string
676-
$cellContent .= $domText;
677-
}
677+
// simply append the text if the cell content is a plain text string
678+
$cellContent .= $domText;
678679
// but if we have a rich text run instead, we need to append it correctly
679680
// TODO
680681
} elseif ($child instanceof DOMElement) {
@@ -920,7 +921,7 @@ private function applyInlineStyle(Worksheet &$sheet, int $row, string $column, a
920921
$styles = explode(';', $attributeArray['style']);
921922
foreach ($styles as $st) {
922923
$value = explode(':', $st);
923-
$styleName = isset($value[0]) ? trim($value[0]) : null;
924+
$styleName = trim($value[0]);
924925
$styleValue = isset($value[1]) ? trim($value[1]) : null;
925926
$styleValueString = (string) $styleValue;
926927

0 commit comments

Comments
 (0)