File tree Expand file tree Collapse file tree 3 files changed +27
-8
lines changed Expand file tree Collapse file tree 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
57215721 return $ iteratee ->getIterableValueType ();
57225722 }
57235723
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+
57245747}
Original file line number Diff line number Diff line change 66use PhpParser \Node \Expr ;
77use PhpParser \Node \Name ;
88use PhpParser \Node \Param ;
9+ use PHPStan \Php \PhpVersion ;
910use PHPStan \Reflection \ClassConstantReflection ;
1011use PHPStan \Reflection \ClassMemberAccessAnswerer ;
1112use PHPStan \Reflection \ClassReflection ;
@@ -136,4 +137,6 @@ public function filterByFalseyValue(Expr $expr): self;
136137
137138 public function isInFirstLevelStatement (): bool ;
138139
140+ public function getPhpVersion (): PhpVersion ;
141+
139142}
Original file line number Diff line number Diff line change 55use PhpParser \Node ;
66use PHPStan \Analyser \Scope ;
77use PHPStan \Node \InClassMethodNode ;
8- use PHPStan \Php \PhpVersion ;
98use PHPStan \Rules \Rule ;
109use PHPStan \Rules \RuleErrorBuilder ;
1110use function sprintf ;
1413final class FinalPrivateMethodRule implements Rule
1514{
1615
17- public function __construct (
18- private PhpVersion $ phpVersion ,
19- )
20- {
21- }
22-
2316 public function getNodeType (): string
2417 {
2518 return InClassMethodNode::class;
@@ -28,7 +21,7 @@ public function getNodeType(): string
2821 public function processNode (Node $ node , Scope $ scope ): array
2922 {
3023 $ method = $ node ->getMethodReflection ();
31- if (!$ this -> phpVersion ->producesWarningForFinalPrivateMethods ()) {
24+ if (!$ scope -> getPhpVersion () ->producesWarningForFinalPrivateMethods ()) {
3225 return [];
3326 }
3427
You can’t perform that action at this time.
0 commit comments