Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4df15b2

Browse files
committedNov 17, 2024··
Increase PHPStan rule level to 10
1 parent 15ab164 commit 4df15b2

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed
 

‎phpstan.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 9
2+
level: 10
33
paths:
44
- src
55
- tests/unit

‎src/Restorer.php

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use function array_key_exists;
1414
use function array_keys;
1515
use function array_merge;
16+
use function assert;
1617
use function in_array;
1718
use function is_array;
1819
use ReflectionClass;
@@ -95,6 +96,8 @@ private function restoreSuperGlobalArray(Snapshot $snapshot, string $superGlobal
9596
);
9697

9798
foreach ($keys as $key) {
99+
assert(isset($GLOBALS[$superGlobalArray]) && is_array($GLOBALS[$superGlobalArray]));
100+
98101
if (isset($superGlobalVariables[$superGlobalArray][$key])) {
99102
$GLOBALS[$superGlobalArray][$key] = $superGlobalVariables[$superGlobalArray][$key];
100103
} else {

‎src/Snapshot.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public function __construct(?ExcludeList $excludeList = null, bool $includeGloba
128128

129129
assert($iniSettings !== false);
130130

131+
/* @phpstan-ignore assign.propertyType */
131132
$this->iniSettings = $iniSettings;
132133
}
133134

@@ -238,6 +239,7 @@ private function snapshotConstants(): void
238239
$constants = get_defined_constants(true);
239240

240241
if (isset($constants['user'])) {
242+
/* @phpstan-ignore assign.propertyType */
241243
$this->constants = $constants['user'];
242244
}
243245
}
@@ -292,7 +294,7 @@ private function snapshotGlobals(): void
292294
!in_array($key, $superGlobalArrays, true) &&
293295
$this->canBeSerialized($GLOBALS[$key]) &&
294296
!$this->excludeList->isGlobalVariableExcluded($key)) {
295-
/* @noinspection UnserializeExploitsInspection */
297+
/* @phpstan-ignore assign.propertyType */
296298
$this->globalVariables[$key] = unserialize(serialize($GLOBALS[$key]));
297299
}
298300
}
@@ -304,7 +306,7 @@ private function snapshotSuperGlobalArray(string $superGlobalArray): void
304306

305307
if (isset($GLOBALS[$superGlobalArray]) && is_array($GLOBALS[$superGlobalArray])) {
306308
foreach ($GLOBALS[$superGlobalArray] as $key => $value) {
307-
/* @noinspection UnserializeExploitsInspection */
309+
/* @phpstan-ignore assign.propertyType */
308310
$this->superGlobalVariables[$superGlobalArray][$key] = unserialize(serialize($value));
309311
}
310312
}
@@ -396,6 +398,7 @@ private function enumerateObjectsAndResources(mixed $variable, Context $processe
396398
{
397399
$result = [];
398400

401+
/* @phpstan-ignore argument.type */
399402
if ($processed->contains($variable)) {
400403
return $result;
401404
}

‎tests/unit/SnapshotTest.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ public function testStaticAttributes(): void
5353

5454
public function testStaticNotInitialisedAttributes(): void
5555
{
56-
/* @noinspection PhpExpressionResultUnusedInspection */
56+
/**
57+
* @noinspection PhpExpressionResultUnusedInspection
58+
*
59+
* @phpstan-ignore new.resultUnused
60+
*/
5761
new SnapshotClassTyped;
5862

5963
$this->excludeAllLoadedClassesExceptClass(SnapshotClassTyped::class);
@@ -159,7 +163,11 @@ public function testClasses(): void
159163

160164
public function testInterfaces(): void
161165
{
162-
/* @noinspection PhpExpressionResultUnusedInspection */
166+
/**
167+
* @noinspection PhpExpressionResultUnusedInspection
168+
*
169+
* @phpstan-ignore new.resultUnused
170+
*/
163171
new ExcludedClass;
164172

165173
$snapshot = new Snapshot($this->excludeList, false, false, false, false, false, true, false, false, false);

0 commit comments

Comments
 (0)
Please sign in to comment.