Skip to content

Commit 7de7536

Browse files
committed
PHPStan 2
1 parent 288965e commit 7de7536

File tree

6 files changed

+48
-42
lines changed

6 files changed

+48
-42
lines changed

autoload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
}
2323

2424
$relative_class = substr($class, $len);
25-
$file = $base_dir . str_replace('\\', DIRECTORY_SEPARATOR, $relative_class) . '.php';
25+
$file = $base_dir . str_replace('\\', DIRECTORY_SEPARATOR, $relative_class ?: '_') . '.php';
2626

2727
if (file_exists($file)) {
2828
require $file;

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
"ext-simplexml": "*",
3333
"ext-tokenizer": "*",
3434
"ext-xmlwriter": "*",
35-
"phpstan/phpstan": "^1.12",
36-
"phpstan/phpstan-strict-rules": "^1.6",
37-
"squizlabs/php_codesniffer": "^3.10"
35+
"phpstan/phpstan": "^2",
36+
"phpstan/phpstan-strict-rules": "2",
37+
"squizlabs/php_codesniffer": "^3"
3838
},
3939
"scripts": {
4040
"php-lint": "find . -type d -name 'vendor' -prune -o -name '*.php' -print0 | xargs -0 -n1 -P4 php -l 1>/dev/null",

composer.lock

Lines changed: 18 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.dist.neon

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
parameters:
2-
level: 9
3-
treatPhpDocTypesAsCertain: false
2+
phpVersion:
3+
min: 70400 # PHP 7.4
4+
max: 80499 # PHP 8.4
5+
level: 10 # https://phpstan.org/user-guide/rule-levels
46
fileExtensions:
57
- php
68
paths:
79
- src/
810
excludePaths:
911
analyseAndScan:
1012
- vendor/
13+
checkBenevolentUnionTypes: true
14+
checkImplicitMixed: false # TODO pass
15+
checkMissingOverrideMethodAttribute: true
16+
checkTooWideReturnTypesInProtectedAndPublicMethods: true
17+
reportAnyTypeWideningInVarTag: true
18+
treatPhpDocTypesAsCertain: false
1119
strictRules:
12-
allRules: false
13-
booleansInConditions: true
14-
closureUsesThis: true
15-
disallowedConstructs: false
20+
disallowedEmpty: false
1621
disallowedLooseComparison: false
17-
matchingInheritedMethodNames: true
18-
noVariableVariables: true
19-
numericOperandsInArithmeticOperators: true
20-
overwriteVariablesWithLoop: true
21-
requireParentConstructorCall: true
22-
strictCalls: true
23-
switchConditionsMatchingType: true
24-
uselessCast: true
22+
disallowedShortTernary: false
23+
strictArrayFilter: false # TODO pas
2524
exceptions:
2625
check:
2726
missingCheckedExceptionInThrows: true

src/XlsxFastEditor.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public static function excelDateToDateTime(float $excelDateTime, int $workbookDa
255255
try {
256256
return $excelBaseDate->add(new \DateInterval($iso8601));
257257
} catch (\Exception $ex) {
258-
throw new \InvalidArgumentException('Invalid date!', $ex->getCode(), $ex);
258+
throw new \InvalidArgumentException('Invalid date!', is_int($ex->getCode()) ? $ex->getCode() : 0, $ex);
259259
}
260260
}
261261

@@ -347,7 +347,11 @@ public function setFullCalcOnLoad(int $sheetNumber, bool $value): void
347347
throw new XlsxFastEditorXmlException("Error creating XML fragment for setFullCalcOnLoad!", $dex->code, $dex);
348348
}
349349
if ($sheetCalcPr !== false && $sheetData->parentNode !== null) {
350-
$sheetData->parentNode->insertBefore($sheetCalcPr, $sheetData->nextSibling);
350+
if ($sheetData->nextSibling === null) {
351+
$sheetData->parentNode->appendChild($sheetCalcPr);
352+
} else {
353+
$sheetData->parentNode->insertBefore($sheetCalcPr, $sheetData->nextSibling);
354+
}
351355
}
352356
}
353357
}
@@ -943,7 +947,7 @@ public function writeHyperlink(int $sheetNumber, string $cellName, string $value
943947
}
944948

945949
/**
946-
* Write a formulat in the given worksheet at the given cell location, without changing the type/style of the cell.
950+
* Write a formula in the given worksheet at the given cell location, without changing the type/style of the cell.
947951
* Auto-creates the cell if it does not already exists.
948952
* Removes the formulas of the cell, if any.
949953
*

src/XlsxFastEditorCell.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ private function initCellValue(): \DOMElement
278278
}
279279

280280
/**
281-
* Write a formulat, without changing the type/style of the cell.
281+
* Write a formula, without changing the type/style of the cell.
282282
* Removes the formulas of the cell, if any.
283283
* @throws XlsxFastEditorXmlException
284284
*/
@@ -308,9 +308,13 @@ public function writeFormula(string $value): void
308308
}
309309
try {
310310
$f = $dom->createElement('f', $value);
311+
if (!($f instanceof \DOMElement)) {
312+
throw new XlsxFastEditorXmlException("Error creating DOMElement of formula for cell {$this->name()}!");
313+
}
311314
} catch (\DOMException $dex) {
312-
throw new XlsxFastEditorXmlException("Error creating formulat for cell {$this->name()}!", $dex->code, $dex);
315+
throw new XlsxFastEditorXmlException("Error creating formula for cell {$this->name()}!", $dex->code, $dex);
313316
}
317+
314318
$this->c->appendChild($f);
315319

316320
$this->editor->_clearCalcChain();

0 commit comments

Comments
 (0)