diff --git a/src/DependencyInjection/ValidateIgnoredErrorsExtension.php b/src/DependencyInjection/ValidateIgnoredErrorsExtension.php index 6bcd2eb995d..ea92091bc91 100644 --- a/src/DependencyInjection/ValidateIgnoredErrorsExtension.php +++ b/src/DependencyInjection/ValidateIgnoredErrorsExtension.php @@ -138,7 +138,7 @@ public function getRegistry(): UnaryOperatorTypeSpecifyingExtensionRegistry return new UnaryOperatorTypeSpecifyingExtensionRegistry([]); } - }, new OversizedArrayBuilder(), true), + }, new OversizedArrayBuilder()), ), ), ); diff --git a/src/Reflection/InitializerExprTypeResolver.php b/src/Reflection/InitializerExprTypeResolver.php index 495b8266664..128ec206aab 100644 --- a/src/Reflection/InitializerExprTypeResolver.php +++ b/src/Reflection/InitializerExprTypeResolver.php @@ -30,7 +30,6 @@ use PhpParser\Node\Scalar\String_; use PHPStan\Analyser\ConstantResolver; use PHPStan\Analyser\OutOfClassScope; -use PHPStan\DependencyInjection\AutowiredParameter; use PHPStan\DependencyInjection\AutowiredService; use PHPStan\DependencyInjection\Type\OperatorTypeSpecifyingExtensionRegistryProvider; use PHPStan\DependencyInjection\Type\UnaryOperatorTypeSpecifyingExtensionRegistryProvider; @@ -70,7 +69,6 @@ use PHPStan\Type\Enum\EnumCaseObjectType; use PHPStan\Type\ErrorType; use PHPStan\Type\FloatType; -use PHPStan\Type\GeneralizePrecision; use PHPStan\Type\Generic\GenericClassStringType; use PHPStan\Type\Generic\TemplateType; use PHPStan\Type\Generic\TemplateTypeMap; @@ -141,8 +139,6 @@ public function __construct( private OperatorTypeSpecifyingExtensionRegistryProvider $operatorTypeSpecifyingExtensionRegistryProvider, private UnaryOperatorTypeSpecifyingExtensionRegistryProvider $unaryOperatorTypeSpecifyingExtensionRegistryProvider, private OversizedArrayBuilder $oversizedArrayBuilder, - #[AutowiredParameter] - private bool $usePathConstantsAsConstantString, ) { } @@ -185,16 +181,14 @@ public function getType(Expr $expr, InitializerExprContext $context): Type if ($file === null) { return new StringType(); } - $stringType = new ConstantStringType($file); - return $this->usePathConstantsAsConstantString ? $stringType : $stringType->generalize(GeneralizePrecision::moreSpecific()); + return new ConstantStringType($file); } if ($expr instanceof Dir) { $file = $context->getFile(); if ($file === null) { return new StringType(); } - $stringType = new ConstantStringType(dirname($file)); - return $this->usePathConstantsAsConstantString ? $stringType : $stringType->generalize(GeneralizePrecision::moreSpecific()); + return new ConstantStringType(dirname($file)); } if ($expr instanceof Line) { return new ConstantIntegerType($expr->getStartLine()); diff --git a/src/Testing/PHPStanTestCase.php b/src/Testing/PHPStanTestCase.php index ac028fdcf39..51e16832a22 100644 --- a/src/Testing/PHPStanTestCase.php +++ b/src/Testing/PHPStanTestCase.php @@ -85,7 +85,6 @@ public static function createScopeFactory(ReflectionProvider $reflectionProvider $container->getByType(OperatorTypeSpecifyingExtensionRegistryProvider::class), $container->getByType(UnaryOperatorTypeSpecifyingExtensionRegistryProvider::class), new OversizedArrayBuilder(), - $container->getParameter('usePathConstantsAsConstantString'), ); return new ScopeFactory( diff --git a/tests/PHPStan/Analyser/Fiber/data/fnsr.php b/tests/PHPStan/Analyser/Fiber/data/fnsr.php index ccfeaa3e85a..e230f2c244e 100644 --- a/tests/PHPStan/Analyser/Fiber/data/fnsr.php +++ b/tests/PHPStan/Analyser/Fiber/data/fnsr.php @@ -466,8 +466,8 @@ public function __construct(private int $i, private int $j, private int $k) { class MagicConstUser { function doFoo(): void { - assertType('literal-string&non-falsy-string', __DIR__); - assertType('literal-string&non-falsy-string', __FILE__); + assertType("'data'", substr(__DIR__, -4)); + assertType("'fnsr.php'", substr(__FILE__, -8)); assertType('471', __LINE__); assertType("'FiberNodeScopeResolverTest'", __NAMESPACE__); assertType("'FiberNodeScopeResolverTest\\\\MagicConstUser'", __CLASS__); diff --git a/tests/PHPStan/Analyser/PathConstantsTest.php b/tests/PHPStan/Analyser/PathConstantsTest.php index 3a3e124e58b..479f7de5de7 100644 --- a/tests/PHPStan/Analyser/PathConstantsTest.php +++ b/tests/PHPStan/Analyser/PathConstantsTest.php @@ -31,11 +31,4 @@ public function testFileAsserts( $this->assertFileAsserts($assertType, $file, ...$args); } - public static function getAdditionalConfigFiles(): array - { - return [ - __DIR__ . '/usePathConstantsAsConstantString.neon', - ]; - } - } diff --git a/tests/PHPStan/Analyser/nsrt/binary.php b/tests/PHPStan/Analyser/nsrt/binary.php index ce3a13e6cc6..8320efef3df 100644 --- a/tests/PHPStan/Analyser/nsrt/binary.php +++ b/tests/PHPStan/Analyser/nsrt/binary.php @@ -356,8 +356,8 @@ public function doFoo(array $generalArray) assertType('int|string', $stringOrNull ?? $integer); assertType('\'Foo\'', \Foo::class); assertType('106', $line); - assertType('literal-string&non-falsy-string', $dir); - assertType('literal-string&non-falsy-string', $file); + assertType("'nsrt'", substr($dir, -4)); + assertType("'binary.php'", substr($file, -10)); assertType('\'BinaryOperations\\\\NestedNamespace\'', $namespace); assertType('\'BinaryOperations\\\\NestedNamespace\\\\Foo\'', $class); assertType('\'BinaryOperations\\\\NestedNamespace\\\\Foo::doFoo\'', $method); diff --git a/tests/PHPStan/Analyser/usePathConstantsAsConstantString.neon b/tests/PHPStan/Analyser/usePathConstantsAsConstantString.neon deleted file mode 100644 index 12225ce6e67..00000000000 --- a/tests/PHPStan/Analyser/usePathConstantsAsConstantString.neon +++ /dev/null @@ -1,2 +0,0 @@ -parameters: - usePathConstantsAsConstantString: true diff --git a/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedSingleFileSourceLocatorTest.php b/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedSingleFileSourceLocatorTest.php index e20a66eec01..497bec85200 100644 --- a/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedSingleFileSourceLocatorTest.php +++ b/tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedSingleFileSourceLocatorTest.php @@ -192,7 +192,7 @@ public static function dataConst(): array ], [ 'const_with_dir_const', - 'literal-string&non-falsy-string', + "'" . __DIR__ . "/data'", ], [ 'OPTIMIZED_SFSL_OBJECT_CONSTANT', diff --git a/tests/PHPStan/Rules/Keywords/RequireFileExistsRuleTest.php b/tests/PHPStan/Rules/Keywords/RequireFileExistsRuleTest.php index 732819b506c..b75e7ce4cad 100644 --- a/tests/PHPStan/Rules/Keywords/RequireFileExistsRuleTest.php +++ b/tests/PHPStan/Rules/Keywords/RequireFileExistsRuleTest.php @@ -24,13 +24,6 @@ protected function getRule(): Rule return new RequireFileExistsRule($this->currentWorkingDirectory); } - public static function getAdditionalConfigFiles(): array - { - return [ - __DIR__ . '/../../Analyser/usePathConstantsAsConstantString.neon', - ]; - } - public function testBasicCase(): void { $this->analyse([__DIR__ . '/data/require-file-simple-case.php'], [