Skip to content

Commit cc7ff8b

Browse files
committed
[BE] Remove rules about unreachable branches
1 parent 7d74a63 commit cc7ff8b

13 files changed

+5
-575
lines changed

changelog-2.0.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Major new features 🚀
1616
* [Learn more on phpstan.org](https://phpstan.org/blog/enhancements-in-handling-parameters-passed-by-reference)
1717
* [#2941](https://github.com/phpstan/phpstan-src/pull/2941), thanks @ljmaskey!
1818
* Check too wide private property type (level 4) (https://github.com/phpstan/phpstan-src/commit/7453f4f75fae3d635063589467842aae29d88b54)
19+
* Remove "unreachable branches" rules: UnreachableIfBranchesRule, UnreachableTernaryElseBranchRule, unreachable arm error in MatchExpressionRule
20+
* Because "always true" is always reported, these are no longer needed
1921
* LogicalXorConstantConditionRule (level 4) (https://github.com/phpstan/phpstan-src/commit/3a12724fd636b1bcf36c22b36e8f765d97150895, https://github.com/phpstan/phpstan-src/commit/3b011f6524254dad0f16840fdcfdbe7421548617), #7539
2022
* Check that each trait is used and analysed at least once (level 4) (https://github.com/phpstan/phpstan-src/commit/c4d05276fb8605d6ac20acbe1cc5df31cd6c10b0)
2123
* Check preg_quote delimiter sanity (level 0) ([#3252](https://github.com/phpstan/phpstan-src/pull/3252)), #11338, thanks @staabm!
@@ -66,8 +68,6 @@ Bleeding edge (TODO move to other sections)
6668
* Move IllegalConstructorMethodCallRule and IllegalConstructorStaticCallRule to phpstan-strict-rules (https://github.com/phpstan/phpstan-src/commit/124b30f98c182193187be0b9c2e151e477429b7a, https://github.com/phpstan/phpstan-strict-rules/commit/0c82c96f2a55d8b91bbc7ee6512c94f68a206b43)
6769
* Add `@readonly` rule that disallows default values ([#1391](https://github.com/phpstan/phpstan-src/pull/1391)), thanks @herndlm!
6870
* Always report always true conditions, except for last elseif and match arm ([#2105](https://github.com/phpstan/phpstan-src/pull/2105)), thanks @staabm!
69-
* Disable "unreachable branches" rules: UnreachableIfBranchesRule, UnreachableTernaryElseBranchRule, unreachable arm error in MatchExpressionRule
70-
* Because "always true" is always reported, these are no longer needed
7171
* Report narrowing `PHPStan\Type\Type` interface via `@var` (https://github.com/phpstan/phpstan-src/commit/713b98fb107213c28e3d8c8b4b43c5f5fc47c144), https://github.com/nunomaduro/larastan/issues/1567#issuecomment-1460445389
7272
* Check invalid PHPDocs in previously unchecked statement types (https://github.com/phpstan/phpstan-src/commit/9780d352f3264aac09ac7954f691de1877db8e01)
7373
* InvalidPHPStanDocTagRule in StubValidator (https://github.com/phpstan/phpstan-src/commit/9c2552b7e744926d1a74c1ba8fd32c64079eed61)

conf/bleedingEdge.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ parameters:
99
looseComparison: true
1010
readOnlyByPhpDoc: true
1111
alwaysTrueAlwaysReported: true
12-
disableUnreachableBranchesRules: true
1312
pure: true
1413
requireFileExists: true

conf/config.level4.neon

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ services:
197197
class: PHPStan\Rules\Comparison\MatchExpressionRule
198198
arguments:
199199
checkAlwaysTrueStrictComparison: %checkAlwaysTrueStrictComparison%
200-
disableUnreachable: %featureToggles.disableUnreachableBranchesRules%
201200
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
202201
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
203202
tags:
@@ -237,24 +236,6 @@ services:
237236
tags:
238237
- phpstan.rules.rule
239238

240-
-
241-
class: PHPStan\Rules\Comparison\UnreachableIfBranchesRule
242-
arguments:
243-
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
244-
disable: %featureToggles.disableUnreachableBranchesRules%
245-
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
246-
tags:
247-
- phpstan.rules.rule
248-
249-
-
250-
class: PHPStan\Rules\Comparison\UnreachableTernaryElseBranchRule
251-
arguments:
252-
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
253-
disable: %featureToggles.disableUnreachableBranchesRules%
254-
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
255-
tags:
256-
- phpstan.rules.rule
257-
258239
-
259240
class: PHPStan\Rules\Comparison\WhileLoopAlwaysFalseConditionRule
260241
arguments:

conf/config.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ parameters:
3030
looseComparison: false
3131
readOnlyByPhpDoc: false
3232
alwaysTrueAlwaysReported: false
33-
disableUnreachableBranchesRules: false
3433
stricterFunctionMap: false
3534
pure: false
3635
requireFileExists: false

conf/parametersSchema.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ parametersSchema:
3636
looseComparison: bool(),
3737
readOnlyByPhpDoc: bool()
3838
alwaysTrueAlwaysReported: bool()
39-
disableUnreachableBranchesRules: bool()
4039
stricterFunctionMap: bool()
4140
pure: bool()
4241
requireFileExists: bool()

phpstan-baseline.neon

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -491,16 +491,6 @@ parameters:
491491
count: 2
492492
path: src/Rules/Comparison/TernaryOperatorConstantConditionRule.php
493493

494-
-
495-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantBooleanType is error\\-prone and deprecated\\. Use Type\\:\\:isTrue\\(\\) or Type\\:\\:isFalse\\(\\) instead\\.$#"
496-
count: 1
497-
path: src/Rules/Comparison/UnreachableIfBranchesRule.php
498-
499-
-
500-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantBooleanType is error\\-prone and deprecated\\. Use Type\\:\\:isTrue\\(\\) or Type\\:\\:isFalse\\(\\) instead\\.$#"
501-
count: 1
502-
path: src/Rules/Comparison/UnreachableTernaryElseBranchRule.php
503-
504494
-
505495
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantBooleanType is error\\-prone and deprecated\\. Use Type\\:\\:isTrue\\(\\) or Type\\:\\:isFalse\\(\\) instead\\.$#"
506496
count: 1

src/Rules/Comparison/MatchExpressionRule.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ final class MatchExpressionRule implements Rule
2828
public function __construct(
2929
private ConstantConditionRuleHelper $constantConditionRuleHelper,
3030
private bool $checkAlwaysTrueStrictComparison,
31-
private bool $disableUnreachable,
3231
private bool $reportAlwaysTrueInLastCondition,
3332
private bool $treatPhpDocTypesAsCertain,
3433
)
@@ -54,12 +53,6 @@ public function processNode(Node $node, Scope $scope): array
5453
$nextArmIsDeadForNativeType
5554
|| ($nextArmIsDeadForType && $this->treatPhpDocTypesAsCertain)
5655
) {
57-
if (!$this->disableUnreachable) {
58-
$errors[] = RuleErrorBuilder::message('Match arm is unreachable because previous comparison is always true.')
59-
->identifier('match.unreachable')
60-
->line($arm->getLine())
61-
->build();
62-
}
6356
continue;
6457
}
6558
$armConditions = $arm->getConditions();

src/Rules/Comparison/UnreachableIfBranchesRule.php

Lines changed: 0 additions & 84 deletions
This file was deleted.

src/Rules/Comparison/UnreachableTernaryElseBranchRule.php

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)