Skip to content

Commit

Permalink
[BCB] Removed polluteCatchScopeWithTryAssignments config parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 12, 2021
1 parent 492cfbc commit 8933c7e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 78 deletions.
3 changes: 0 additions & 3 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ parameters:
phpVersion: null
polluteScopeWithLoopInitialAssignments: true
polluteScopeWithAlwaysIterableForeach: true
polluteCatchScopeWithTryAssignments: false
propertyAlwaysWrittenTags: []
propertyAlwaysReadTags: []
additionalConstructors: []
Expand Down Expand Up @@ -285,7 +284,6 @@ parametersSchema:
phpVersion: schema(anyOf(schema(int(), min(70100), max(80099))), nullable())
polluteScopeWithLoopInitialAssignments: bool()
polluteScopeWithAlwaysIterableForeach: bool()
polluteCatchScopeWithTryAssignments: bool()
propertyAlwaysWrittenTags: listOf(string())
propertyAlwaysReadTags: listOf(string())
additionalConstructors: listOf(string())
Expand Down Expand Up @@ -477,7 +475,6 @@ services:
arguments:
classReflector: @nodeScopeResolverClassReflector
polluteScopeWithLoopInitialAssignments: %polluteScopeWithLoopInitialAssignments%
polluteCatchScopeWithTryAssignments: %polluteCatchScopeWithTryAssignments%
polluteScopeWithAlwaysIterableForeach: %polluteScopeWithAlwaysIterableForeach%
earlyTerminatingMethodCalls: %earlyTerminatingMethodCalls%
earlyTerminatingFunctionCalls: %earlyTerminatingFunctionCalls%
Expand Down
7 changes: 1 addition & 6 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ class NodeScopeResolver

private bool $polluteScopeWithLoopInitialAssignments;

private bool $polluteCatchScopeWithTryAssignments;

private bool $polluteScopeWithAlwaysIterableForeach;

