Skip to content

Allow toggling treatPhpDocTypesAsCertain tip #3452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions conf/config.level4.neon
Original file line number Diff line number Diff line change
@@ -67,6 +67,7 @@ services:
checkAlwaysTrueInstanceof: %checkAlwaysTrueInstanceof%
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
tags:
- phpstan.rules.rule

@@ -76,6 +77,7 @@ services:
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
bleedingEdge: %featureToggles.bleedingEdge%
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
tags:
- phpstan.rules.rule

@@ -85,6 +87,7 @@ services:
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
bleedingEdge: %featureToggles.bleedingEdge%
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
tags:
- phpstan.rules.rule

@@ -93,6 +96,7 @@ services:
arguments:
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
tags:
- phpstan.rules.rule

@@ -149,6 +153,7 @@ services:
class: PHPStan\Rules\Comparison\DoWhileLoopConstantConditionRule
arguments:
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
tags:
- phpstan.rules.rule

@@ -157,13 +162,15 @@ services:
arguments:
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
tags:
- phpstan.rules.rule

-
class: PHPStan\Rules\Comparison\IfConstantConditionRule
arguments:
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
tags:
- phpstan.rules.rule

@@ -173,6 +180,7 @@ services:
checkAlwaysTrueCheckTypeFunctionCall: %checkAlwaysTrueCheckTypeFunctionCall%
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
tags:
- phpstan.rules.rule

@@ -182,6 +190,7 @@ services:
checkAlwaysTrueCheckTypeFunctionCall: %checkAlwaysTrueCheckTypeFunctionCall%
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
tags:
- phpstan.rules.rule

@@ -191,6 +200,7 @@ services:
checkAlwaysTrueCheckTypeFunctionCall: %checkAlwaysTrueCheckTypeFunctionCall%
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
tags:
- phpstan.rules.rule

@@ -199,6 +209,7 @@ services:
arguments:
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%

-
class: PHPStan\Rules\DeadCode\BetterNoopRule
@@ -217,6 +228,7 @@ services:
class: PHPStan\Rules\Comparison\NumberComparisonOperatorsConstantConditionRule
arguments:
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
tags:
- phpstan.rules.rule

@@ -226,6 +238,7 @@ services:
checkAlwaysTrueStrictComparison: %checkAlwaysTrueStrictComparison%
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
tags:
- phpstan.rules.rule

@@ -235,11 +248,13 @@ services:
checkAlwaysTrueLooseComparison: %checkAlwaysTrueLooseComparison%
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
reportAlwaysTrueInLastCondition: %reportAlwaysTrueInLastCondition%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%

-
class: PHPStan\Rules\Comparison\TernaryOperatorConstantConditionRule
arguments:
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
tags:
- phpstan.rules.rule

@@ -248,6 +263,7 @@ services:
arguments:
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
disable: %featureToggles.disableUnreachableBranchesRules%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
tags:
- phpstan.rules.rule

@@ -256,20 +272,23 @@ services:
arguments:
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
disable: %featureToggles.disableUnreachableBranchesRules%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
tags:
- phpstan.rules.rule

-
class: PHPStan\Rules\Comparison\WhileLoopAlwaysFalseConditionRule
arguments:
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
tags:
- phpstan.rules.rule

-
class: PHPStan\Rules\Comparison\WhileLoopAlwaysTrueConditionRule
arguments:
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%
tags:
- phpstan.rules.rule

2 changes: 2 additions & 0 deletions conf/config.level5.neon
Original file line number Diff line number Diff line change
@@ -34,11 +34,13 @@ services:
class: PHPStan\Rules\Functions\ArrayFilterRule
arguments:
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%

-
class: PHPStan\Rules\Functions\ArrayValuesRule
arguments:
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
treatPhpDocTypesAsCertainTip: %tips.treatPhpDocTypesAsCertain%

