Skip to content

Commit d22c481

Browse files
committed
Remove checkAlwaysTrue* options
1 parent 59fd06a commit d22c481

20 files changed

+132
-167
lines changed

UPGRADING.md

+9
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ parameters:
6060
identifier: missingType.generics
6161
```
6262

63+
### Removed `checkAlwaysTrue*` options
64+
65+
These options have been removed because PHPStan now always behaves as if these were set to `true`:
66+
67+
* `checkAlwaysTrueCheckTypeFunctionCall`
68+
* `checkAlwaysTrueInstanceof`
69+
* `checkAlwaysTrueStrictComparison`
70+
* `checkAlwaysTrueLooseComparison`
71+
6372
### Removed option `excludes_analyse`
6473

6574
It has been replaced with [`excludePaths`](https://phpstan.org/user-guide/ignoring-errors#excluding-whole-files).

conf/config.level4.neon

-7
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ services:
5353
-
5454
class: PHPStan\Rules\Classes\ImpossibleInstanceOfRule
5555
arguments:
56-
checkAlwaysTrueInstanceof: %checkAlwaysTrueInstanceof%
5756
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
5857
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
5958
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
@@ -157,7 +156,6 @@ services:
157156
-
158157
class: PHPStan\Rules\Comparison\ImpossibleCheckTypeFunctionCallRule
159158
arguments:
160-
checkAlwaysTrueCheckTypeFunctionCall: %checkAlwaysTrueCheckTypeFunctionCall%
161159
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
162160
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
163161
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
@@ -167,7 +165,6 @@ services:
167165
-
168166
class: PHPStan\Rules\Comparison\ImpossibleCheckTypeMethodCallRule
169167
arguments:
170-
checkAlwaysTrueCheckTypeFunctionCall: %checkAlwaysTrueCheckTypeFunctionCall%
171168
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
172169
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
173170
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
@@ -177,7 +174,6 @@ services:
177174
-
178175
class: PHPStan\Rules\Comparison\ImpossibleCheckTypeStaticMethodCallRule
179176
arguments:
180-
checkAlwaysTrueCheckTypeFunctionCall: %checkAlwaysTrueCheckTypeFunctionCall%
181177
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
182178
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
183179
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
@@ -196,7 +192,6 @@ services:
196192
-
197193
class: PHPStan\Rules\Comparison\MatchExpressionRule
198194
arguments:
199-
checkAlwaysTrueStrictComparison: %checkAlwaysTrueStrictComparison%
200195
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
201196
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
202197
tags:
@@ -213,7 +208,6 @@ services:
213208
-
214209
class: PHPStan\Rules\Comparison\StrictComparisonOfDifferentTypesRule
215210
arguments:
216-
checkAlwaysTrueStrictComparison: %checkAlwaysTrueStrictComparison%
217211
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
218212
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
219213
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
@@ -223,7 +217,6 @@ services:
223217
-
224218
class: PHPStan\Rules\Comparison\ConstantLooseComparisonRule
225219
arguments:
226-
checkAlwaysTrueLooseComparison: %checkAlwaysTrueLooseComparison%
227220
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
228221
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
229222
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%

conf/config.neon

-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ parameters:
3535
fileExtensions:
3636
- php
3737
checkAdvancedIsset: false
38-
checkAlwaysTrueCheckTypeFunctionCall: true
39-
checkAlwaysTrueInstanceof: true
40-
checkAlwaysTrueStrictComparison: true
41-
checkAlwaysTrueLooseComparison: true
4238
reportAlwaysTrueInLastCondition: false
4339
checkClassCaseSensitivity: false
4440
checkExplicitMixed: false

conf/parametersSchema.neon

-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ parametersSchema:
4141
])
4242
fileExtensions: listOf(string())
4343
checkAdvancedIsset: bool()
44-
checkAlwaysTrueCheckTypeFunctionCall: bool()
45-
checkAlwaysTrueInstanceof: bool()
46-
checkAlwaysTrueStrictComparison: bool()
47-
checkAlwaysTrueLooseComparison: bool()
4844
reportAlwaysTrueInLastCondition: bool()
4945
checkClassCaseSensitivity: bool()
5046
checkExplicitMixed: bool()

src/Rules/Classes/ImpossibleInstanceOfRule.php

+16-19
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ final class ImpossibleInstanceOfRule implements Rule
2222
{
2323

2424
public function __construct(
25-
private bool $checkAlwaysTrueInstanceof,
2625
private bool $treatPhpDocTypesAsCertain,
2726
private bool $reportAlwaysTrueInLastCondition,
2827
private bool $treatPhpDocTypesAsCertainTip,
@@ -89,28 +88,26 @@ public function processNode(Node $node, Scope $scope): array
8988
$classType->describe(VerbosityLevel::getRecommendedLevelByType($classType)),
9089
)))->identifier('instanceof.alwaysFalse')->build(),
9190
];
92-
} elseif ($this->checkAlwaysTrueInstanceof) {
93-
$isLast = $node->getAttribute(LastConditionVisitor::ATTRIBUTE_NAME);
94-
if ($isLast === true && !$this->reportAlwaysTrueInLastCondition) {
95-
return [];
96-
}
97-
98-
$exprType = $this->treatPhpDocTypesAsCertain ? $scope->getType($node->expr) : $scope->getNativeType($node->expr);
99-
$errorBuilder = $addTip(RuleErrorBuilder::message(sprintf(
100-
'Instanceof between %s and %s will always evaluate to true.',
101-
$exprType->describe(VerbosityLevel::typeOnly()),
102-
$classType->describe(VerbosityLevel::getRecommendedLevelByType($classType)),
103-
)));
104-
if ($isLast === false && !$this->reportAlwaysTrueInLastCondition) {
105-
$errorBuilder->tip('Remove remaining cases below this one and this error will disappear too.');
106-
}
91+
}
10792

108-
$errorBuilder->identifier('instanceof.alwaysTrue');
93+
$isLast = $node->getAttribute(LastConditionVisitor::ATTRIBUTE_NAME);
94+
if ($isLast === true && !$this->reportAlwaysTrueInLastCondition) {
95+
return [];
96+
}
10997

110-
return [$errorBuilder->build()];
98+
$exprType = $this->treatPhpDocTypesAsCertain ? $scope->getType($node->expr) : $scope->getNativeType($node->expr);
99+
$errorBuilder = $addTip(RuleErrorBuilder::message(sprintf(
100+
'Instanceof between %s and %s will always evaluate to true.',
101+
$exprType->describe(VerbosityLevel::typeOnly()),
102+
$classType->describe(VerbosityLevel::getRecommendedLevelByType($classType)),
103+
)));
104+
if ($isLast === false && !$this->reportAlwaysTrueInLastCondition) {
105+
$errorBuilder->tip('Remove remaining cases below this one and this error will disappear too.');
111106
}
112107

113-
return [];
108+
$errorBuilder->identifier('instanceof.alwaysTrue');
109+
110+
return [$errorBuilder->build()];
114111
}
115112

116113
}

src/Rules/Comparison/ConstantLooseComparisonRule.php

+16-19
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ final class ConstantLooseComparisonRule implements Rule
1818
{
1919

2020
public function __construct(
21-
private bool $checkAlwaysTrueLooseComparison,
2221
private bool $treatPhpDocTypesAsCertain,
2322
private bool $reportAlwaysTrueInLastCondition,
2423
private bool $treatPhpDocTypesAsCertainTip,
@@ -67,28 +66,26 @@ public function processNode(Node $node, Scope $scope): array
6766
$scope->getType($node->right)->describe(VerbosityLevel::value()),
6867
)))->identifier(sprintf('%s.alwaysFalse', $node instanceof Node\Expr\BinaryOp\Equal ? 'equal' : 'notEqual'))->build(),
6968
];
70-
} elseif ($this->checkAlwaysTrueLooseComparison) {
71-
$isLast = $node->getAttribute(LastConditionVisitor::ATTRIBUTE_NAME);
72-
if ($isLast === true && !$this->reportAlwaysTrueInLastCondition) {
73-
return [];
74-
}
75-
76-
$errorBuilder = $addTip(RuleErrorBuilder::message(sprintf(
77-
'Loose comparison using %s between %s and %s will always evaluate to true.',
78-
$node->getOperatorSigil(),
79-
$scope->getType($node->left)->describe(VerbosityLevel::value()),
80-
$scope->getType($node->right)->describe(VerbosityLevel::value()),
81-
)));
82-
if ($isLast === false && !$this->reportAlwaysTrueInLastCondition) {
83-
$errorBuilder->tip('Remove remaining cases below this one and this error will disappear too.');
84-
}
69+
}
8570

86-
$errorBuilder->identifier(sprintf('%s.alwaysTrue', $node instanceof Node\Expr\BinaryOp\Equal ? 'equal' : 'notEqual'));
71+
$isLast = $node->getAttribute(LastConditionVisitor::ATTRIBUTE_NAME);
72+
if ($isLast === true && !$this->reportAlwaysTrueInLastCondition) {
73+
return [];
74+
}
8775

88-
return [$errorBuilder->build()];
76+
$errorBuilder = $addTip(RuleErrorBuilder::message(sprintf(
77+
'Loose comparison using %s between %s and %s will always evaluate to true.',
78+
$node->getOperatorSigil(),
79+
$scope->getType($node->left)->describe(VerbosityLevel::value()),
80+
$scope->getType($node->right)->describe(VerbosityLevel::value()),
81+
)));
82+
if ($isLast === false && !$this->reportAlwaysTrueInLastCondition) {
83+
$errorBuilder->tip('Remove remaining cases below this one and this error will disappear too.');
8984
}
9085

91-
return [];
86+
$errorBuilder->identifier(sprintf('%s.alwaysTrue', $node instanceof Node\Expr\BinaryOp\Equal ? 'equal' : 'notEqual'));
87+
88+
return [$errorBuilder->build()];
9289
}
9390

9491
}

src/Rules/Comparison/ImpossibleCheckTypeFunctionCallRule.php

+15-18
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ final class ImpossibleCheckTypeFunctionCallRule implements Rule
1818

1919
public function __construct(
2020
private ImpossibleCheckTypeHelper $impossibleCheckTypeHelper,
21-
private bool $checkAlwaysTrueCheckTypeFunctionCall,
2221
private bool $treatPhpDocTypesAsCertain,
2322
private bool $reportAlwaysTrueInLastCondition,
2423
private bool $treatPhpDocTypesAsCertainTip,
@@ -70,27 +69,25 @@ public function processNode(Node $node, Scope $scope): array
7069
$this->impossibleCheckTypeHelper->getArgumentsDescription($scope, $node->getArgs()),
7170
)))->identifier('function.impossibleType')->build(),
7271
];
73-
} elseif ($this->checkAlwaysTrueCheckTypeFunctionCall) {
74-
$isLast = $node->getAttribute(LastConditionVisitor::ATTRIBUTE_NAME);
75-
if ($isLast === true && !$this->reportAlwaysTrueInLastCondition) {
76-
return [];
77-
}
78-
79-
$errorBuilder = $addTip(RuleErrorBuilder::message(sprintf(
80-
'Call to function %s()%s will always evaluate to true.',
81-
$functionName,
82-
$this->impossibleCheckTypeHelper->getArgumentsDescription($scope, $node->getArgs()),
83-
)));
84-
if ($isLast === false && !$this->reportAlwaysTrueInLastCondition) {
85-
$errorBuilder->tip('Remove remaining cases below this one and this error will disappear too.');
86-
}
72+
}
8773

88-
$errorBuilder->identifier('function.alreadyNarrowedType');
74+
$isLast = $node->getAttribute(LastConditionVisitor::ATTRIBUTE_NAME);
75+
if ($isLast === true && !$this->reportAlwaysTrueInLastCondition) {
76+
return [];
77+
}
8978

90-
return [$errorBuilder->build()];
79+
$errorBuilder = $addTip(RuleErrorBuilder::message(sprintf(
80+
'Call to function %s()%s will always evaluate to true.',
81+
$functionName,
82+
$this->impossibleCheckTypeHelper->getArgumentsDescription($scope, $node->getArgs()),
83+
)));
84+
if ($isLast === false && !$this->reportAlwaysTrueInLastCondition) {
85+
$errorBuilder->tip('Remove remaining cases below this one and this error will disappear too.');
9186
}
9287

93-
return [];
88+
$errorBuilder->identifier('function.alreadyNarrowedType');
89+
90+
return [$errorBuilder->build()];
9491
}
9592

9693
}

src/Rules/Comparison/ImpossibleCheckTypeMethodCallRule.php

+17-20
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ final class ImpossibleCheckTypeMethodCallRule implements Rule
2020

2121
public function __construct(
2222
private ImpossibleCheckTypeHelper $impossibleCheckTypeHelper,
23-
private bool $checkAlwaysTrueCheckTypeFunctionCall,
2423
private bool $treatPhpDocTypesAsCertain,
2524
private bool $reportAlwaysTrueInLastCondition,
2625
private bool $treatPhpDocTypesAsCertainTip,
@@ -70,29 +69,27 @@ public function processNode(Node $node, Scope $scope): array
7069
$this->impossibleCheckTypeHelper->getArgumentsDescription($scope, $node->getArgs()),
7170
)))->identifier('method.impossibleType')->build(),
7271
];
73-
} elseif ($this->checkAlwaysTrueCheckTypeFunctionCall) {
74-
$isLast = $node->getAttribute(LastConditionVisitor::ATTRIBUTE_NAME);
75-
if ($isLast === true && !$this->reportAlwaysTrueInLastCondition) {
76-
return [];
77-
}
78-
79-
$method = $this->getMethod($node->var, $node->name->name, $scope);
80-
$errorBuilder = $addTip(RuleErrorBuilder::message(sprintf(
81-
'Call to method %s::%s()%s will always evaluate to true.',
82-
$method->getDeclaringClass()->getDisplayName(),
83-
$method->getName(),
84-
$this->impossibleCheckTypeHelper->getArgumentsDescription($scope, $node->getArgs()),
85-
)));
86-
if ($isLast === false && !$this->reportAlwaysTrueInLastCondition) {
87-
$errorBuilder->tip('Remove remaining cases below this one and this error will disappear too.');
88-
}
72+
}
8973

90-
$errorBuilder->identifier('method.alreadyNarrowedType');
74+
$isLast = $node->getAttribute(LastConditionVisitor::ATTRIBUTE_NAME);
75+
if ($isLast === true && !$this->reportAlwaysTrueInLastCondition) {
76+
return [];
77+
}
9178

92-
return [$errorBuilder->build()];
79+
$method = $this->getMethod($node->var, $node->name->name, $scope);
80+
$errorBuilder = $addTip(RuleErrorBuilder::message(sprintf(
81+
'Call to method %s::%s()%s will always evaluate to true.',
82+
$method->getDeclaringClass()->getDisplayName(),
83+
$method->getName(),
84+
$this->impossibleCheckTypeHelper->getArgumentsDescription($scope, $node->getArgs()),
85+
)));
86+
if ($isLast === false && !$this->reportAlwaysTrueInLastCondition) {
87+
$errorBuilder->tip('Remove remaining cases below this one and this error will disappear too.');
9388
}
9489

95-
return [];
90+
$errorBuilder->identifier('method.alreadyNarrowedType');
91+
92+
return [$errorBuilder->build()];
9693
}
9794

9895
private function getMethod(

src/Rules/Comparison/ImpossibleCheckTypeStaticMethodCallRule.php

+17-20
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ final class ImpossibleCheckTypeStaticMethodCallRule implements Rule
2020

2121
public function __construct(
2222
private ImpossibleCheckTypeHelper $impossibleCheckTypeHelper,
23-
private bool $checkAlwaysTrueCheckTypeFunctionCall,
2423
private bool $treatPhpDocTypesAsCertain,
2524
private bool $reportAlwaysTrueInLastCondition,
2625
private bool $treatPhpDocTypesAsCertainTip,
@@ -71,29 +70,27 @@ public function processNode(Node $node, Scope $scope): array
7170
$this->impossibleCheckTypeHelper->getArgumentsDescription($scope, $node->getArgs()),
7271
)))->identifier('staticMethod.impossibleType')->build(),
7372
];
74-
} elseif ($this->checkAlwaysTrueCheckTypeFunctionCall) {
75-
$isLast = $node->getAttribute(LastConditionVisitor::ATTRIBUTE_NAME);
76-
if ($isLast === true && !$this->reportAlwaysTrueInLastCondition) {
77-
return [];
78-
}
79-
80-
$method = $this->getMethod($node->class, $node->name->name, $scope);
81-
$errorBuilder = $addTip(RuleErrorBuilder::message(sprintf(
82-
'Call to static method %s::%s()%s will always evaluate to true.',
83-
$method->getDeclaringClass()->getDisplayName(),
84-
$method->getName(),
85-
$this->impossibleCheckTypeHelper->getArgumentsDescription($scope, $node->getArgs()),
86-
)));
87-
if ($isLast === false && !$this->reportAlwaysTrueInLastCondition) {
88-
$errorBuilder->tip('Remove remaining cases below this one and this error will disappear too.');
89-
}
73+
}
9074

91-
$errorBuilder->identifier('staticMethod.alreadyNarrowedType');
75+
$isLast = $node->getAttribute(LastConditionVisitor::ATTRIBUTE_NAME);
76+
if ($isLast === true && !$this->reportAlwaysTrueInLastCondition) {
77+
return [];
78+
}
9279

93-
return [$errorBuilder->build()];
80+
$method = $this->getMethod($node->class, $node->name->name, $scope);
81+
$errorBuilder = $addTip(RuleErrorBuilder::message(sprintf(
82+
'Call to static method %s::%s()%s will always evaluate to true.',
83+
$method->getDeclaringClass()->getDisplayName(),
84+
$method->getName(),
85+
$this->impossibleCheckTypeHelper->getArgumentsDescription($scope, $node->getArgs()),
86+
)));
87+
if ($isLast === false && !$this->reportAlwaysTrueInLastCondition) {
88+
$errorBuilder->tip('Remove remaining cases below this one and this error will disappear too.');
9489
}
9590

96-
return [];
91+
$errorBuilder->identifier('staticMethod.alreadyNarrowedType');
92+
93+
return [$errorBuilder->build()];
9794
}
9895

9996
/**

0 commit comments

Comments
 (0)