/** @var string[][] className(string) => methods(string[]) */
Expand All @@ -176,7 +174,6 @@ class NodeScopeResolver
* @param FileHelper $fileHelper
* @param TypeSpecifier $typeSpecifier
* @param bool $polluteScopeWithLoopInitialAssignments
* @param bool $polluteCatchScopeWithTryAssignments
* @param bool $polluteScopeWithAlwaysIterableForeach
* @param string[][] $earlyTerminatingMethodCalls className(string) => methods(string[])
* @param array<int, string> $earlyTerminatingFunctionCalls
Expand All @@ -196,7 +193,6 @@ public function __construct(
TypeSpecifier $typeSpecifier,
DynamicThrowTypeExtensionProvider $dynamicThrowTypeExtensionProvider,
bool $polluteScopeWithLoopInitialAssignments,
bool $polluteCatchScopeWithTryAssignments,
bool $polluteScopeWithAlwaysIterableForeach,
array $earlyTerminatingMethodCalls,
array $earlyTerminatingFunctionCalls,
Expand All @@ -216,7 +212,6 @@ public function __construct(
$this->typeSpecifier = $typeSpecifier;
$this->dynamicThrowTypeExtensionProvider = $dynamicThrowTypeExtensionProvider;
$this->polluteScopeWithLoopInitialAssignments = $polluteScopeWithLoopInitialAssignments;
$this->polluteCatchScopeWithTryAssignments = $polluteCatchScopeWithTryAssignments;
$this->polluteScopeWithAlwaysIterableForeach = $polluteScopeWithAlwaysIterableForeach;
$this->earlyTerminatingMethodCalls = $earlyTerminatingMethodCalls;
$this->earlyTerminatingFunctionCalls = $earlyTerminatingFunctionCalls;
Expand Down Expand Up @@ -1185,7 +1180,7 @@ private function processStmtNode(
foreach ($stmt->catches as $catchNode) {
$nodeCallback($catchNode, $scope);

if ($this->preciseExceptionTracking || !$this->polluteCatchScopeWithTryAssignments) {
if ($this->preciseExceptionTracking) {
$catchType = TypeCombinator::union(...array_map(static function (Name $name): Type {
return new ObjectType($name->toString());
}, $catchNode->types));
Expand Down
6 changes: 0 additions & 6 deletions src/Testing/RuleTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ private function getAnalyser(): Analyser
$typeSpecifier,
self::getContainer()->getByType(DynamicThrowTypeExtensionProvider::class),
$this->shouldPolluteScopeWithLoopInitialAssignments(),
$this->shouldPolluteCatchScopeWithTryAssignments(),
$this->shouldPolluteScopeWithAlwaysIterableForeach(),
[],
[],
Expand Down Expand Up @@ -185,11 +184,6 @@ protected function shouldPolluteScopeWithLoopInitialAssignments(): bool
return false;
}

protected function shouldPolluteCatchScopeWithTryAssignments(): bool
{
return false;
}

protected function shouldPolluteScopeWithAlwaysIterableForeach(): bool
{
return true;
Expand Down
4 changes: 0 additions & 4 deletions src/Testing/TypeInferenceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
abstract class TypeInferenceTestCase extends \PHPStan\Testing\TestCase
{

/** @var bool */
protected $polluteCatchScopeWithTryAssignments = true;

/**
* @param string $file
* @param callable(\PhpParser\Node, \PHPStan\Analyser\Scope): void $callback
Expand Down Expand Up @@ -77,7 +74,6 @@ public function processFile(
$typeSpecifier,
self::getContainer()->getByType(DynamicThrowTypeExtensionProvider::class),
true,
$this->polluteCatchScopeWithTryAssignments,
true,
$this->getEarlyTerminatingMethodCalls(),
$this->getEarlyTerminatingFunctionCalls(),
Expand Down
39 changes: 12 additions & 27 deletions tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10360,33 +10360,18 @@ public function testTryCatchScope(
string $evaluatedPointExpression
): void
{
foreach ([true, false] as $polluteCatchScopeWithTryAssignments) {
$this->polluteCatchScopeWithTryAssignments = $polluteCatchScopeWithTryAssignments;

try {
$this->assertTypes(
__DIR__ . '/data/try-catch-scope.php',
$description,
$expression,
[],
[],
[],
[],
$evaluatedPointExpression,
[],
false
);
} catch (\PHPUnit\Framework\ExpectationFailedException $e) {
throw new \PHPUnit\Framework\ExpectationFailedException(
sprintf(
'%s (polluteCatchScopeWithTryAssignments: %s)',
$e->getMessage(),
$polluteCatchScopeWithTryAssignments ? 'true' : 'false'
),
$e->getComparisonFailure()
);
}
}
$this->assertTypes(
__DIR__ . '/data/try-catch-scope.php',
$description,
$expression,
[],
[],
[],
[],
$evaluatedPointExpression,
[],
false
);
}

/**
Expand Down
32 changes: 0 additions & 32 deletions tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ class DefinedVariableRuleTest extends \PHPStan\Testing\RuleTestCase
/** @var bool */
private $polluteScopeWithLoopInitialAssignments;

/** @var bool */
private $polluteCatchScopeWithTryAssignments;

/** @var bool */
private $polluteScopeWithAlwaysIterableForeach;

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

protected function shouldPolluteCatchScopeWithTryAssignments(): bool
{
return $this->polluteCatchScopeWithTryAssignments;
}

protected function shouldPolluteScopeWithAlwaysIterableForeach(): bool
{
return $this->polluteScopeWithAlwaysIterableForeach;
Expand All @@ -51,7 +43,6 @@ public function testDefinedVariables(): void
require_once __DIR__ . '/data/defined-variables-definition.php';
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/defined-variables.php'], [
Expand Down Expand Up @@ -254,7 +245,6 @@ public function testDefinedVariablesInClosures(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/defined-variables-closures.php'], [
Expand All @@ -269,7 +259,6 @@ public function testDefinedVariablesInShortArrayDestructuringSyntax(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/defined-variables-array-destructuring-short-syntax.php'], [
Expand All @@ -292,7 +281,6 @@ public function testCliArgumentsVariablesNotRegistered(): void
{
$this->cliArgumentsVariablesRegistered = false;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/cli-arguments-variables.php'], [
Expand All @@ -311,7 +299,6 @@ public function testCliArgumentsVariablesRegistered(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/cli-arguments-variables.php'], [
Expand Down Expand Up @@ -370,7 +357,6 @@ public function testLoopInitialAssignments(
): void
{
$this->cliArgumentsVariablesRegistered = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->polluteScopeWithLoopInitialAssignments = $polluteScopeWithLoopInitialAssignments;
$this->checkMaybeUndefinedVariables = $checkMaybeUndefinedVariables;
$this->polluteScopeWithAlwaysIterableForeach = true;
Expand All @@ -381,7 +367,6 @@ public function testDefineVariablesInClass(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/define-variables-class.php'], []);
Expand All @@ -391,7 +376,6 @@ public function testDeadBranches(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/dead-branches.php'], [
Expand Down Expand Up @@ -422,7 +406,6 @@ public function testForeach(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/foreach.php'], [
Expand Down Expand Up @@ -595,7 +578,6 @@ public function testForeachPolluteScopeWithAlwaysIterableForeach(bool $polluteSc
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = $polluteScopeWithAlwaysIterableForeach;
$this->analyse([__DIR__ . '/data/foreach-always-iterable.php'], $errors);
Expand All @@ -605,7 +587,6 @@ public function testBooleanOperatorsTruthyFalsey(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/boolean-op-truthy-falsey.php'], [
Expand All @@ -628,7 +609,6 @@ public function testArrowFunctions(): void

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

$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/defined-variables-coalesce-assign.php'], [
Expand All @@ -666,7 +645,6 @@ public function testBug2748(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/bug-2748.php'], [
Expand All @@ -685,7 +663,6 @@ public function testGlobalVariables(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/global-variables.php'], []);
Expand All @@ -695,7 +672,6 @@ public function testRootScopeMaybeDefined(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = false;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/root-scope-maybe.php'], []);
Expand All @@ -705,7 +681,6 @@ public function testRootScopeMaybeDefinedCheck(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/root-scope-maybe.php'], [
Expand All @@ -724,7 +699,6 @@ public function testFormerThisVariableRule(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/this.php'], [
Expand All @@ -751,7 +725,6 @@ public function testClosureUse(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/defined-variables-anonymous-function-use.php'], [
Expand Down Expand Up @@ -790,7 +763,6 @@ public function testNullsafeIsset(): void

$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/variable-nullsafe-isset.php'], []);
Expand All @@ -800,7 +772,6 @@ public function testBug1306(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/bug-1306.php'], []);
Expand All @@ -810,7 +781,6 @@ public function testBug3515(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/bug-3515.php'], [
Expand All @@ -829,7 +799,6 @@ public function testBug4412(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/bug-4412.php'], [
Expand All @@ -844,7 +813,6 @@ public function testBug3283(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->polluteCatchScopeWithTryAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/bug-3283.php'], []);
Expand Down

0 comments on commit 8933c7e

Please sign in to comment.