-
class: PHPStan\Rules\Functions\CallUserFuncRule
2 changes: 2 additions & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
@@ -161,6 +161,8 @@ parameters:
treatPhpDocTypesAsCertain: true
usePathConstantsAsConstantString: false
rememberPossiblyImpureFunctionValues: true
tips:
treatPhpDocTypesAsCertain: true
tipsOfTheDay: true
reportMagicMethods: false
reportMagicProperties: false
3 changes: 3 additions & 0 deletions conf/parametersSchema.neon
Original file line number Diff line number Diff line change
@@ -129,6 +129,9 @@ parametersSchema:
deprecationRulesInstalled: bool()
inferPrivatePropertyTypeFromConstructor: bool()

tips: structure([
treatPhpDocTypesAsCertain: bool()
])
tipsOfTheDay: bool()
reportMaybes: bool()
reportMaybesInMethodSignatures: bool()
5 changes: 5 additions & 0 deletions src/Rules/Classes/ImpossibleInstanceOfRule.php
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ public function __construct(
private bool $checkAlwaysTrueInstanceof,
private bool $treatPhpDocTypesAsCertain,
private bool $reportAlwaysTrueInLastCondition,
private bool $treatPhpDocTypesAsCertainTip,
)
{
}
@@ -71,6 +72,10 @@ public function processNode(Node $node, Scope $scope): array
return $ruleErrorBuilder;
}

if (!$this->treatPhpDocTypesAsCertainTip) {
return $ruleErrorBuilder;
}

return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
};

10 changes: 10 additions & 0 deletions src/Rules/Comparison/BooleanAndConstantConditionRule.php
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ public function __construct(
private bool $treatPhpDocTypesAsCertain,
private bool $bleedingEdge,
private bool $reportAlwaysTrueInLastCondition,
private bool $treatPhpDocTypesAsCertainTip,
)
{
}
@@ -52,6 +53,9 @@ public function processNode(
if ($booleanNativeType instanceof ConstantBooleanType) {
return $ruleErrorBuilder;
}
if (!$this->treatPhpDocTypesAsCertainTip) {
return $ruleErrorBuilder;
}

return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
};
@@ -90,6 +94,9 @@ public function processNode(
if ($booleanNativeType instanceof ConstantBooleanType) {
return $ruleErrorBuilder;
}
if (!$this->treatPhpDocTypesAsCertainTip) {
return $ruleErrorBuilder;
}

return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
};
@@ -122,6 +129,9 @@ public function processNode(
if ($booleanNativeType instanceof ConstantBooleanType) {
return $ruleErrorBuilder;
}
if (!$this->treatPhpDocTypesAsCertainTip) {
return $ruleErrorBuilder;
}

return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
};
4 changes: 4 additions & 0 deletions src/Rules/Comparison/BooleanNotConstantConditionRule.php
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ public function __construct(
private ConstantConditionRuleHelper $helper,
private bool $treatPhpDocTypesAsCertain,
private bool $reportAlwaysTrueInLastCondition,
private bool $treatPhpDocTypesAsCertainTip,
)
{
}
@@ -45,6 +46,9 @@ public function processNode(
if ($booleanNativeType instanceof ConstantBooleanType) {
return $ruleErrorBuilder;
}
if (!$this->treatPhpDocTypesAsCertainTip) {
return $ruleErrorBuilder;
}

return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
};
10 changes: 10 additions & 0 deletions src/Rules/Comparison/BooleanOrConstantConditionRule.php
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ public function __construct(
private bool $treatPhpDocTypesAsCertain,
private bool $bleedingEdge,
private bool $reportAlwaysTrueInLastCondition,
private bool $treatPhpDocTypesAsCertainTip,
)
{
}
@@ -52,6 +53,9 @@ public function processNode(
if ($booleanNativeType instanceof ConstantBooleanType) {
return $ruleErrorBuilder;
}
if (!$this->treatPhpDocTypesAsCertainTip) {
return $ruleErrorBuilder;
}

return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
};
@@ -90,6 +94,9 @@ public function processNode(
if ($booleanNativeType instanceof ConstantBooleanType) {
return $ruleErrorBuilder;
}
if (!$this->treatPhpDocTypesAsCertainTip) {
return $ruleErrorBuilder;
}

return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
};
@@ -122,6 +129,9 @@ public function processNode(
if ($booleanNativeType instanceof ConstantBooleanType) {
return $ruleErrorBuilder;
}
if (!$this->treatPhpDocTypesAsCertainTip) {
return $ruleErrorBuilder;
}

return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
};
4 changes: 4 additions & 0 deletions src/Rules/Comparison/ConstantLooseComparisonRule.php
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ public function __construct(
private bool $checkAlwaysTrueLooseComparison,
private bool $treatPhpDocTypesAsCertain,
private bool $reportAlwaysTrueInLastCondition,
private bool $treatPhpDocTypesAsCertainTip,
)
{
}
@@ -50,6 +51,9 @@ public function processNode(Node $node, Scope $scope): array
if ($instanceofTypeWithoutPhpDocs instanceof ConstantBooleanType) {
return $ruleErrorBuilder;
}
if (!$this->treatPhpDocTypesAsCertainTip) {
return $ruleErrorBuilder;
}

