Skip to content

Commit

Permalink
Increase PHPStan rule level to 10
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Nov 17, 2024
1 parent 15ab164 commit 4df15b2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 9
level: 10
paths:
- src
- tests/unit
3 changes: 3 additions & 0 deletions src/Restorer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions src/Snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public function __construct(?ExcludeList $excludeList = null, bool $includeGloba

assert($iniSettings !== false);

/* @phpstan-ignore assign.propertyType */
$this->iniSettings = $iniSettings;
}

Expand Down Expand Up @@ -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'];
}
}
Expand Down Expand Up @@ -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]));
}
}
Expand All @@ -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));
}
}
Expand Down Expand Up @@ -396,6 +398,7 @@ private function enumerateObjectsAndResources(mixed $variable, Context $processe
{
$result = [];

/* @phpstan-ignore argument.type */
if ($processed->contains($variable)) {
return $result;
}
Expand Down
12 changes: 10 additions & 2 deletions tests/unit/SnapshotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4df15b2

Please sign in to comment.