Skip to content

Commit 8f2986a

Browse files
authored
Merge branch refs/heads/1.12.x into 2.1.x
2 parents c6e0450 + 4111d0f commit 8f2986a

File tree

4 files changed

+68
-2
lines changed

4 files changed

+68
-2
lines changed

src/Analyser/ImpurePoint.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use PHPStan\Node\VirtualNode;
77

88
/**
9-
* @phpstan-type ImpurePointIdentifier = 'echo'|'die'|'exit'|'propertyAssign'|'propertyAssignByRef'|'propertyUnset'|'methodCall'|'new'|'functionCall'|'include'|'require'|'print'|'eval'|'superglobal'|'yield'|'yieldFrom'|'static'|'global'|'betweenPhpTags'
9+
* @phpstan-type ImpurePointIdentifier = 'echo'|'die'|'exit'|'propertyAssign'|'propertyAssignByRef'|'propertyUnset'|'methodCall'|'new'|'functionCall'|'include'|'require'|'print'|'eval'|'superglobal'|'yield'|'yieldFrom'|'static'|'global'|'betweenPhpTags'|'staticPropertyAccess'
1010
* @api
1111
*/
1212
final class ImpurePoint

src/Analyser/NodeScopeResolver.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -3042,7 +3042,15 @@ static function (): void {
30423042
} elseif ($expr instanceof StaticPropertyFetch) {
30433043
$hasYield = false;
30443044
$throwPoints = [];
3045-
$impurePoints = [];
3045+
$impurePoints = [
3046+
new ImpurePoint(
3047+
$scope,
3048+
$expr,
3049+
'staticPropertyAccess',
3050+
'static property access',
3051+
true,
3052+
),
3053+
];
30463054
if ($expr->class instanceof Expr) {
30473055
$result = $this->processExprNode($stmt, $expr->class, $scope, $nodeCallback, $context->enterDeep());
30483056
$hasYield = $result->hasYield();

tests/PHPStan/Rules/Pure/PureMethodRuleTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ public function testRule(): void
140140
'Possibly impure call to a callable in pure method PureMethod\MaybeCallableFromUnion::doFoo().',
141141
330,
142142
],
143+
[
144+
'Impure static property access in pure method PureMethod\StaticMethodAccessingStaticProperty::getA().',
145+
388,
146+
],
147+
[
148+
'Impure property assignment in pure method PureMethod\StaticMethodAssigningStaticProperty::getA().',
149+
409,
150+
],
143151
]);
144152
}
145153

@@ -151,6 +159,10 @@ public function testPureConstructor(): void
151159

152160
$this->treatPhpDocTypesAsCertain = true;
153161
$this->analyse([__DIR__ . '/data/pure-constructor.php'], [
162+
[
163+
'Impure static property access in pure method PureConstructor\Foo::__construct().',
164+
19,
165+
],
154166
[
155167
'Impure property assignment in pure method PureConstructor\Foo::__construct().',
156168
19,

tests/PHPStan/Rules/Pure/data/pure-method.php

+46
Original file line numberDiff line numberDiff line change
@@ -375,3 +375,49 @@ public function assertSth($value): void
375375
}
376376

377377
}
378+
379+
class StaticMethodAccessingStaticProperty
380+
{
381+
public static int $a = 0;
382+
383+
/**
384+
* @phpstan-pure
385+
*/
386+
public static function getA(): int
387+
{
388+
return self::$a;
389+
}
390+
391+
/**
392+
* @phpstan-impure
393+
*/
394+
public static function getB(): int
395+
{
396+
return self::$a;
397+
}
398+
}
399+
400+
class StaticMethodAssigningStaticProperty
401+
{
402+
public static int $a = 0;
403+
404+
/**
405+
* @phpstan-pure
406+
*/
407+
public static function getA(): int
408+
{
409+
self::$a = 1;
410+
411+
return 1;
412+
}
413+
414+
/**
415+
* @phpstan-impure
416+
*/
417+
public static function getB(): int
418+
{
419+
self::$a = 1;
420+
421+
return 1;
422+
}
423+
}

0 commit comments

Comments
 (0)