Skip to content

Commit 8933c7e

Browse files
committed
[BCB] Removed polluteCatchScopeWithTryAssignments config parameter
1 parent 492cfbc commit 8933c7e

File tree

6 files changed

+13
-78
lines changed

6 files changed

+13
-78
lines changed

conf/config.neon

-3
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ parameters:
9999
phpVersion: null
100100
polluteScopeWithLoopInitialAssignments: true
101101
polluteScopeWithAlwaysIterableForeach: true
102-
polluteCatchScopeWithTryAssignments: false
103102
propertyAlwaysWrittenTags: []
104103
propertyAlwaysReadTags: []
105104
additionalConstructors: []
@@ -285,7 +284,6 @@ parametersSchema:
285284
phpVersion: schema(anyOf(schema(int(), min(70100), max(80099))), nullable())
286285
polluteScopeWithLoopInitialAssignments: bool()
287286
polluteScopeWithAlwaysIterableForeach: bool()
288-
polluteCatchScopeWithTryAssignments: bool()
289287
propertyAlwaysWrittenTags: listOf(string())
290288
propertyAlwaysReadTags: listOf(string())
291289
additionalConstructors: listOf(string())
@@ -477,7 +475,6 @@ services:
477475
arguments:
478476
classReflector: @nodeScopeResolverClassReflector
479477
polluteScopeWithLoopInitialAssignments: %polluteScopeWithLoopInitialAssignments%
480-
polluteCatchScopeWithTryAssignments: %polluteCatchScopeWithTryAssignments%
481478
polluteScopeWithAlwaysIterableForeach: %polluteScopeWithAlwaysIterableForeach%
482479
earlyTerminatingMethodCalls: %earlyTerminatingMethodCalls%
483480
earlyTerminatingFunctionCalls: %earlyTerminatingFunctionCalls%

src/Analyser/NodeScopeResolver.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ class NodeScopeResolver
150150

151151
private bool $polluteScopeWithLoopInitialAssignments;
152152

153-
private bool $polluteCatchScopeWithTryAssignments;
154-
155153
private bool $polluteScopeWithAlwaysIterableForeach;
156154

