Skip to content

Commit fceb178

Browse files
committed
RequireFileExistsRule: enable __DIR__ only for bleeding edge
1 parent e300c7e commit fceb178

6 files changed

Lines changed: 11 additions & 0 deletions

File tree

conf/bleedingEdge.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ parameters:
1616
reportNestedTooWideType: false # tmp
1717
assignToByRefForeachExpr: true
1818
curlSetOptArrayTypes: true
19+
magicDirInInclude: true
1920
checkDateIntervalConstructor: true
2021
reportMethodPurityOverride: true
2122
checkDynamicConstantNameValues: true

conf/config.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ parameters:
4343
reportNestedTooWideType: false
4444
assignToByRefForeachExpr: false
4545
curlSetOptArrayTypes: false
46+
magicDirInInclude: false
4647
checkDateIntervalConstructor: false
4748
reportMethodPurityOverride: false
4849
checkDynamicConstantNameValues: false

conf/parametersSchema.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ parametersSchema:
4545
reportNestedTooWideType: bool()
4646
assignToByRefForeachExpr: bool()
4747
curlSetOptArrayTypes: bool()
48+
magicDirInInclude: bool()
4849
checkDateIntervalConstructor: bool()
4950
reportMethodPurityOverride: bool()
5051
checkDynamicConstantNameValues: bool()

src/Rules/Keywords/RequireFileExistsRule.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public function __construct(
3737
#[AutowiredParameter]
3838
private string $currentWorkingDirectory,
3939
private ExprPrinter $exprPrinter,
40+
#[AutowiredParameter(ref: '%featureToggles.magicDirInInclude%')]
41+
private bool $checkMagicDirInInclude,
4042
)
4143
{
4244
}
@@ -151,6 +153,10 @@ private function resolveFilePaths(Expr $expr, Scope $scope, bool &$magicDirFallb
151153
{
152154
$magicDirFallback = false;
153155

156+
if (!$this->checkMagicDirInInclude) {
157+
return $scope->getType($expr)->getConstantStrings();
158+
}
159+
154160
if (!$expr instanceof Expr\BinaryOp\Concat) {
155161
return $scope->getType($expr)->getConstantStrings();
156162
}

tests/PHPStan/Rules/Keywords/RequireFileExistsRuleNoConstantPathTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ protected function getRule(): Rule
1919
return new RequireFileExistsRule(
2020
$this->currentWorkingDirectory,
2121
self::getContainer()->getByType(ExprPrinter::class),
22+
true,
2223
);
2324
}
2425

tests/PHPStan/Rules/Keywords/RequireFileExistsRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ protected function getRule(): Rule
2424
return new RequireFileExistsRule(
2525
$this->currentWorkingDirectory,
2626
self::getContainer()->getByType(ExprPrinter::class),
27+
true,
2728
);
2829
}
2930

0 commit comments

Comments
 (0)