return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
};
4 changes: 4 additions & 0 deletions src/Rules/Comparison/DoWhileLoopConstantConditionRule.php
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ final class DoWhileLoopConstantConditionRule implements Rule
public function __construct(
private ConstantConditionRuleHelper $helper,
private bool $treatPhpDocTypesAsCertain,
private bool $treatPhpDocTypesAsCertainTip,
)
{
}
@@ -70,6 +71,9 @@ public function processNode(Node $node, Scope $scope): array
if ($booleanNativeType instanceof ConstantBooleanType) {
return $ruleErrorBuilder;
}
if (!$this->treatPhpDocTypesAsCertainTip) {
return $ruleErrorBuilder;
}

return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
};
4 changes: 4 additions & 0 deletions src/Rules/Comparison/ElseIfConstantConditionRule.php
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ public function __construct(
private ConstantConditionRuleHelper $helper,
private bool $treatPhpDocTypesAsCertain,
private bool $reportAlwaysTrueInLastCondition,
private bool $treatPhpDocTypesAsCertainTip,
)
{
}
@@ -45,6 +46,9 @@ public function processNode(
if ($booleanNativeType instanceof ConstantBooleanType) {
return $ruleErrorBuilder;
}
if (!$this->treatPhpDocTypesAsCertainTip) {
return $ruleErrorBuilder;
}

return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
};
4 changes: 4 additions & 0 deletions src/Rules/Comparison/IfConstantConditionRule.php
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ final class IfConstantConditionRule implements Rule
public function __construct(
private ConstantConditionRuleHelper $helper,
private bool $treatPhpDocTypesAsCertain,
private bool $treatPhpDocTypesAsCertainTip,
)
{
}
@@ -43,6 +44,9 @@ public function processNode(
if ($booleanNativeType instanceof ConstantBooleanType) {
return $ruleErrorBuilder;
}
if (!$this->treatPhpDocTypesAsCertainTip) {
return $ruleErrorBuilder;
}

return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
};
4 changes: 4 additions & 0 deletions src/Rules/Comparison/ImpossibleCheckTypeFunctionCallRule.php
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ public function __construct(
private bool $checkAlwaysTrueCheckTypeFunctionCall,
private bool $treatPhpDocTypesAsCertain,
private bool $reportAlwaysTrueInLastCondition,
private bool $treatPhpDocTypesAsCertainTip,
)
{
}
@@ -54,6 +55,9 @@ public function processNode(Node $node, Scope $scope): array
if ($isAlways !== null) {
return $ruleErrorBuilder;
}
if (!$this->treatPhpDocTypesAsCertainTip) {
return $ruleErrorBuilder;
}

return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
};
Loading
Loading