Skip to content

Commit a16184e

Browse files
authored
Introduce RuleErrorBuilder::treatPhpDocTypesAsCertainTip() for a bit more DRYness
1 parent b323fc3 commit a16184e

22 files changed

+46
-40
lines changed

src/Rules/Classes/ImpossibleInstanceOfRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function processNode(Node $node, Scope $scope): array
7171
return $ruleErrorBuilder;
7272
}
7373

74-
return $ruleErrorBuilder->tip('Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.');
74+
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
7575
};
7676

7777
if (!$instanceofType->getValue()) {

src/Rules/Comparison/BooleanAndConstantConditionRule.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ public function processNode(
4242
$nodeText = $this->bleedingEdge ? $originalNode->getOperatorSigil() : '&&';
4343
$leftType = $this->helper->getBooleanType($scope, $originalNode->left);
4444
$identifierType = $originalNode instanceof Node\Expr\BinaryOp\BooleanAnd ? 'booleanAnd' : 'logicalAnd';
45-
$tipText = 'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.';
4645
if ($leftType instanceof ConstantBooleanType) {
47-
$addTipLeft = function (RuleErrorBuilder $ruleErrorBuilder) use ($scope, $tipText, $originalNode): RuleErrorBuilder {
46+
$addTipLeft = function (RuleErrorBuilder $ruleErrorBuilder) use ($scope, $originalNode): RuleErrorBuilder {
4847
if (!$this->treatPhpDocTypesAsCertain) {
4948
return $ruleErrorBuilder;
5049
}
@@ -54,7 +53,7 @@ public function processNode(
5453
return $ruleErrorBuilder;
5554
}
5655

57-
return $ruleErrorBuilder->tip($tipText);
56+
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
5857
};
5958

6059
$isLast = $node->getAttribute(LastConditionVisitor::ATTRIBUTE_NAME);
@@ -79,7 +78,7 @@ public function processNode(
7978
$originalNode->right,
8079
);
8180
if ($rightType instanceof ConstantBooleanType && !$scope->isInFirstLevelStatement()) {
82-
$addTipRight = function (RuleErrorBuilder $ruleErrorBuilder) use ($rightScope, $originalNode, $tipText): RuleErrorBuilder {
81+
$addTipRight = function (RuleErrorBuilder $ruleErrorBuilder) use ($rightScope, $originalNode): RuleErrorBuilder {
8382
if (!$this->treatPhpDocTypesAsCertain) {
8483
return $ruleErrorBuilder;
8584
}
@@ -92,7 +91,7 @@ public function processNode(
9291
return $ruleErrorBuilder;
9392
}
9493

95-
return $ruleErrorBuilder->tip($tipText);
94+
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
9695
};
9796

9897
$isLast = $node->getAttribute(LastConditionVisitor::ATTRIBUTE_NAME);
@@ -114,7 +113,7 @@ public function processNode(
114113
if (count($errors) === 0 && !$scope->isInFirstLevelStatement()) {
115114
$nodeType = $this->treatPhpDocTypesAsCertain ? $scope->getType($originalNode) : $scope->getNativeType($originalNode);
116115
if ($nodeType instanceof ConstantBooleanType) {
117-
$addTip = function (RuleErrorBuilder $ruleErrorBuilder) use ($scope, $originalNode, $tipText): RuleErrorBuilder {
116+
$addTip = function (RuleErrorBuilder $ruleErrorBuilder) use ($scope, $originalNode): RuleErrorBuilder {
118117
if (!$this->treatPhpDocTypesAsCertain) {
119118
return $ruleErrorBuilder;
120119
}
@@ -124,7 +123,7 @@ public function processNode(
124123
return $ruleErrorBuilder;
125124
}
126125

127-
return $ruleErrorBuilder->tip($tipText);
126+
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
128127
};
129128

130129
$isLast = $node->getAttribute(LastConditionVisitor::ATTRIBUTE_NAME);

src/Rules/Comparison/BooleanNotConstantConditionRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function processNode(
4646
return $ruleErrorBuilder;
4747
}
4848

49-
return $ruleErrorBuilder->tip('Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.');
49+
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
5050
};
5151

5252
$isLast = $node->getAttribute(LastConditionVisitor::ATTRIBUTE_NAME);

src/Rules/Comparison/BooleanOrConstantConditionRule.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ public function processNode(
4242
$messages = [];
4343
$leftType = $this->helper->getBooleanType($scope, $originalNode->left);
4444
$identifierType = $originalNode instanceof Node\Expr\BinaryOp\BooleanOr ? 'booleanOr' : 'logicalOr';
45-
$tipText = 'Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.';
4645
if ($leftType instanceof ConstantBooleanType) {
47-
$addTipLeft = function (RuleErrorBuilder $ruleErrorBuilder) use ($scope, $originalNode, $tipText): RuleErrorBuilder {
46+
$addTipLeft = function (RuleErrorBuilder $ruleErrorBuilder) use ($scope, $originalNode): RuleErrorBuilder {
4847
if (!$this->treatPhpDocTypesAsCertain) {
4948
return $ruleErrorBuilder;
5049
}
@@ -54,7 +53,7 @@ public function processNode(
5453
return $ruleErrorBuilder;
5554
}
5655

57-
return $ruleErrorBuilder->tip($tipText);
56+
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
5857
};
5958

6059
$isLast = $node->getAttribute(LastConditionVisitor::ATTRIBUTE_NAME);
@@ -79,7 +78,7 @@ public function processNode(
7978
$originalNode->right,
8079
);
8180
if ($rightType instanceof ConstantBooleanType && !$scope->isInFirstLevelStatement()) {
82-
$addTipRight = function (RuleErrorBuilder $ruleErrorBuilder) use ($rightScope, $originalNode, $tipText): RuleErrorBuilder {
81+
$addTipRight = function (RuleErrorBuilder $ruleErrorBuilder) use ($rightScope, $originalNode): RuleErrorBuilder {
8382
if (!$this->treatPhpDocTypesAsCertain) {
8483
return $ruleErrorBuilder;
8584
}
@@ -92,7 +91,7 @@ public function processNode(
9291
return $ruleErrorBuilder;
9392
}
9493

95-
return $ruleErrorBuilder->tip($tipText);
94+
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
9695
};
9796

9897
$isLast = $node->getAttribute(LastConditionVisitor::ATTRIBUTE_NAME);
@@ -114,7 +113,7 @@ public function processNode(
114113
if (count($messages) === 0 && !$scope->isInFirstLevelStatement()) {
115114
$nodeType = $this->treatPhpDocTypesAsCertain ? $scope->getType($originalNode) : $scope->getNativeType($originalNode);
116115
if ($nodeType instanceof ConstantBooleanType) {
117-
$addTip = function (RuleErrorBuilder $ruleErrorBuilder) use ($scope, $originalNode, $tipText): RuleErrorBuilder {
116+
$addTip = function (RuleErrorBuilder $ruleErrorBuilder) use ($scope, $originalNode): RuleErrorBuilder {
118117
if (!$this->treatPhpDocTypesAsCertain) {
119118
return $ruleErrorBuilder;
120119
}
@@ -124,7 +123,7 @@ public function processNode(
124123
return $ruleErrorBuilder;
125124
}
126125

127-
return $ruleErrorBuilder->tip($tipText);
126+
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
128127
};
129128

130129
$isLast = $node->getAttribute(LastConditionVisitor::ATTRIBUTE_NAME);

src/Rules/Comparison/ConstantLooseComparisonRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function processNode(Node $node, Scope $scope): array
5151
return $ruleErrorBuilder;
5252
}
5353

54-
return $ruleErrorBuilder->tip('Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.');
54+
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
5555
};
5656

5757
if (!$nodeType->getValue()) {

src/Rules/Comparison/DoWhileLoopConstantConditionRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function processNode(Node $node, Scope $scope): array
7171
return $ruleErrorBuilder;
7272
}
7373

74-
return $ruleErrorBuilder->tip('Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.');
74+
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
7575
};
7676

7777
return [

src/Rules/Comparison/ElseIfConstantConditionRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function processNode(
4646
return $ruleErrorBuilder;
4747
}
4848

49-
return $ruleErrorBuilder->tip('Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.');
49+
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
5050
};
5151

5252
$isLast = $node->cond->getAttribute(LastConditionVisitor::ATTRIBUTE_NAME);

src/Rules/Comparison/IfConstantConditionRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function processNode(
4444
return $ruleErrorBuilder;
4545
}
4646

47-
return $ruleErrorBuilder->tip('Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.');
47+
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
4848
};
4949

5050
return [

src/Rules/Comparison/ImpossibleCheckTypeFunctionCallRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function processNode(Node $node, Scope $scope): array
5555
return $ruleErrorBuilder;
5656
}
5757

58-
return $ruleErrorBuilder->tip('Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.');
58+
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
5959
};
6060

6161
if (!$isAlways) {

src/Rules/Comparison/ImpossibleCheckTypeMethodCallRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function processNode(Node $node, Scope $scope): array
5353
return $ruleErrorBuilder;
5454
}
5555

56-
return $ruleErrorBuilder->tip('Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.');
56+
return $ruleErrorBuilder->treatPhpDocTypesAsCertainTip();
5757
};
5858

5959
if (!$isAlways) {

0 commit comments

Comments
 (0)