Skip to content

Commit 12f7f32

Browse files
committed
$composerPhpVersionFactory is not nullable
1 parent 7dae2e2 commit 12f7f32

File tree

5 files changed

+19
-23
lines changed

5 files changed

+19
-23
lines changed

src/Analyser/ConstantResolver.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __construct(
4545
private ReflectionProviderProvider $reflectionProviderProvider,
4646
private array $dynamicConstantNames,
4747
private int|array|null $phpVersion,
48-
private ?ComposerPhpVersionFactory $composerPhpVersionFactory,
48+
private ComposerPhpVersionFactory $composerPhpVersionFactory,
4949
)
5050
{
5151
}
@@ -370,10 +370,6 @@ private function getMinPhpVersion(): ?PhpVersion
370370
return new PhpVersion($this->phpVersion['min']);
371371
}
372372

373-
if ($this->composerPhpVersionFactory === null) {
374-
return null;
375-
}
376-
377373
return $this->composerPhpVersionFactory->getMinVersion();
378374
}
379375

@@ -391,10 +387,6 @@ private function getMaxPhpVersion(): ?PhpVersion
391387
return new PhpVersion($this->phpVersion['max']);
392388
}
393389

394-
if ($this->composerPhpVersionFactory === null) {
395-
return null;
396-
}
397-
398390
return $this->composerPhpVersionFactory->getMaxVersion();
399391
}
400392

src/DependencyInjection/ValidateIgnoredErrorsExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHPStan\Command\IgnoredRegexValidator;
1313
use PHPStan\DependencyInjection\Type\OperatorTypeSpecifyingExtensionRegistryProvider;
1414
use PHPStan\File\FileExcluder;
15+
use PHPStan\Php\ComposerPhpVersionFactory;
1516
use PHPStan\Php\PhpVersion;
1617
use PHPStan\PhpDoc\DirectTypeNodeResolverExtensionRegistryProvider;
1718
use PHPStan\PhpDoc\TypeNodeResolver;
@@ -65,7 +66,8 @@ public function loadConfiguration(): void
6566
$reflectionProviderProvider = new DirectReflectionProviderProvider($reflectionProvider);
6667
ReflectionProviderStaticAccessor::registerInstance($reflectionProvider);
6768
PhpVersionStaticAccessor::registerInstance(new PhpVersion(PHP_VERSION_ID));
68-
$constantResolver = new ConstantResolver($reflectionProviderProvider, [], null, null);
69+
$composerPhpVersionFactory = new ComposerPhpVersionFactory([]);
70+
$constantResolver = new ConstantResolver($reflectionProviderProvider, [], null, $composerPhpVersionFactory);
6971

7072
$phpDocParserConfig = new ParserConfig([]);
7173
$ignoredRegexValidator = new IgnoredRegexValidator(

src/Testing/PHPStanTestCase.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use PHPStan\Internal\DirectoryCreatorException;
2222
use PHPStan\Node\Printer\ExprPrinter;
2323
use PHPStan\Parser\Parser;
24+
use PHPStan\Php\ComposerPhpVersionFactory;
2425
use PHPStan\Php\PhpVersion;
2526
use PHPStan\PhpDoc\TypeNodeResolver;
2627
use PHPStan\PhpDoc\TypeStringResolver;
@@ -137,7 +138,8 @@ public static function createScopeFactory(ReflectionProvider $reflectionProvider
137138
}
138139

139140
$reflectionProviderProvider = new DirectReflectionProviderProvider($reflectionProvider);
140-
$constantResolver = new ConstantResolver($reflectionProviderProvider, $dynamicConstantNames, null, null);
141+
$composerPhpVersionFactory = $container->getByType(ComposerPhpVersionFactory::class);
142+
$constantResolver = new ConstantResolver($reflectionProviderProvider, $dynamicConstantNames, null, $composerPhpVersionFactory);
141143

142144
$initializerExprTypeResolver = new InitializerExprTypeResolver(
143145
$constantResolver,

tests/PHPStan/Analyser/nsrt/bug-4434.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ class HelloWorld
1010
public function testSendEmailToLog(): void
1111
{
1212
foreach ([1] as $emailFile) {
13-
assertType('int<5, max>', PHP_MAJOR_VERSION);
14-
assertType('int<5, max>', \PHP_MAJOR_VERSION);
13+
assertType('int<5, 8>', PHP_MAJOR_VERSION);
14+
assertType('int<5, 8>', \PHP_MAJOR_VERSION);
1515
if (PHP_MAJOR_VERSION === 7) {
1616
assertType('7', PHP_MAJOR_VERSION);
1717
assertType('7', \PHP_MAJOR_VERSION);
1818
} else {
19-
assertType('int<5, 6>|int<8, max>', PHP_MAJOR_VERSION);
20-
assertType('int<5, 6>|int<8, max>', \PHP_MAJOR_VERSION);
19+
assertType('8|int<5, 6>', PHP_MAJOR_VERSION);
20+
assertType('8|int<5, 6>', \PHP_MAJOR_VERSION);
2121
}
2222
}
2323
}
@@ -28,14 +28,14 @@ class HelloWorld2
2828
public function testSendEmailToLog(): void
2929
{
3030
foreach ([1] as $emailFile) {
31-
assertType('int<5, max>', PHP_MAJOR_VERSION);
32-
assertType('int<5, max>', \PHP_MAJOR_VERSION);
31+
assertType('int<5, 8>', PHP_MAJOR_VERSION);
32+
assertType('int<5, 8>', \PHP_MAJOR_VERSION);
3333
if (PHP_MAJOR_VERSION === 100) {
34-
assertType('100', PHP_MAJOR_VERSION);
35-
assertType('100', \PHP_MAJOR_VERSION);
34+
assertType('*NEVER*', PHP_MAJOR_VERSION);
35+
assertType('*NEVER*', \PHP_MAJOR_VERSION);
3636
} else {
37-
assertType('int<5, 99>|int<101, max>', PHP_MAJOR_VERSION);
38-
assertType('int<5, 99>|int<101, max>', \PHP_MAJOR_VERSION);
37+
assertType('int<5, 8>', PHP_MAJOR_VERSION);
38+
assertType('int<5, 8>', \PHP_MAJOR_VERSION);
3939
}
4040
}
4141
}

tests/PHPStan/Analyser/nsrt/predefined-constants.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
// core, https://www.php.net/manual/en/reserved.constants.php
66
assertType('non-falsy-string', PHP_VERSION);
7-
assertType('int<5, max>', PHP_MAJOR_VERSION);
7+
assertType('int<5, 8>', PHP_MAJOR_VERSION);
88
assertType('int<0, max>', PHP_MINOR_VERSION);
99
assertType('int<0, max>', PHP_RELEASE_VERSION);
10-
assertType('int<50207, max>', PHP_VERSION_ID);
10+
assertType('int<50207, 80499>', PHP_VERSION_ID);
1111
assertType('string', PHP_EXTRA_VERSION);
1212
assertType('0|1', PHP_ZTS);
1313
assertType('0|1', PHP_DEBUG);

0 commit comments

Comments
 (0)