Skip to content

Commit 566cd60

Browse files
committed
Revert "Allow mixed type dynamic constants."
This reverts commit 1854985.
1 parent 1854985 commit 566cd60

File tree

10 files changed

+7
-170
lines changed

10 files changed

+7
-170
lines changed

conf/config.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ parameters:
176176
- ZEND_DEBUG_BUILD
177177
- ZEND_THREAD_SAFE
178178
- E_ALL # different on PHP 8.4
179-
mixedTypeConstantNames:
180179
customRulesetUsed: null
181180
editorUrl: null
182181
editorUrlTitle: null

conf/parametersSchema.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ parametersSchema:
140140
resultCachePath: string()
141141
resultCacheChecksProjectExtensionFilesDependencies: bool()
142142
dynamicConstantNames: listOf(string())
143-
mixedTypeConstantNames: listOf(string())
144143
customRulesetUsed: schema(bool(), nullable())
145144
rootDir: string()
146145
tmpDir: string()

src/Analyser/ConstantResolver.php

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ final class ConstantResolver
3333

3434
/**
3535
* @param string[] $dynamicConstantNames
36-
* @param string[] $mixedTypeConstantNames
3736
*/
38-
public function __construct(private ReflectionProviderProvider $reflectionProviderProvider, private array $dynamicConstantNames, private array $mixedTypeConstantNames)
37+
public function __construct(private ReflectionProviderProvider $reflectionProviderProvider, private array $dynamicConstantNames)
3938
{
4039
}
4140

@@ -303,14 +302,8 @@ public function resolvePredefinedConstant(string $resolvedConstantName): ?Type
303302

304303
public function resolveConstantType(string $constantName, Type $constantType): Type
305304
{
306-
if ($constantType->isConstantValue()->yes()) {
307-
if (in_array($constantName, $this->dynamicConstantNames, true)) {
308-
return $constantType->generalize(GeneralizePrecision::lessSpecific());
309-
}
310-
311-
if (in_array($constantName, $this->mixedTypeConstantNames, true)) {
312-
return new MixedType();
313-
}
305+
if ($constantType->isConstantValue()->yes() && in_array($constantName, $this->dynamicConstantNames, true)) {
306+
return $constantType->generalize(GeneralizePrecision::lessSpecific());
314307
}
315308

316309
return $constantType;
@@ -329,16 +322,6 @@ public function resolveClassConstantType(string $className, string $constantName
329322
}
330323
}
331324

332-
if (in_array($lookupConstantName, $this->mixedTypeConstantNames, true)) {
333-
if ($nativeType !== null) {
334-
return $nativeType;
335-
}
336-
337-
if ($constantType->isConstantValue()->yes()) {
338-
return new MixedType();
339-
}
340-
}
341-
342325
return $constantType;
343326
}
344327

src/Analyser/ConstantResolverFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public function create(): ConstantResolver
2020
return new ConstantResolver(
2121
$this->reflectionProviderProvider,
2222
$this->container->getParameter('dynamicConstantNames'),
23-
$this->container->getParameter('mixedTypeConstantNames') ?? [],
2423
);
2524
}
2625

src/DependencyInjection/ValidateIgnoredErrorsExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function loadConfiguration(): void
6565
$reflectionProviderProvider = new DirectReflectionProviderProvider($reflectionProvider);
6666
ReflectionProviderStaticAccessor::registerInstance($reflectionProvider);
6767
PhpVersionStaticAccessor::registerInstance(new PhpVersion(PHP_VERSION_ID));
68-
$constantResolver = new ConstantResolver($reflectionProviderProvider, [], []);
68+
$constantResolver = new ConstantResolver($reflectionProviderProvider, []);
6969

