Skip to content

Commit ba93e96

Browse files
committed
[BE] Check @phpstan-pure
1 parent 3758793 commit ba93e96

8 files changed

+34
-74
lines changed

changelog-2.0.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ Major new features 🚀
1919
* Always report always true conditions, except for last elseif and match arm (https://github.com/phpstan/phpstan-src/commit/565fb0f6da9cdc58e8686598015561a848693972)
2020
* Remove "unreachable branches" rules: UnreachableIfBranchesRule, UnreachableTernaryElseBranchRule, unreachable arm error in MatchExpressionRule
2121
* Because "always true" is always reported, these are no longer needed
22+
* Checking truthiness of `@phpstan-pure` above functions and methods
23+
* Check `new`/function call/method call/static method call on a separate line without any side effects even without `@phpstan-pure` PHPDoc tag on the declaration side
24+
* https://github.com/phpstan/phpstan-src/commit/281a87d1ab61809076ecfa6dfc2cc86e3babe235
25+
* [#3020](https://github.com/phpstan/phpstan-src/pull/3020), thanks @staabm!
26+
* [#3022](https://github.com/phpstan/phpstan-src/pull/3022), thanks @staabm!
27+
* [#3023](https://github.com/phpstan/phpstan-src/pull/3023), thanks @staabm!
2228
* LogicalXorConstantConditionRule (level 4) (https://github.com/phpstan/phpstan-src/commit/3a12724fd636b1bcf36c22b36e8f765d97150895, https://github.com/phpstan/phpstan-src/commit/3b011f6524254dad0f16840fdcfdbe7421548617), #7539
2329
* Check that each trait is used and analysed at least once (level 4) (https://github.com/phpstan/phpstan-src/commit/c4d05276fb8605d6ac20acbe1cc5df31cd6c10b0)
2430
* Check preg_quote delimiter sanity (level 0) ([#3252](https://github.com/phpstan/phpstan-src/pull/3252)), #11338, thanks @staabm!
@@ -78,12 +84,6 @@ Bleeding edge (TODO move to other sections)
7884
* Report unused results of `&&` and `||` (https://github.com/phpstan/phpstan-src/commit/cf2c8bbd9ebd2ebe300dbd310e136ad603d7def3)
7985
* Add option `reportAnyTypeWideningInVarTag` ([#2840](https://github.com/phpstan/phpstan-src/pull/2840)), thanks @janedbal!
8086
* Fix checking generic `mixed` type based on config ([#2885](https://github.com/phpstan/phpstan-src/pull/2885)), thanks @schlndh!
81-
* Checking truthiness of `@phpstan-pure` above functions and methods
82-
* Check `new`/function call/method call/static method call on a separate line without any side effects even without `@phpstan-pure` PHPDoc tag on the declaration side
83-
* https://github.com/phpstan/phpstan-src/commit/281a87d1ab61809076ecfa6dfc2cc86e3babe235
84-
* [#3020](https://github.com/phpstan/phpstan-src/pull/3020), thanks @staabm!
85-
* [#3022](https://github.com/phpstan/phpstan-src/pull/3022), thanks @staabm!
86-
* [#3023](https://github.com/phpstan/phpstan-src/pull/3023), thanks @staabm!
8787
* CallToConstructorStatementWithoutSideEffectsRule - report class with no constructor (https://github.com/phpstan/phpstan-src/commit/b116d25a6e4ba6c09f59af6569d9e6f6fd20aff4)
8888
* Check `@param-immediately-invoked-callable` and `@param-later-invoked-callable` (https://github.com/phpstan/phpstan-src/commit/580a6add422f4e34191df9e7a77ba1655e914bda), #10932
8989

conf/bleedingEdge.neon

-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@ parameters:
33
bleedingEdge: true
44
skipCheckGenericClasses!: []
55
stricterFunctionMap: true
6-
7-
pure: true

conf/config.level2.neon

+2-9
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,14 @@ rules:
6363
- PHPStan\Rules\PhpDoc\RequireImplementsDefinitionClassRule
6464
- PHPStan\Rules\PhpDoc\RequireExtendsDefinitionClassRule
6565
- PHPStan\Rules\PhpDoc\RequireExtendsDefinitionTraitRule
66+
- PHPStan\Rules\Pure\PureFunctionRule
67+
- PHPStan\Rules\Pure\PureMethodRule
6668

6769
conditionalTags:
6870
PHPStan\Rules\Methods\IllegalConstructorMethodCallRule:
6971
phpstan.rules.rule: %featureToggles.illegalConstructorMethodCall%
7072
PHPStan\Rules\Methods\IllegalConstructorStaticCallRule:
7173
phpstan.rules.rule: %featureToggles.illegalConstructorMethodCall%
72-
PHPStan\Rules\Pure\PureFunctionRule:
73-
phpstan.rules.rule: %featureToggles.pure%
74-
PHPStan\Rules\Pure\PureMethodRule:
75-
phpstan.rules.rule: %featureToggles.pure%
7674

7775
services:
7876
-
@@ -118,8 +116,3 @@ services:
118116
class: PHPStan\Rules\PhpDoc\InvalidPHPStanDocTagRule
119117
tags:
120118
- phpstan.rules.rule
121-
-
122-
class: PHPStan\Rules\Pure\PureFunctionRule
123-
124-
-
125-
class: PHPStan\Rules\Pure\PureMethodRule

conf/config.level4.neon

+19-43
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ includes:
33

44
rules:
55
- PHPStan\Rules\Arrays\DeadForeachRule
6+
- PHPStan\Rules\DeadCode\CallToConstructorStatementWithoutImpurePointsRule
7+
- PHPStan\Rules\DeadCode\CallToFunctionStatementWithoutImpurePointsRule
8+
- PHPStan\Rules\DeadCode\CallToMethodStatementWithoutImpurePointsRule
9+
- PHPStan\Rules\DeadCode\CallToStaticMethodStatementWithoutImpurePointsRule
610
- PHPStan\Rules\DeadCode\NoopRule
711
- PHPStan\Rules\DeadCode\UnreachableStatementRule
812
- PHPStan\Rules\DeadCode\UnusedPrivateConstantRule
913
- PHPStan\Rules\DeadCode\UnusedPrivateMethodRule
1014
- PHPStan\Rules\Exceptions\OverwrittenExitPointByFinallyRule
1115
- PHPStan\Rules\Functions\CallToFunctionStatementWithoutSideEffectsRule
16+
- PHPStan\Rules\Methods\CallToConstructorStatementWithoutSideEffectsRule
1217
- PHPStan\Rules\Methods\CallToMethodStatementWithoutSideEffectsRule
1318
- PHPStan\Rules\Methods\CallToStaticMethodStatementWithoutSideEffectsRule
1419
- PHPStan\Rules\Methods\NullsafeMethodCallRule
@@ -20,30 +25,6 @@ rules:
2025
- PHPStan\Rules\TooWideTypehints\TooWidePropertyTypeRule
2126
- PHPStan\Rules\Traits\NotAnalysedTraitRule
2227

23-
conditionalTags:
24-
PHPStan\Rules\DeadCode\CallToConstructorStatementWithoutImpurePointsRule:
25-
phpstan.rules.rule: %featureToggles.pure%
26-
PHPStan\Rules\DeadCode\PossiblyPureNewCollector:
27-
phpstan.collector: %featureToggles.pure%
28-
PHPStan\Rules\DeadCode\ConstructorWithoutImpurePointsCollector:
29-
phpstan.collector: %featureToggles.pure%
30-
PHPStan\Rules\DeadCode\CallToFunctionStatementWithoutImpurePointsRule:
31-
phpstan.rules.rule: %featureToggles.pure%
32-
PHPStan\Rules\DeadCode\PossiblyPureFuncCallCollector:
33-
phpstan.collector: %featureToggles.pure%
34-
PHPStan\Rules\DeadCode\FunctionWithoutImpurePointsCollector:
35-
phpstan.collector: %featureToggles.pure%
36-
PHPStan\Rules\DeadCode\CallToMethodStatementWithoutImpurePointsRule:
37-
phpstan.rules.rule: %featureToggles.pure%
38-
PHPStan\Rules\DeadCode\PossiblyPureMethodCallCollector:
39-
phpstan.collector: %featureToggles.pure%
40-
PHPStan\Rules\DeadCode\MethodWithoutImpurePointsCollector:
41-
phpstan.collector: %featureToggles.pure%
42-
PHPStan\Rules\DeadCode\CallToStaticMethodStatementWithoutImpurePointsRule:
43-
phpstan.rules.rule: %featureToggles.pure%
44-
PHPStan\Rules\DeadCode\PossiblyPureStaticCallCollector:
45-
phpstan.collector: %featureToggles.pure%
46-
4728
parameters:
4829
checkAdvancedIsset: true
4930

@@ -84,38 +65,40 @@ services:
8465
tags:
8566
- phpstan.rules.rule
8667

87-
-
88-
class: PHPStan\Rules\DeadCode\CallToConstructorStatementWithoutImpurePointsRule
89-
9068
-
9169
class: PHPStan\Rules\DeadCode\ConstructorWithoutImpurePointsCollector
70+
tags:
71+
- phpstan.collector
9272

9373
-
9474
class: PHPStan\Rules\DeadCode\PossiblyPureNewCollector
95-
96-
-
97-
class: PHPStan\Rules\DeadCode\CallToFunctionStatementWithoutImpurePointsRule
75+
tags:
76+
- phpstan.collector
9877

9978
-
10079
class: PHPStan\Rules\DeadCode\FunctionWithoutImpurePointsCollector
80+
tags:
81+
- phpstan.collector
10182

10283
-
10384
class: PHPStan\Rules\DeadCode\PossiblyPureFuncCallCollector
104-
105-
-
106-
class: PHPStan\Rules\DeadCode\CallToMethodStatementWithoutImpurePointsRule
85+
tags:
86+
- phpstan.collector
10787

10888
-
10989
class: PHPStan\Rules\DeadCode\MethodWithoutImpurePointsCollector
90+
tags:
91+
- phpstan.collector
11092

11193
-
11294
class: PHPStan\Rules\DeadCode\PossiblyPureMethodCallCollector
113-
114-
-
115-
class: PHPStan\Rules\DeadCode\CallToStaticMethodStatementWithoutImpurePointsRule
95+
tags:
96+
- phpstan.collector
11697

11798
-
11899
class: PHPStan\Rules\DeadCode\PossiblyPureStaticCallCollector
100+
tags:
101+
- phpstan.collector
119102

120103
-
121104
class: PHPStan\Rules\DeadCode\UnusedPrivatePropertyRule
@@ -245,13 +228,6 @@ services:
245228
tags:
246229
- phpstan.rules.rule
247230

248-
-
249-
class: PHPStan\Rules\Methods\CallToConstructorStatementWithoutSideEffectsRule
250-
arguments:
251-
reportNoConstructor: %featureToggles.pure%
252-
tags:
253-
- phpstan.rules.rule
254-
255231
-
256232
class: PHPStan\Rules\TooWideTypehints\TooWideMethodReturnTypehintRule
257233
arguments:

conf/config.neon

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ parameters:
2525
skipCheckGenericClasses: []
2626
illegalConstructorMethodCall: false
2727
stricterFunctionMap: false
28-
pure: false
2928
fileExtensions:
3029
- php
3130
checkAdvancedIsset: false

conf/parametersSchema.neon

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ parametersSchema:
3131
skipCheckGenericClasses: listOf(string()),
3232
illegalConstructorMethodCall: bool(),
3333
stricterFunctionMap: bool()
34-
pure: bool()
3534
])
3635
fileExtensions: listOf(string())
3736
checkAdvancedIsset: bool()

src/Rules/Methods/CallToConstructorStatementWithoutSideEffectsRule.php

+6-11
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ final class CallToConstructorStatementWithoutSideEffectsRule implements Rule
1919

2020
public function __construct(
2121
private ReflectionProvider $reflectionProvider,
22-
private bool $reportNoConstructor,
2322
)
2423
{
2524
}
@@ -47,16 +46,12 @@ public function processNode(Node $node, Scope $scope): array
4746

4847
$classReflection = $this->reflectionProvider->getClass($className);
4948
if (!$classReflection->hasConstructor()) {
50-
if ($this->reportNoConstructor) {
51-
return [
52-
RuleErrorBuilder::message(sprintf(
53-
'Call to new %s() on a separate line has no effect.',
54-
$classReflection->getDisplayName(),
55-
))->identifier('new.resultUnused')->build(),
56-
];
57-
}
58-
59-
return [];
49+
return [
50+
RuleErrorBuilder::message(sprintf(
51+
'Call to new %s() on a separate line has no effect.',
52+
$classReflection->getDisplayName(),
53+
))->identifier('new.resultUnused')->build(),
54+
];
6055
}
6156

6257
$constructor = $classReflection->getConstructor();

tests/PHPStan/Rules/Methods/CallToConstructorStatementWithoutSideEffectsRuleTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CallToConstructorStatementWithoutSideEffectsRuleTest extends RuleTestCase
1313

1414
protected function getRule(): Rule
1515
{
16-
return new CallToConstructorStatementWithoutSideEffectsRule($this->createReflectionProvider(), true);
16+
return new CallToConstructorStatementWithoutSideEffectsRule($this->createReflectionProvider());
1717
}
1818

1919
public function testRule(): void

0 commit comments

Comments
 (0)