From 4df15b25d05fbe785a29532866680c3228757510 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sun, 17 Nov 2024 14:09:00 +0100 Subject: [PATCH] Increase PHPStan rule level to 10 --- phpstan.neon | 2 +- src/Restorer.php | 3 +++ src/Snapshot.php | 7 +++++-- tests/unit/SnapshotTest.php | 12 ++++++++++-- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index ffe9f16..cf62feb 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 9 + level: 10 paths: - src - tests/unit diff --git a/src/Restorer.php b/src/Restorer.php index 2a08a5e..7bdadb3 100644 --- a/src/Restorer.php +++ b/src/Restorer.php @@ -13,6 +13,7 @@ use function array_key_exists; use function array_keys; use function array_merge; +use function assert; use function in_array; use function is_array; use ReflectionClass; @@ -95,6 +96,8 @@ private function restoreSuperGlobalArray(Snapshot $snapshot, string $superGlobal ); foreach ($keys as $key) { + assert(isset($GLOBALS[$superGlobalArray]) && is_array($GLOBALS[$superGlobalArray])); + if (isset($superGlobalVariables[$superGlobalArray][$key])) { $GLOBALS[$superGlobalArray][$key] = $superGlobalVariables[$superGlobalArray][$key]; } else { diff --git a/src/Snapshot.php b/src/Snapshot.php index e8b7a16..b3acfd6 100644 --- a/src/Snapshot.php +++ b/src/Snapshot.php @@ -128,6 +128,7 @@ public function __construct(?ExcludeList $excludeList = null, bool $includeGloba assert($iniSettings !== false); + /* @phpstan-ignore assign.propertyType */ $this->iniSettings = $iniSettings; } @@ -238,6 +239,7 @@ private function snapshotConstants(): void $constants = get_defined_constants(true); if (isset($constants['user'])) { + /* @phpstan-ignore assign.propertyType */ $this->constants = $constants['user']; } } @@ -292,7 +294,7 @@ private function snapshotGlobals(): void !in_array($key, $superGlobalArrays, true) && $this->canBeSerialized($GLOBALS[$key]) && !$this->excludeList->isGlobalVariableExcluded($key)) { - /* @noinspection UnserializeExploitsInspection */ + /* @phpstan-ignore assign.propertyType */ $this->globalVariables[$key] = unserialize(serialize($GLOBALS[$key])); } } @@ -304,7 +306,7 @@ private function snapshotSuperGlobalArray(string $superGlobalArray): void if (isset($GLOBALS[$superGlobalArray]) && is_array($GLOBALS[$superGlobalArray])) { foreach ($GLOBALS[$superGlobalArray] as $key => $value) { - /* @noinspection UnserializeExploitsInspection */ + /* @phpstan-ignore assign.propertyType */ $this->superGlobalVariables[$superGlobalArray][$key] = unserialize(serialize($value)); } } @@ -396,6 +398,7 @@ private function enumerateObjectsAndResources(mixed $variable, Context $processe { $result = []; + /* @phpstan-ignore argument.type */ if ($processed->contains($variable)) { return $result; } diff --git a/tests/unit/SnapshotTest.php b/tests/unit/SnapshotTest.php index 5e832ad..273ef7a 100644 --- a/tests/unit/SnapshotTest.php +++ b/tests/unit/SnapshotTest.php @@ -53,7 +53,11 @@ public function testStaticAttributes(): void public function testStaticNotInitialisedAttributes(): void { - /* @noinspection PhpExpressionResultUnusedInspection */ + /** + * @noinspection PhpExpressionResultUnusedInspection + * + * @phpstan-ignore new.resultUnused + */ new SnapshotClassTyped; $this->excludeAllLoadedClassesExceptClass(SnapshotClassTyped::class); @@ -159,7 +163,11 @@ public function testClasses(): void public function testInterfaces(): void { - /* @noinspection PhpExpressionResultUnusedInspection */ + /** + * @noinspection PhpExpressionResultUnusedInspection + * + * @phpstan-ignore new.resultUnused + */ new ExcludedClass; $snapshot = new Snapshot($this->excludeList, false, false, false, false, false, true, false, false, false);