Skip to content

Commit 8bb568c

Browse files
authored
Prep Work Before Upgrading to Phpstan 1.7.7 (#2867)
Clean up the usual discrepancies which arise between Phpstan releases.
1 parent c936f1d commit 8bb568c

File tree

7 files changed

+30
-55
lines changed

7 files changed

+30
-55
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ parameters:
9595
count: 1
9696
path: src/PhpSpreadsheet/Calculation/Calculation.php
9797

98-
-
99-
message: "#^Offset 'type' does not exist on array\\|null\\.$#"
100-
count: 3
101-
path: src/PhpSpreadsheet/Calculation/Calculation.php
102-
10398
-
10499
message: "#^Offset 'value' does not exist on array\\|null\\.$#"
105100
count: 5
@@ -765,11 +760,6 @@ parameters:
765760
count: 1
766761
path: src/PhpSpreadsheet/Calculation/MathTrig/IntClass.php
767762

768-
-
769-
message: "#^PHPDoc tag @var for constant PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Subtotal\\:\\:CALL_FUNCTIONS with type array\\<callable\\(\\)\\: mixed\\> is not subtype of value array\\{1\\: array\\{'PhpOffice…', 'average'\\}, 2\\: array\\{'PhpOffice…', 'COUNT'\\}, 3\\: array\\{'PhpOffice…', 'COUNTA'\\}, 4\\: array\\{'PhpOffice…', 'max'\\}, 5\\: array\\{'PhpOffice…', 'min'\\}, 6\\: array\\{'PhpOffice…', 'product'\\}, 7\\: array\\{'PhpOffice…', 'STDEV'\\}, 8\\: array\\{'PhpOffice…', 'STDEVP'\\}, \\.\\.\\.\\}\\.$#"
770-
count: 1
771-
path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
772-
773763
-
774764
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\:\\:MAXIFS\\(\\) should return float but returns float\\|string\\|null\\.$#"
775765
count: 1
@@ -4300,21 +4290,6 @@ parameters:
43004290
count: 1
43014291
path: src/PhpSpreadsheet/Writer/Xls/Parser.php
43024292

4303-
-
4304-
message: "#^Offset 'left' does not exist on non\\-empty\\-array\\|string\\.$#"
4305-
count: 6
4306-
path: src/PhpSpreadsheet/Writer/Xls/Parser.php
4307-
4308-
-
4309-
message: "#^Offset 'right' does not exist on non\\-empty\\-array\\|string\\.$#"
4310-
count: 5
4311-
path: src/PhpSpreadsheet/Writer/Xls/Parser.php
4312-
4313-
-
4314-
message: "#^Offset 'value' does not exist on non\\-empty\\-array\\|string\\.$#"
4315-
count: 7
4316-
path: src/PhpSpreadsheet/Writer/Xls/Parser.php
4317-
43184293
-
43194294
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Writer\\\\Xls\\\\Parser\\:\\:\\$spreadsheet has no type specified\\.$#"
43204295
count: 1
@@ -4815,11 +4790,6 @@ parameters:
48154790
count: 1
48164791
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
48174792

4818-
-
4819-
message: "#^Negated boolean expression is always false\\.$#"
4820-
count: 1
4821-
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
4822-
48234793
-
48244794
message: "#^Parameter \\#2 \\$content of method XMLWriter\\:\\:writeElement\\(\\) expects string\\|null, int\\|string given\\.$#"
48254795
count: 1
@@ -4860,8 +4830,3 @@ parameters:
48604830
count: 1
48614831
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
48624832

4863-
-
4864-
message: "#^Strict comparison using \\=\\=\\= between false and true will always evaluate to false\\.$#"
4865-
count: 2
4866-
path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php
4867-

phpstan.neon.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ parameters:
2424
- '~^Instantiated class (AccBarPlot|AccLinePlot|BarPlot|ContourPlot|Graph|GroupBarPlot|GroupBarPlot|LinePlot|LinePlot|PieGraph|PiePlot|PiePlot3D|PiePlotC|RadarGraph|RadarPlot|ScatterPlot|Spline|StockPlot) not found\.$~'
2525
- '~^Call to method .*\(\) on an unknown class (AccBarPlot|AccLinePlot|BarPlot|ContourPlot|Graph|GroupBarPlot|GroupBarPlot|LinePlot|LinePlot|PieGraph|PiePlot|PiePlot3D|PiePlotC|RadarGraph|RadarPlot|ScatterPlot|Spline|StockPlot)\.$~'
2626
- '~^Access to property .* on an unknown class (AccBarPlot|AccLinePlot|BarPlot|ContourPlot|Graph|GroupBarPlot|GroupBarPlot|LinePlot|LinePlot|PieGraph|PiePlot|PiePlot3D|PiePlotC|RadarGraph|RadarPlot|ScatterPlot|Spline|StockPlot)\.$~'
27+
28+
# Some issues in Xls/Parser between 1.6.3 and 1.7.7
29+
-
30+
message: "#^Offset '(left|right|value)' does not exist on (non-empty-array\\|string|array\\|null)\\.$#"
31+
path: src/PhpSpreadsheet/Writer/Xls/Parser.php

src/PhpSpreadsheet/Calculation/Calculation.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4021,6 +4021,7 @@ private function internalParseFormula($formula, ?Cell $cell = null)
40214021
// Find out if we're currently at the beginning of a number, variable, cell reference, function, parenthesis or operand
40224022
$isOperandOrFunction = (bool) preg_match($regexpMatchString, substr($formula, $index), $match);
40234023

4024+
$expectingOperatorCopy = $expectingOperator;
40244025
if ($opCharacter == '-' && !$expectingOperator) { // Is it a negation instead of a minus?
40254026
// Put a negation on the stack
40264027
$stack->push('Unary Operator', '~');
@@ -4173,7 +4174,7 @@ private function internalParseFormula($formula, ?Cell $cell = null)
41734174
$this->branchPruner->incrementDepth();
41744175
$stack->push('Brace', '(', null);
41754176
++$index;
4176-
} elseif ($isOperandOrFunction && !$expectingOperator) { // do we now have a function/variable/number?
4177+
} elseif ($isOperandOrFunction && !$expectingOperatorCopy) { // do we now have a function/variable/number?
41774178
$expectingOperator = true;
41784179
$expectingOperand = false;
41794180
$val = $match[1];
@@ -4398,13 +4399,17 @@ private function internalParseFormula($formula, ?Cell $cell = null)
43984399

43994400
// If we're expecting an operator, but only have a space between the previous and next operands (and both are
44004401
// Cell References) then we have an INTERSECTION operator
4402+
$countOutputMinus1 = count($output) - 1;
44014403
if (
44024404
($expectingOperator) &&
4405+
array_key_exists($countOutputMinus1, $output) &&
4406+
is_array($output[$countOutputMinus1]) &&
4407+
array_key_exists('type', $output[$countOutputMinus1]) &&
44034408
(
44044409
(preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '.*/Ui', substr($formula, $index), $match)) &&
4405-
($output[count($output) - 1]['type'] === 'Cell Reference') ||
4410+
($output[$countOutputMinus1]['type'] === 'Cell Reference') ||
44064411
(preg_match('/^' . self::CALCULATION_REGEXP_DEFINEDNAME . '.*/miu', substr($formula, $index), $match)) &&
4407-
($output[count($output) - 1]['type'] === 'Defined Name' || $output[count($output) - 1]['type'] === 'Value')
4412+
($output[$countOutputMinus1]['type'] === 'Defined Name' || $output[$countOutputMinus1]['type'] === 'Value')
44084413
)
44094414
) {
44104415
while (

src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ function ($index) use ($cellReference) {
5454
);
5555
}
5656

57-
/** @var callable[] */
5857
private const CALL_FUNCTIONS = [
5958
1 => [Statistical\Averages::class, 'average'], // 1 and 101
6059
[Statistical\Counts::class, 'COUNT'], // 2 and 102

src/PhpSpreadsheet/Reader/Xls.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,13 +2280,15 @@ private function readXf(): void
22802280
// bit: 31; mask: 0x80000000; 1 = diagonal line from bottom left to top right
22812281
$diagonalUp = (0x80000000 & self::getInt4d($recordData, 10)) >> 31 ? true : false;
22822282

2283-
if ($diagonalUp == false && $diagonalDown == false) {
2284-
$objStyle->getBorders()->setDiagonalDirection(Borders::DIAGONAL_NONE);
2285-
} elseif ($diagonalUp == true && $diagonalDown == false) {
2283+
if ($diagonalUp === false) {
2284+
if ($diagonalDown == false) {
2285+
$objStyle->getBorders()->setDiagonalDirection(Borders::DIAGONAL_NONE);
2286+
} else {
2287+
$objStyle->getBorders()->setDiagonalDirection(Borders::DIAGONAL_DOWN);
2288+
}
2289+
} elseif ($diagonalDown == false) {
22862290
$objStyle->getBorders()->setDiagonalDirection(Borders::DIAGONAL_UP);
2287-
} elseif ($diagonalUp == false && $diagonalDown == true) {
2288-
$objStyle->getBorders()->setDiagonalDirection(Borders::DIAGONAL_DOWN);
2289-
} elseif ($diagonalUp == true && $diagonalDown == true) {
2291+
} else {
22902292
$objStyle->getBorders()->setDiagonalDirection(Borders::DIAGONAL_BOTH);
22912293
}
22922294

src/PhpSpreadsheet/Reader/Xlsx/Styles.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,14 @@ public function readBorderStyle(Borders $borderStyle, SimpleXMLElement $borderSt
194194
$diagonalUp = self::boolean($diagonalUp);
195195
$diagonalDown = $this->getAttribute($borderStyleXml, 'diagonalDown');
196196
$diagonalDown = self::boolean($diagonalDown);
197-
if (!$diagonalUp && !$diagonalDown) {
198-
$borderStyle->setDiagonalDirection(Borders::DIAGONAL_NONE);
199-
} elseif ($diagonalUp && !$diagonalDown) {
197+
if ($diagonalUp === false) {
198+
if ($diagonalDown === false) {
199+
$borderStyle->setDiagonalDirection(Borders::DIAGONAL_NONE);
200+
} else {
201+
$borderStyle->setDiagonalDirection(Borders::DIAGONAL_DOWN);
202+
}
203+
} elseif ($diagonalDown === false) {
200204
$borderStyle->setDiagonalDirection(Borders::DIAGONAL_UP);
201-
} elseif (!$diagonalUp && $diagonalDown) {
202-
$borderStyle->setDiagonalDirection(Borders::DIAGONAL_DOWN);
203205
} else {
204206
$borderStyle->setDiagonalDirection(Borders::DIAGONAL_BOTH);
205207
}

src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,7 @@ private function writeSheetFormatPr(XMLWriter $objWriter, PhpspreadsheetWorkshee
318318
}
319319

320320
// Set Zero Height row
321-
if (
322-
(string) $worksheet->getDefaultRowDimension()->getZeroHeight() === '1' ||
323-
strtolower((string) $worksheet->getDefaultRowDimension()->getZeroHeight()) == 'true'
324-
) {
321+
if ($worksheet->getDefaultRowDimension()->getZeroHeight()) {
325322
$objWriter->writeAttribute('zeroHeight', '1');
326323
}
327324

@@ -1162,7 +1159,7 @@ private function writeSheetData(XMLWriter $objWriter, PhpspreadsheetWorksheet $w
11621159
$rowDimension = $worksheet->getRowDimension($currentRow);
11631160

11641161
// Write current row?
1165-
$writeCurrentRow = isset($cellsByRow[$currentRow]) || $rowDimension->getRowHeight() >= 0 || $rowDimension->getVisible() == false || $rowDimension->getCollapsed() == true || $rowDimension->getOutlineLevel() > 0 || $rowDimension->getXfIndex() !== null;
1162+
$writeCurrentRow = isset($cellsByRow[$currentRow]) || $rowDimension->getRowHeight() >= 0 || $rowDimension->getVisible() === false || $rowDimension->getCollapsed() === true || $rowDimension->getOutlineLevel() > 0 || $rowDimension->getXfIndex() !== null;
11661163

11671164
if ($writeCurrentRow) {
11681165
// Start a new row

0 commit comments

Comments
 (0)