File tree 3 files changed +27
-8
lines changed
3 files changed +27
-8
lines changed Original file line number Diff line number Diff line change @@ -5721,4 +5721,27 @@ public function getIterableValueType(Type $iteratee): Type
5721
5721
return $ iteratee ->getIterableValueType ();
5722
5722
}
5723
5723
5724
+ public function getPhpVersion (): PhpVersion
5725
+ {
5726
+ $ versionId = $ this ->getType (new ConstFetch (new Name ('PHP_VERSION_ID ' )));
5727
+ if ($ versionId instanceof IntegerRangeType && $ versionId ->getMin () !== null ) {
5728
+ return new PhpVersion ($ versionId ->getMin (), PhpVersion::SOURCE_RUNTIME );
5729
+ }
5730
+
5731
+ $ scalars = $ versionId ->getConstantScalarValues ();
5732
+ if ($ scalars !== []) {
5733
+ $ ints = [];
5734
+ foreach ($ scalars as $ scalar ) {
5735
+ if (!is_int ($ scalar )) {
5736
+ throw new ShouldNotHappenException ();
5737
+ }
5738
+ $ ints [] = $ scalar ;
5739
+ }
5740
+
5741
+ return new PhpVersion (min ($ ints ), PhpVersion::SOURCE_RUNTIME );
5742
+ }
5743
+
5744
+ return $ this ->phpVersion ;
5745
+ }
5746
+
5724
5747
}
Original file line number Diff line number Diff line change 6
6
use PhpParser \Node \Expr ;
7
7
use PhpParser \Node \Name ;
8
8
use PhpParser \Node \Param ;
9
+ use PHPStan \Php \PhpVersion ;
9
10
use PHPStan \Reflection \ClassConstantReflection ;
10
11
use PHPStan \Reflection \ClassMemberAccessAnswerer ;
11
12
use PHPStan \Reflection \ClassReflection ;
@@ -136,4 +137,6 @@ public function filterByFalseyValue(Expr $expr): self;
136
137
137
138
public function isInFirstLevelStatement (): bool ;
138
139
140
+ public function getPhpVersion (): PhpVersion ;
141
+
139
142
}
Original file line number Diff line number Diff line change 5
5
use PhpParser \Node ;
6
6
use PHPStan \Analyser \Scope ;
7
7
use PHPStan \Node \InClassMethodNode ;
8
- use PHPStan \Php \PhpVersion ;
9
8
use PHPStan \Rules \Rule ;
10
9
use PHPStan \Rules \RuleErrorBuilder ;
11
10
use function sprintf ;
14
13
final class FinalPrivateMethodRule implements Rule
15
14
{
16
15
17
- public function __construct (
18
- private PhpVersion $ phpVersion ,
19
- )
20
- {
21
- }
22
-
23
16
public function getNodeType (): string
24
17
{
25
18
return InClassMethodNode::class;
@@ -28,7 +21,7 @@ public function getNodeType(): string
28
21
public function processNode (Node $ node , Scope $ scope ): array
29
22
{
30
23
$ method = $ node ->getMethodReflection ();
31
- if (!$ this -> phpVersion ->producesWarningForFinalPrivateMethods ()) {
24
+ if (!$ scope -> getPhpVersion () ->producesWarningForFinalPrivateMethods ()) {
32
25
return [];
33
26
}
34
27
You can’t perform that action at this time.
0 commit comments