Skip to content

Commit 747d62e

Browse files
committed
test
1 parent e2a886c commit 747d62e

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

src/Analyser/MutatingScope.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5690,7 +5690,7 @@ private function getGlobalConstantType(Name $name): ?Type
56905690
$fetches[] = new ConstFetch(new FullyQualified($name->toString()));
56915691
$fetches[] = new ConstFetch($name);
56925692

5693-
foreach($fetches as $constFetch) {
5693+
foreach ($fetches as $constFetch) {
56945694
if ($this->hasExpressionType($constFetch)->yes()) {
56955695
return $this->getType($constFetch);
56965696
}

src/Php/PhpVersions.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ public function __construct(
1818
{
1919
}
2020

21+
public function getType(): Type
22+
{
23+
return $this->phpVersions;
24+
}
25+
2126
public function supportsNoncapturingCatches(): TrinaryLogic
2227
{
2328
return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Analyser;
4+
5+
use PhpParser\Node;
6+
use PhpParser\Node\Expr\Exit_;
7+
use PHPStan\Testing\TypeInferenceTestCase;
8+
use PHPStan\Type\VerbosityLevel;
9+
use const PHP_VERSION_ID;
10+
11+
class ScopePhpVersionTest extends TypeInferenceTestCase
12+
{
13+
14+
public function dataTestPhpVersion(): array
15+
{
16+
return [
17+
[
18+
'int<80000, 80499>',
19+
__DIR__ . '/data/global-scope-constants.php',
20+
],
21+
];
22+
}
23+
24+
/**
25+
* @dataProvider dataTestPhpVersion
26+
*/
27+
public function testPhpVersion(string $expected, string $file): void
28+
{
29+
self::processFile($file, function (Node $node, Scope $scope) use ($expected): void {
30+
if (!($node instanceof Exit_)) {
31+
return;
32+
}
33+
$this->assertSame(
34+
$expected,
35+
$scope->getPhpVersion()->getType()->describe(VerbosityLevel::precise()),
36+
);
37+
});
38+
}
39+
40+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
// global namespace required for the test to work
4+
5+
if (PHP_VERSION_ID < 80000) {
6+
return;
7+
}
8+
9+
exit();

0 commit comments

Comments
 (0)