157155
/** @var string[][] className(string) => methods(string[]) */
@@ -176,7 +174,6 @@ class NodeScopeResolver
176174
* @param FileHelper $fileHelper
177175
* @param TypeSpecifier $typeSpecifier
178176
* @param bool $polluteScopeWithLoopInitialAssignments
179-
* @param bool $polluteCatchScopeWithTryAssignments
180177
* @param bool $polluteScopeWithAlwaysIterableForeach
181178
* @param string[][] $earlyTerminatingMethodCalls className(string) => methods(string[])
182179
* @param array<int, string> $earlyTerminatingFunctionCalls
@@ -196,7 +193,6 @@ public function __construct(
196193
TypeSpecifier $typeSpecifier,
197194
DynamicThrowTypeExtensionProvider $dynamicThrowTypeExtensionProvider,
198195
bool $polluteScopeWithLoopInitialAssignments,
199-
bool $polluteCatchScopeWithTryAssignments,
200196
bool $polluteScopeWithAlwaysIterableForeach,
201197
array $earlyTerminatingMethodCalls,
202198
array $earlyTerminatingFunctionCalls,
@@ -216,7 +212,6 @@ public function __construct(
216212
$this->typeSpecifier = $typeSpecifier;
217213
$this->dynamicThrowTypeExtensionProvider = $dynamicThrowTypeExtensionProvider;
218214
$this->polluteScopeWithLoopInitialAssignments = $polluteScopeWithLoopInitialAssignments;
219-
$this->polluteCatchScopeWithTryAssignments = $polluteCatchScopeWithTryAssignments;
220215
$this->polluteScopeWithAlwaysIterableForeach = $polluteScopeWithAlwaysIterableForeach;
221216
$this->earlyTerminatingMethodCalls = $earlyTerminatingMethodCalls;
222217
$this->earlyTerminatingFunctionCalls = $earlyTerminatingFunctionCalls;
@@ -1185,7 +1180,7 @@ private function processStmtNode(
11851180
foreach ($stmt->catches as $catchNode) {
11861181
$nodeCallback($catchNode, $scope);
11871182

1188-
if ($this->preciseExceptionTracking || !$this->polluteCatchScopeWithTryAssignments) {
1183+
if ($this->preciseExceptionTracking) {
11891184
$catchType = TypeCombinator::union(...array_map(static function (Name $name): Type {
11901185
return new ObjectType($name->toString());
11911186
}, $catchNode->types));

src/Testing/RuleTestCase.php

-6
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ private function getAnalyser(): Analyser
8585
$typeSpecifier,
8686
self::getContainer()->getByType(DynamicThrowTypeExtensionProvider::class),
8787
$this->shouldPolluteScopeWithLoopInitialAssignments(),
88-
$this->shouldPolluteCatchScopeWithTryAssignments(),
8988
$this->shouldPolluteScopeWithAlwaysIterableForeach(),
9089
[],
9190
[],
@@ -185,11 +184,6 @@ protected function shouldPolluteScopeWithLoopInitialAssignments(): bool
185184
return false;
186185
}
187186

188-
protected function shouldPolluteCatchScopeWithTryAssignments(): bool
189-
{
190-
return false;
191-
}
192-
193187
protected function shouldPolluteScopeWithAlwaysIterableForeach(): bool
194188
{
195189
return true;

src/Testing/TypeInferenceTestCase.php

-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
abstract class TypeInferenceTestCase extends \PHPStan\Testing\TestCase
3232
{
3333

34-
/** @var bool */
35-
protected $polluteCatchScopeWithTryAssignments = true;
36-
3734
/**
3835
* @param string $file
3936
* @param callable(\PhpParser\Node, \PHPStan\Analyser\Scope): void $callback
@@ -77,7 +74,6 @@ public function processFile(
7774
$typeSpecifier,
7875
self::getContainer()->getByType(DynamicThrowTypeExtensionProvider::class),
7976
true,
80-
$this->polluteCatchScopeWithTryAssignments,
8177
true,
8278
$this->getEarlyTerminatingMethodCalls(),
8379
$this->getEarlyTerminatingFunctionCalls(),

tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php

+12-27
Original file line numberDiff line numberDiff line change
@@ -10360,33 +10360,18 @@ public function testTryCatchScope(
1036010360
string $evaluatedPointExpression
1036110361
): void
1036210362
{
10363-
foreach ([true, false] as $polluteCatchScopeWithTryAssignments) {
10364-
$this->polluteCatchScopeWithTryAssignments = $polluteCatchScopeWithTryAssignments;
10365-
10366-
try {
10367-
$this->assertTypes(
10368-
__DIR__ . '/data/try-catch-scope.php',
10369-
$description,
10370-
$expression,
10371-
[],
10372-
[],
10373-
[],
10374-
[],
10375-
$evaluatedPointExpression,
10376-
[],
10377-
false
10378-
);
10379-
} catch (\PHPUnit\Framework\ExpectationFailedException $e) {
10380-
throw new \PHPUnit\Framework\ExpectationFailedException(
10381-
sprintf(
10382-
'%s (polluteCatchScopeWithTryAssignments: %s)',
10383-
$e->getMessage(),
10384-
$polluteCatchScopeWithTryAssignments ? 'true' : 'false'
10385-
),
10386-
$e->getComparisonFailure()
10387-
);
10388-
}
10389-
}
10363+
$this->assertTypes(
10364+
__DIR__ . '/data/try-catch-scope.php',
10365+
$description,
10366+
$expression,
10367+
[],
10368+
[],
10369+
[],
10370+
[],
10371+
$evaluatedPointExpression,
10372+
[],
10373+
false
10374+
);
1039010375
}
1039110376

1039210377
/**

tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php

-32
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ class DefinedVariableRuleTest extends \PHPStan\Testing\RuleTestCase
1717
/** @var bool */
1818
private $polluteScopeWithLoopInitialAssignments;
1919

20-
/** @var bool */
21-
private $polluteCatchScopeWithTryAssignments;
22-
2320
/** @var bool */
2421
private $polluteScopeWithAlwaysIterableForeach;
2522

@@ -36,11 +33,6 @@ protected function shouldPolluteScopeWithLoopInitialAssignments(): bool
3633
return $this->polluteScopeWithLoopInitialAssignments;
3734
}
3835

39-
protected function shouldPolluteCatchScopeWithTryAssignments(): bool
40-
{
41-
return $this->polluteCatchScopeWithTryAssignments;
42-
}
43-
4436
protected function shouldPolluteScopeWithAlwaysIterableForeach(): bool
4537
{
4638
return $this->polluteScopeWithAlwaysIterableForeach;
@@ -51,7 +43,6 @@ public function testDefinedVariables(): void
5143
require_once __DIR__ . '/data/defined-variables-definition.php';
5244
$this->cliArgumentsVariablesRegistered = true;
5345
$this->polluteScopeWithLoopInitialAssignments = false;
54-
$this->polluteCatchScopeWithTryAssignments = false;
5546
$this->checkMaybeUndefinedVariables = true;
5647
$this->polluteScopeWithAlwaysIterableForeach = true;
5748
$this->analyse([__DIR__ . '/data/defined-variables.php'], [
@@ -254,7 +245,6 @@ public function testDefinedVariablesInClosures(): void
254245
{
255246
$this->cliArgumentsVariablesRegistered = true;
256247
$this->polluteScopeWithLoopInitialAssignments = false;
257-
$this->polluteCatchScopeWithTryAssignments = false;
258248
$this->checkMaybeUndefinedVariables = true;
259249
$this->polluteScopeWithAlwaysIterableForeach = true;
260250
$this->analyse([__DIR__ . '/data/defined-variables-closures.php'], [
@@ -269,7 +259,6 @@ public function testDefinedVariablesInShortArrayDestructuringSyntax(): void
269259
{
270260
$this->cliArgumentsVariablesRegistered = true;
271261
$this->polluteScopeWithLoopInitialAssignments = false;
272-
$this->polluteCatchScopeWithTryAssignments = false;
273262
$this->checkMaybeUndefinedVariables = true;
274263
$this->polluteScopeWithAlwaysIterableForeach = true;
275264
$this->analyse([__DIR__ . '/data/defined-variables-array-destructuring-short-syntax.php'], [
@@ -292,7 +281,6 @@ public function testCliArgumentsVariablesNotRegistered(): void
292281
{
293282
$this->cliArgumentsVariablesRegistered = false;
294283
$this->polluteScopeWithLoopInitialAssignments = false;
295-
$this->polluteCatchScopeWithTryAssignments = false;
296284
$this->checkMaybeUndefinedVariables = true;
297285
$this->polluteScopeWithAlwaysIterableForeach = true;
298286
$this->analyse([__DIR__ . '/data/cli-arguments-variables.php'], [
@@ -311,7 +299,6 @@ public function testCliArgumentsVariablesRegistered(): void
311299
{
312300
$this->cliArgumentsVariablesRegistered = true;
313301
$this->polluteScopeWithLoopInitialAssignments = false;
314-
$this->polluteCatchScopeWithTryAssignments = false;
315302
$this->checkMaybeUndefinedVariables = true;
316303
$this->polluteScopeWithAlwaysIterableForeach = true;
317304
$this->analyse([__DIR__ . '/data/cli-arguments-variables.php'], [
@@ -370,7 +357,6 @@ public function testLoopInitialAssignments(
370357
): void
371358
{
372359
$this->cliArgumentsVariablesRegistered = false;
373-
$this->polluteCatchScopeWithTryAssignments = false;
374360
$this->polluteScopeWithLoopInitialAssignments = $polluteScopeWithLoopInitialAssignments;
375361
$this->checkMaybeUndefinedVariables = $checkMaybeUndefinedVariables;
376362
$this->polluteScopeWithAlwaysIterableForeach = true;
@@ -381,7 +367,6 @@ public function testDefineVariablesInClass(): void
381367
{
382368
$this->cliArgumentsVariablesRegistered = true;
383369
$this->polluteScopeWithLoopInitialAssignments = false;
384-
$this->polluteCatchScopeWithTryAssignments = false;
385370
$this->checkMaybeUndefinedVariables = true;
386371
$this->polluteScopeWithAlwaysIterableForeach = true;
387372
$this->analyse([__DIR__ . '/data/define-variables-class.php'], []);
@@ -391,7 +376,6 @@ public function testDeadBranches(): void
391376
{
392377
$this->cliArgumentsVariablesRegistered = true;
393378
$this->polluteScopeWithLoopInitialAssignments = false;
394-
$this->polluteCatchScopeWithTryAssignments = false;
395379
$this->checkMaybeUndefinedVariables = true;
396380
$this->polluteScopeWithAlwaysIterableForeach = true;
397381
$this->analyse([__DIR__ . '/data/dead-branches.php'], [
@@ -422,7 +406,6 @@ public function testForeach(): void
422406
{
423407
$this->cliArgumentsVariablesRegistered = true;
424408
$this->polluteScopeWithLoopInitialAssignments = false;
425-
$this->polluteCatchScopeWithTryAssignments = false;
426409
$this->checkMaybeUndefinedVariables = true;
427410
$this->polluteScopeWithAlwaysIterableForeach = true;
428411
$this->analyse([__DIR__ . '/data/foreach.php'], [
@@ -595,7 +578,6 @@ public function testForeachPolluteScopeWithAlwaysIterableForeach(bool $polluteSc
595578
{
596579
$this->cliArgumentsVariablesRegistered = true;
597580
$this->polluteScopeWithLoopInitialAssignments = false;
598-
$this->polluteCatchScopeWithTryAssignments = false;
599581
$this->checkMaybeUndefinedVariables = true;
600582
$this->polluteScopeWithAlwaysIterableForeach = $polluteScopeWithAlwaysIterableForeach;
601583
$this->analyse([__DIR__ . '/data/foreach-always-iterable.php'], $errors);
@@ -605,7 +587,6 @@ public function testBooleanOperatorsTruthyFalsey(): void
605587
{
606588
$this->cliArgumentsVariablesRegistered = true;
607589
$this->polluteScopeWithLoopInitialAssignments = false;
608-
$this->polluteCatchScopeWithTryAssignments = false;
609590
$this->checkMaybeUndefinedVariables = true;
610591
$this->polluteScopeWithAlwaysIterableForeach = true;
611592
$this->analyse([__DIR__ . '/data/boolean-op-truthy-falsey.php'], [
@@ -628,7 +609,6 @@ public function testArrowFunctions(): void
628609

629610
$this->cliArgumentsVariablesRegistered = true;
630611
$this->polluteScopeWithLoopInitialAssignments = false;
631-
$this->polluteCatchScopeWithTryAssignments = false;
632612
$this->checkMaybeUndefinedVariables = true;
633613
$this->polluteScopeWithAlwaysIterableForeach = true;
634614
$this->analyse([__DIR__ . '/data/defined-variables-arrow-functions.php'], [
@@ -651,7 +631,6 @@ public function testCoalesceAssign(): void
651631

652632
$this->cliArgumentsVariablesRegistered = true;
653633
$this->polluteScopeWithLoopInitialAssignments = false;
654-
$this->polluteCatchScopeWithTryAssignments = false;
655634
$this->checkMaybeUndefinedVariables = true;
656635
$this->polluteScopeWithAlwaysIterableForeach = true;
657636
$this->analyse([__DIR__ . '/data/defined-variables-coalesce-assign.php'], [
@@ -666,7 +645,6 @@ public function testBug2748(): void
666645
{
667646
$this->cliArgumentsVariablesRegistered = true;
668647
$this->polluteScopeWithLoopInitialAssignments = false;
669-
$this->polluteCatchScopeWithTryAssignments = false;
670648
$this->checkMaybeUndefinedVariables = true;
671649
$this->polluteScopeWithAlwaysIterableForeach = true;
672650
$this->analyse([__DIR__ . '/data/bug-2748.php'], [
@@ -685,7 +663,6 @@ public function testGlobalVariables(): void
685663
{
686664
$this->cliArgumentsVariablesRegistered = true;
687665
$this->polluteScopeWithLoopInitialAssignments = false;
688-
$this->polluteCatchScopeWithTryAssignments = false;
689666
$this->checkMaybeUndefinedVariables = true;
690667
$this->polluteScopeWithAlwaysIterableForeach = true;
691668
$this->analyse([__DIR__ . '/data/global-variables.php'], []);
@@ -695,7 +672,6 @@ public function testRootScopeMaybeDefined(): void
695672
{
696673
$this->cliArgumentsVariablesRegistered = true;
697674
$this->polluteScopeWithLoopInitialAssignments = false;
698-
$this->polluteCatchScopeWithTryAssignments = false;
699675
$this->checkMaybeUndefinedVariables = false;
700676
$this->polluteScopeWithAlwaysIterableForeach = true;
701677
$this->analyse([__DIR__ . '/data/root-scope-maybe.php'], []);
@@ -705,7 +681,6 @@ public function testRootScopeMaybeDefinedCheck(): void
705681
{
706682
$this->cliArgumentsVariablesRegistered = true;
707683
$this->polluteScopeWithLoopInitialAssignments = false;
708-
$this->polluteCatchScopeWithTryAssignments = false;
709684
$this->checkMaybeUndefinedVariables = true;
710685
$this->polluteScopeWithAlwaysIterableForeach = true;
711686
$this->analyse([__DIR__ . '/data/root-scope-maybe.php'], [
@@ -724,7 +699,6 @@ public function testFormerThisVariableRule(): void
724699
{
725700
$this->cliArgumentsVariablesRegistered = true;
726701
$this->polluteScopeWithLoopInitialAssignments = false;
727-
$this->polluteCatchScopeWithTryAssignments = false;
728702
$this->checkMaybeUndefinedVariables = true;
729703
$this->polluteScopeWithAlwaysIterableForeach = true;
730704
$this->analyse([__DIR__ . '/data/this.php'], [
@@ -751,7 +725,6 @@ public function testClosureUse(): void
751725
{
752726
$this->cliArgumentsVariablesRegistered = true;
753727
$this->polluteScopeWithLoopInitialAssignments = false;
754-
$this->polluteCatchScopeWithTryAssignments = false;
755728
$this->checkMaybeUndefinedVariables = true;
756729
$this->polluteScopeWithAlwaysIterableForeach = true;
757730
$this->analyse([__DIR__ . '/data/defined-variables-anonymous-function-use.php'], [
@@ -790,7 +763,6 @@ public function testNullsafeIsset(): void
790763

791764
$this->cliArgumentsVariablesRegistered = true;
792765
$this->polluteScopeWithLoopInitialAssignments = false;
793-
$this->polluteCatchScopeWithTryAssignments = false;
794766
$this->checkMaybeUndefinedVariables = true;
795767
$this->polluteScopeWithAlwaysIterableForeach = true;
796768
$this->analyse([__DIR__ . '/data/variable-nullsafe-isset.php'], []);
@@ -800,7 +772,6 @@ public function testBug1306(): void
800772
{
801773
$this->cliArgumentsVariablesRegistered = true;
802774
$this->polluteScopeWithLoopInitialAssignments = false;
803-
$this->polluteCatchScopeWithTryAssignments = false;
804775
$this->checkMaybeUndefinedVariables = true;
805776
$this->polluteScopeWithAlwaysIterableForeach = true;
806777
$this->analyse([__DIR__ . '/data/bug-1306.php'], []);
@@ -810,7 +781,6 @@ public function testBug3515(): void
810781
{
811782
$this->cliArgumentsVariablesRegistered = true;
812783
$this->polluteScopeWithLoopInitialAssignments = false;
813-
$this->polluteCatchScopeWithTryAssignments = false;
814784
$this->checkMaybeUndefinedVariables = true;
815785
$this->polluteScopeWithAlwaysIterableForeach = true;
816786
$this->analyse([__DIR__ . '/data/bug-3515.php'], [
@@ -829,7 +799,6 @@ public function testBug4412(): void
829799
{
830800
$this->cliArgumentsVariablesRegistered = true;
831801
$this->polluteScopeWithLoopInitialAssignments = false;
832-
$this->polluteCatchScopeWithTryAssignments = false;
833802
$this->checkMaybeUndefinedVariables = true;
834803
$this->polluteScopeWithAlwaysIterableForeach = true;
835804
$this->analyse([__DIR__ . '/data/bug-4412.php'], [
@@ -844,7 +813,6 @@ public function testBug3283(): void
844813
{
845814
$this->cliArgumentsVariablesRegistered = true;
846815
$this->polluteScopeWithLoopInitialAssignments = false;
847-
$this->polluteCatchScopeWithTryAssignments = false;
848816
$this->checkMaybeUndefinedVariables = true;
849817
$this->polluteScopeWithAlwaysIterableForeach = true;
850818
$this->analyse([__DIR__ . '/data/bug-3283.php'], []);

0 commit comments

Comments
 (0)