Skip to content

Commit 4eeecf6

Browse files
committed
fix
1 parent dedde46 commit 4eeecf6

File tree

4 files changed

+20
-63
lines changed

4 files changed

+20
-63
lines changed

src/Analyser/MutatingScope.php

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@
145145
use function implode;
146146
use function in_array;
147147
use function is_bool;
148-
use function is_int;
149148
use function is_numeric;
150149
use function is_string;
151150
use function ltrim;
@@ -5727,35 +5726,10 @@ public function getPhpVersion(): PhpVersions
57275726
{
57285727
$versionExpr = new ConstFetch(new Name('PHP_VERSION_ID'));
57295728
if (!$this->hasExpressionType($versionExpr)->yes()) {
5730-
return new PhpVersions([$this->phpVersion->getVersionId()]);
5729+
return new PhpVersions(new ConstantIntegerType($this->phpVersion->getVersionId()));
57315730
}
57325731

5733-
$versionId = $this->getType($versionExpr);
5734-
if ($versionId instanceof IntegerRangeType) {
5735-
if ($versionId->getMin() !== null && $versionId->getMax() !== null) {
5736-
return new PhpVersions([$versionId->getMin(), $versionId->getMax()]);
5737-
}
5738-
if ($versionId->getMin() !== null) {
5739-
return new PhpVersions([$versionId->getMin()]);
5740-
}
5741-
if ($versionId->getMax() !== null) {
5742-
return new PhpVersions([$versionId->getMax()]);
5743-
}
5744-
}
5745-
5746-
$scalars = $versionId->getConstantScalarValues();
5747-
if ($scalars !== []) {
5748-
$ints = [];
5749-
foreach ($scalars as $scalar) {
5750-
if (!is_int($scalar)) {
5751-
throw new ShouldNotHappenException();
5752-
}
5753-
$ints[] = $scalar;
5754-
}
5755-
return new PhpVersions($ints);
5756-
}
5757-
5758-
return new PhpVersions([$this->phpVersion->getVersionId()]);
5732+
return new PhpVersions($this->getType($versionExpr));
57595733
}
57605734

57615735
}

src/Php/PhpVersions.php

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,25 @@
22

33
namespace PHPStan\Php;
44

5-
use PHPStan\ShouldNotHappenException;
65
use PHPStan\TrinaryLogic;
7-
use function max;
8-
use function min;
6+
use PHPStan\Type\IntegerRangeType;
7+
use PHPStan\Type\Type;
98

109
/**
1110
* @api
1211
*/
1312
final class PhpVersions
1413
{
1514

16-
private int $minVersionId;
17-
18-
private int $maxVersionId;
19-
20-
/**
21-
* @param list<int> $phpVersionIds
22-
*/
2315
public function __construct(
24-
array $phpVersionIds,
16+
private Type $phpVersions,
2517
)
2618
{
27-
if ($phpVersionIds === []) {
28-
throw new ShouldNotHappenException();
29-
}
30-
31-
$normalizedPhpVersionIds = [];
32-
foreach ($phpVersionIds as $versionId) {
33-
// drop patch version part and replace with 00
34-
$normalizedPhpVersionIds[] = ((int) ($versionId / 100)) * 100;
35-
}
36-
37-
$this->minVersionId = min($normalizedPhpVersionIds);
38-
$this->maxVersionId = max($normalizedPhpVersionIds);
3919
}
4020

4121
public function producesWarningForFinalPrivateMethods(): TrinaryLogic
4222
{
43-
return $this->minPhpVersion(80000);
44-
}
45-
46-
private function minPhpVersion(int $versionId): TrinaryLogic
47-
{
48-
if ($this->minVersionId >= $versionId) {
49-
return TrinaryLogic::createYes();
50-
}
51-
if ($this->maxVersionId >= $versionId) {
52-
return TrinaryLogic::createMaybe();
53-
}
54-
return TrinaryLogic::createNo();
23+
return $this->phpVersions->isSuperTypeOf(IntegerRangeType::fromInterval(80000, null))->result;
5524
}
5625

5726
}

tests/PHPStan/Rules/Methods/FinalPrivateMethodRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public function testRule(): void
2929
'Private method FinalPrivateMethod\FooBarPhp74OrHigher::foo() cannot be final as it is never overridden by other classes.',
3030
59,
3131
],
32+
[
33+
'Private method FinalPrivateMethod\FooBarPhp8orHigher::foo() cannot be final as it is never overridden by other classes.',
34+
69,
35+
],
3236
]);
3337
}
3438

tests/PHPStan/Rules/Methods/data/final-private-method.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,13 @@ final private function foo(): void
6161
}
6262
}
6363
}
64+
65+
if (PHP_VERSION_ID < 70400 || PHP_VERSION_ID >= 80100) {
66+
class FooBarPhp8orHigher
67+
{
68+
69+
final private function foo(): void
70+
{
71+
}
72+
}
73+
}

0 commit comments

Comments
 (0)