Skip to content

Commit 05b80ef

Browse files
committed
Parameter narrowMethodScopeFromConstructor in DI because it's in multiple service in GNSR
1 parent 9960c90 commit 05b80ef

21 files changed

+495
-385
lines changed

conf/config.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ parameters:
213213
- '1.1.1.2'
214214
tmpDir: %sysGetTempDir%/phpstan-fixer
215215
__validate: true
216+
narrowMethodScopeFromConstructor: true
216217
parametersNotInvalidatingCache:
217218
- [parameters, editorUrl]
218219
- [parameters, editorUrlTitle]

conf/parametersSchema.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ parametersSchema:
192192
singleReflectionFile: schema(string(), nullable())
193193
singleReflectionInsteadOfFile: schema(string(), nullable())
194194

195+
# internal for NodeScopeResolver
196+
narrowMethodScopeFromConstructor: bool()
197+
195198
expandRelativePaths:
196199
- '[parameters][paths][]'
197200
- '[parameters][excludePaths][]'

src/Analyser/Generator/StmtHandler/ClassLikeHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public function __construct(
5252
private readonly ClassReflectionFactory $classReflectionFactory,
5353
#[AutowiredParameter(ref: '@nodeScopeResolverReflector')]
5454
private readonly Reflector $reflector,
55-
private readonly bool $narrowMethodScopeFromConstructor = true,
55+
#[AutowiredParameter]
56+
private readonly bool $narrowMethodScopeFromConstructor,
5657
)
5758
{
5859
}

src/Analyser/Generator/StmtHandler/ClassMethodHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use PHPStan\Analyser\ImpurePoint;
2222
use PHPStan\Analyser\Scope;
2323
use PHPStan\Analyser\StatementContext;
24+
use PHPStan\DependencyInjection\AutowiredParameter;
2425
use PHPStan\DependencyInjection\AutowiredService;
2526
use PHPStan\Node\ClassPropertyNode;
2627
use PHPStan\Node\ExecutionEndNode;
@@ -49,7 +50,8 @@ public function __construct(
4950
private ParamHandler $paramHandler,
5051
private DeprecatedAttributeHelper $deprecatedAttributeHelper,
5152
private PropertyHooksHandler $propertyHooksHandler,
52-
private readonly bool $narrowMethodScopeFromConstructor = true,
53+
#[AutowiredParameter]
54+
private readonly bool $narrowMethodScopeFromConstructor,
5355
)
5456
{
5557
}

src/Analyser/NodeScopeResolver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ public function __construct(
283283
private readonly bool $implicitThrows,
284284
#[AutowiredParameter]
285285
private readonly bool $treatPhpDocTypesAsCertain,
286-
private readonly bool $narrowMethodScopeFromConstructor = true,
286+
#[AutowiredParameter]
287+
private readonly bool $narrowMethodScopeFromConstructor,
287288
)
288289
{
289290
$earlyTerminatingMethodNames = [];

src/Testing/PHPStanTestCase.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ abstract class PHPStanTestCase extends TestCase
5555
/** @api */
5656
public static function getContainer(): Container
5757
{
58-
$additionalConfigFiles = static::getAdditionalConfigFiles();
59-
$additionalConfigFiles[] = __DIR__ . '/TestCase.neon';
58+
$additionalConfigFiles = [__DIR__ . '/TestCase.neon'];
59+
foreach (static::getAdditionalConfigFiles() as $configFile) {
60+
$additionalConfigFiles[] = $configFile;
61+
}
6062
$cacheKey = sha1(implode("\n", $additionalConfigFiles));
6163

6264
if (!isset(self::$containers[$cacheKey])) {

src/Testing/RuleTestCase.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected function createNodeScopeResolver(): NodeScopeResolver|GeneratorNodeSco
108108
[],
109109
self::getContainer()->getParameter('exceptions')['implicitThrows'],
110110
$this->shouldTreatPhpDocTypesAsCertain(),
111-
$this->shouldNarrowMethodScopeFromConstructor(),
111+
self::getContainer()->getParameter('narrowMethodScopeFromConstructor'),
112112
);
113113
}
114114

@@ -297,11 +297,6 @@ protected function shouldFailOnPhpErrors(): bool
297297
return true;
298298
}
299299

300-
protected function shouldNarrowMethodScopeFromConstructor(): bool
301-
{
302-
return false;
303-
}
304-
305300
public static function getAdditionalConfigFiles(): array
306301
{
307302
return [

src/Testing/TestCase.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
parameters:
22
inferPrivatePropertyTypeFromConstructor: true
3+
narrowMethodScopeFromConstructor: false
34

45
services:
56
-

src/Testing/TypeInferenceTestCase.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected static function createNodeScopeResolver(): NodeScopeResolver|Generator
8282
static::getEarlyTerminatingFunctionCalls(),
8383
self::getContainer()->getParameter('exceptions')['implicitThrows'],
8484
self::getContainer()->getParameter('treatPhpDocTypesAsCertain'),
85-
true,
85+
self::getContainer()->getParameter('narrowMethodScopeFromConstructor'),
8686
);
8787
}
8888

@@ -459,6 +459,16 @@ private static function isFileLintSkipped(string $file): bool
459459
return false;
460460
}
461461

462+
public static function getAdditionalConfigFiles(): array
463+
{
464+
return array_merge(
465+
parent::getAdditionalConfigFiles(),
466+
[
467+
__DIR__ . '/narrowMethodScopeFromConstructor.neon',
468+
],
469+
);
470+
}
471+
462472
/** @return string[] */
463473
protected static function getAdditionalAnalysedFiles(): array
464474
{
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parameters:
2+
narrowMethodScopeFromConstructor: true

0 commit comments

Comments
 (0)