Skip to content

Commit 8095786

Browse files
committed
test
1 parent e2a886c commit 8095786

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
10+
class ScopePhpVersionTest extends TypeInferenceTestCase
11+
{
12+
13+
public function dataTestPhpVersion(): array
14+
{
15+
return [
16+
[
17+
'int<80000, 80499>',
18+
__DIR__ . '/data/global-scope-constants.php',
19+
],
20+
];
21+
}
22+
23+
/**
24+
* @dataProvider dataTestPhpVersion
25+
*/
26+
public function testPhpVersion(string $expected, string $file): void
27+
{
28+
self::processFile($file, function (Node $node, Scope $scope) use ($expected): void {
29+
if (!($node instanceof Exit_)) {
30+
return;
31+
}
32+
$this->assertSame(
33+
$expected,
34+
$scope->getPhpVersion()->getType()->describe(VerbosityLevel::precise()),
35+
);
36+
});
37+
}
38+
39+
}
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)