From fceb17843b6ca825f20eb633ae510abc5f69a02f Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 15 Jun 2026 14:56:29 +0200 Subject: [PATCH] RequireFileExistsRule: enable __DIR__ only for bleeding edge --- conf/bleedingEdge.neon | 1 + conf/config.neon | 1 + conf/parametersSchema.neon | 1 + src/Rules/Keywords/RequireFileExistsRule.php | 6 ++++++ .../Keywords/RequireFileExistsRuleNoConstantPathTest.php | 1 + tests/PHPStan/Rules/Keywords/RequireFileExistsRuleTest.php | 1 + 6 files changed, 11 insertions(+) diff --git a/conf/bleedingEdge.neon b/conf/bleedingEdge.neon index 528084e353..5f4e2d114a 100644 --- a/conf/bleedingEdge.neon +++ b/conf/bleedingEdge.neon @@ -16,6 +16,7 @@ parameters: reportNestedTooWideType: false # tmp assignToByRefForeachExpr: true curlSetOptArrayTypes: true + magicDirInInclude: true checkDateIntervalConstructor: true reportMethodPurityOverride: true checkDynamicConstantNameValues: true diff --git a/conf/config.neon b/conf/config.neon index df8f46567a..0e09a3ed22 100644 --- a/conf/config.neon +++ b/conf/config.neon @@ -43,6 +43,7 @@ parameters: reportNestedTooWideType: false assignToByRefForeachExpr: false curlSetOptArrayTypes: false + magicDirInInclude: false checkDateIntervalConstructor: false reportMethodPurityOverride: false checkDynamicConstantNameValues: false diff --git a/conf/parametersSchema.neon b/conf/parametersSchema.neon index dc07b020e0..dcd030439b 100644 --- a/conf/parametersSchema.neon +++ b/conf/parametersSchema.neon @@ -45,6 +45,7 @@ parametersSchema: reportNestedTooWideType: bool() assignToByRefForeachExpr: bool() curlSetOptArrayTypes: bool() + magicDirInInclude: bool() checkDateIntervalConstructor: bool() reportMethodPurityOverride: bool() checkDynamicConstantNameValues: bool() diff --git a/src/Rules/Keywords/RequireFileExistsRule.php b/src/Rules/Keywords/RequireFileExistsRule.php index d7e4076ca4..674fc815c1 100644 --- a/src/Rules/Keywords/RequireFileExistsRule.php +++ b/src/Rules/Keywords/RequireFileExistsRule.php @@ -37,6 +37,8 @@ public function __construct( #[AutowiredParameter] private string $currentWorkingDirectory, private ExprPrinter $exprPrinter, + #[AutowiredParameter(ref: '%featureToggles.magicDirInInclude%')] + private bool $checkMagicDirInInclude, ) { } @@ -151,6 +153,10 @@ private function resolveFilePaths(Expr $expr, Scope $scope, bool &$magicDirFallb { $magicDirFallback = false; + if (!$this->checkMagicDirInInclude) { + return $scope->getType($expr)->getConstantStrings(); + } + if (!$expr instanceof Expr\BinaryOp\Concat) { return $scope->getType($expr)->getConstantStrings(); } diff --git a/tests/PHPStan/Rules/Keywords/RequireFileExistsRuleNoConstantPathTest.php b/tests/PHPStan/Rules/Keywords/RequireFileExistsRuleNoConstantPathTest.php index 311915eaa7..6d2f3625ea 100644 --- a/tests/PHPStan/Rules/Keywords/RequireFileExistsRuleNoConstantPathTest.php +++ b/tests/PHPStan/Rules/Keywords/RequireFileExistsRuleNoConstantPathTest.php @@ -19,6 +19,7 @@ protected function getRule(): Rule return new RequireFileExistsRule( $this->currentWorkingDirectory, self::getContainer()->getByType(ExprPrinter::class), + true, ); } diff --git a/tests/PHPStan/Rules/Keywords/RequireFileExistsRuleTest.php b/tests/PHPStan/Rules/Keywords/RequireFileExistsRuleTest.php index c84fdf3a43..c8b989d2ff 100644 --- a/tests/PHPStan/Rules/Keywords/RequireFileExistsRuleTest.php +++ b/tests/PHPStan/Rules/Keywords/RequireFileExistsRuleTest.php @@ -24,6 +24,7 @@ protected function getRule(): Rule return new RequireFileExistsRule( $this->currentWorkingDirectory, self::getContainer()->getByType(ExprPrinter::class), + true, ); }