7070
$phpDocParserConfig = new ParserConfig([]);
7171
$ignoredRegexValidator = new IgnoredRegexValidator(

src/Testing/PHPStanTestCase.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,17 @@ public static function getClassReflectionExtensionRegistryProvider(): ClassRefle
127127

128128
/**
129129
* @param string[] $dynamicConstantNames
130-
* @param string[] $mixedTypeConstantNames
131130
*/
132-
public static function createScopeFactory(ReflectionProvider $reflectionProvider, TypeSpecifier $typeSpecifier, array $dynamicConstantNames = [], array $mixedTypeConstantNames = []): ScopeFactory
131+
public static function createScopeFactory(ReflectionProvider $reflectionProvider, TypeSpecifier $typeSpecifier, array $dynamicConstantNames = []): ScopeFactory
133132
{
134133
$container = self::getContainer();
135134

136135
if (count($dynamicConstantNames) === 0) {
137136
$dynamicConstantNames = $container->getParameter('dynamicConstantNames');
138137
}
139-
if (count($mixedTypeConstantNames) === 0) {
140-
$mixedTypeConstantNames = $container->getParameter('mixedTypeConstantNames') ?? [];
141-
}
142138

143139
$reflectionProviderProvider = new DirectReflectionProviderProvider($reflectionProvider);
144-
$constantResolver = new ConstantResolver($reflectionProviderProvider, $dynamicConstantNames, $mixedTypeConstantNames);
140+
$constantResolver = new ConstantResolver($reflectionProviderProvider, $dynamicConstantNames);
145141

146142
$initializerExprTypeResolver = new InitializerExprTypeResolver(
147143
$constantResolver,

src/Testing/TypeInferenceTestCase.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,11 @@ abstract class TypeInferenceTestCase extends PHPStanTestCase
4949
/**
5050
* @param callable(Node , Scope ): void $callback
5151
* @param string[] $dynamicConstantNames
52-
* @param string[] $mixedTypeConstantNames
5352
*/
5453
public static function processFile(
5554
string $file,
5655
callable $callback,
5756
array $dynamicConstantNames = [],
58-
array $mixedTypeConstantNames = [],
5957
): void
6058
{
6159
$reflectionProvider = self::createReflectionProvider();
@@ -90,7 +88,7 @@ public static function processFile(
9088
);
9189
$resolver->setAnalysedFiles(array_map(static fn (string $file): string => $fileHelper->normalizePath($file), array_merge([$file], static::getAdditionalAnalysedFiles())));
9290

93-
$scopeFactory = self::createScopeFactory($reflectionProvider, $typeSpecifier, $dynamicConstantNames, $mixedTypeConstantNames);
91+
$scopeFactory = self::createScopeFactory($reflectionProvider, $typeSpecifier, $dynamicConstantNames);
9492
$scope = $scopeFactory->create(ScopeContext::create($file));
9593

9694
$resolver->processNodes(

tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -8535,102 +8535,6 @@ public function testDynamicConstantsWithNativeTypes(
85358535
);
85368536
}
85378537

8538-
public function dataMixedTypeConstants(): array
8539-
{
8540-
return [
8541-
[
8542-
'mixed',
8543-
'MixedTypeConstants\MixedTypeConstantClass::MIXED_TYPE_CONSTANT_IN_CLASS',
8544-
],
8545-
[
8546-
"'abc123def'",
8547-
'MixedTypeConstants\MixedTypeConstantClass::PURE_CONSTANT_IN_CLASS',
8548-
],
8549-
[
8550-
"'xyz'",
8551-
'MixedTypeConstants\NoMixedTypeConstantClass::MIXED_TYPE_CONSTANT_IN_CLASS',
8552-
],
8553-
[
8554-
'false',
8555-
'GLOBAL_MIXED_TYPE_CONSTANT',
8556-
],
8557-
[
8558-
'123',
8559-
'GLOBAL_PURE_CONSTANT',
8560-
],
8561-
];
8562-
}
8563-
8564-
/**
8565-
* @dataProvider dataMixedTypeConstants
8566-
*/
8567-
public function testMixedTypeConstants(
8568-
string $description,
8569-
string $expression,
8570-
): void
8571-
{
8572-
$this->assertTypes(
8573-
__DIR__ . '/data/mixed-type-constant.php',
8574-
$description,
8575-
$expression,
8576-
'die',
8577-
[],
8578-
true,
8579-
[
8580-
'MixedTypeConstants\\MixedTypeConstantClass::MIXED_TYPE_CONSTANT_IN_CLASS',
8581-
'GLOBAL_MIXED_TYPE_CONSTANT',
8582-
],
8583-
);
8584-
}
8585-
8586-
public function dataMixedTypeConstantsWithNativeTypes(): array
8587-
{
8588-
return [
8589-
[
8590-
'int',
8591-
'MixedTypeConstantNativeTypes\Foo::FOO',
8592-
],
8593-
[
8594-
'int|string',
8595-
'MixedTypeConstantNativeTypes\Foo::BAR',
8596-
],
8597-
[
8598-
'int',
8599-
'$foo::FOO',
8600-
],
8601-
[
8602-
'int|string',
8603-
'$foo::BAR',
8604-
],
8605-
];
8606-
}
8607-
8608-
/**
8609-
* @dataProvider dataMixedTypeConstantsWithNativeTypes
8610-
*/
8611-
public function testMixedTypeConstantsWithNativeTypes(
8612-
string $description,
8613-
string $expression,
8614-
): void
8615-
{
8616-
if (PHP_VERSION_ID < 80300) {
8617-
$this->markTestSkipped('Test requires PHP 8.3.');
8618-
}
8619-
8620-
$this->assertTypes(
8621-
__DIR__ . '/data/mixed-type-constant-native-types.php',
8622-
$description,
8623-
$expression,
8624-
'die',
8625-
[],
8626-
true,
8627-
[
8628-
'MixedTypeConstantNativeTypes\Foo::FOO',
8629-
'MixedTypeConstantNativeTypes\Foo::BAR',
8630-
],
8631-
);
8632-
}
8633-
86348538
public function dataIsset(): array
86358539
{
86368540
return [
@@ -9641,7 +9545,6 @@ public function testTryCatchScope(
96419545

96429546
/**
96439547
* @param string[] $dynamicConstantNames
9644-
* @param string[] $mixedTypeConstantNames
96459548
*/
96469549
private function assertTypes(
96479550
string $file,
@@ -9650,7 +9553,6 @@ private function assertTypes(
96509553
string $evaluatedPointExpression = 'die',
96519554
array $dynamicConstantNames = [],
96529555
bool $useCache = true,
9653-
array $mixedTypeConstantNames = [],
96549556
): void
96559557
{
96569558
$assertType = function (Scope $scope) use ($expression, $description, $evaluatedPointExpression): void {
@@ -9685,7 +9587,6 @@ static function (Node $node, Scope $scope) use ($file, $evaluatedPointExpression
96859587
$assertType($scope);
96869588
},
96879589
$dynamicConstantNames,
9688-
$mixedTypeConstantNames,
96899590
);
96909591
}
96919592

tests/PHPStan/Analyser/data/mixed-type-constant-native-types.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/PHPStan/Analyser/data/mixed-type-constant.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)