Skip to content

Commit c476a86

Browse files
committed
Clean up old identifiers and metadata
1 parent 9a3ed85 commit c476a86

19 files changed

+13
-140
lines changed

src/Rules/Comparison/ElseIfConstantConditionRule.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,7 @@ public function processNode(
5454
$errorBuilder = $addTip(RuleErrorBuilder::message(sprintf(
5555
'Elseif condition is always %s.',
5656
$exprType->getValue() ? 'true' : 'false',
57-
)))->line($node->cond->getLine())
58-
->identifier('deadCode.elseifConstantCondition')
59-
->metadata([
60-
'depth' => $node->getAttribute('statementDepth'),
61-
'order' => $node->getAttribute('statementOrder'),
62-
'value' => $exprType->getValue(),
63-
]);
57+
)))->line($node->cond->getLine());
6458

6559
if ($exprType->getValue() && $isLast === false && !$this->reportAlwaysTrueInLastCondition) {
6660
$errorBuilder->tip('Remove remaining cases below this one and this error will disappear too.');

src/Rules/Comparison/IfConstantConditionRule.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,7 @@ public function processNode(
5151
$addTip(RuleErrorBuilder::message(sprintf(
5252
'If condition is always %s.',
5353
$exprType->getValue() ? 'true' : 'false',
54-
)))->line($node->cond->getLine())
55-
->identifier('deadCode.ifConstantCondition')
56-
->metadata([
57-
'depth' => $node->getAttribute('statementDepth'),
58-
'order' => $node->getAttribute('statementOrder'),
59-
'value' => $exprType->getValue(),
60-
])
61-
->build(),
54+
)))->line($node->cond->getLine())->build(),
6255
];
6356
}
6457

src/Rules/Comparison/TernaryOperatorConstantConditionRule.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,7 @@ public function processNode(
5050
$addTip(RuleErrorBuilder::message(sprintf(
5151
'Ternary operator condition is always %s.',
5252
$exprType->getValue() ? 'true' : 'false',
53-
)))
54-
->identifier('deadCode.ternaryConstantCondition')
55-
->metadata([
56-
'statementDepth' => $node->getAttribute('statementDepth'),
57-
'statementOrder' => $node->getAttribute('statementOrder'),
58-
'depth' => $node->getAttribute('expressionDepth'),
59-
'order' => $node->getAttribute('expressionOrder'),
60-
'value' => $exprType->getValue(),
61-
])
62-
->build(),
53+
)))->build(),
6354
];
6455
}
6556

src/Rules/Comparison/UnreachableIfBranchesRule.php

+2-16
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,7 @@ public function processNode(Node $node, Scope $scope): array
5353

5454
foreach ($node->elseifs as $elseif) {
5555
if ($nextBranchIsDead) {
56-
$errors[] = $addTip(RuleErrorBuilder::message('Elseif branch is unreachable because previous condition is always true.')->line($elseif->getLine()))
57-
->identifier('deadCode.unreachableElseif')
58-
->metadata([
59-
'ifDepth' => $node->getAttribute('statementDepth'),
60-
'ifOrder' => $node->getAttribute('statementOrder'),
61-
'depth' => $elseif->getAttribute('statementDepth'),
62-
'order' => $elseif->getAttribute('statementOrder'),
63-
])
64-
->build();
56+
$errors[] = $addTip(RuleErrorBuilder::message('Elseif branch is unreachable because previous condition is always true.')->line($elseif->getLine()))->build();
6557
continue;
6658
}
6759

@@ -72,13 +64,7 @@ public function processNode(Node $node, Scope $scope): array
7264
}
7365

7466
if ($node->else !== null && $nextBranchIsDead) {
75-
$errors[] = $addTip(RuleErrorBuilder::message('Else branch is unreachable because previous condition is always true.'))->line($node->else->getLine())
76-
->identifier('deadCode.unreachableElse')
77-
->metadata([
78-
'ifDepth' => $node->getAttribute('statementDepth'),
79-
'ifOrder' => $node->getAttribute('statementOrder'),
80-
])
81-
->build();
67+
$errors[] = $addTip(RuleErrorBuilder::message('Else branch is unreachable because previous condition is always true.'))->line($node->else->getLine())->build();
8268
}
8369

8470
return $errors;

src/Rules/Comparison/UnreachableTernaryElseBranchRule.php

-7
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ public function processNode(Node $node, Scope $scope): array
5555
return [
5656
$addTip(RuleErrorBuilder::message('Else branch is unreachable because ternary operator condition is always true.'))
5757
->line($node->else->getLine())
58-
->identifier('deadCode.unreachableTernaryElse')
59-
->metadata([
60-
'statementDepth' => $node->getAttribute('statementDepth'),
61-
'statementOrder' => $node->getAttribute('statementOrder'),
62-
'depth' => $node->getAttribute('expressionDepth'),
63-
'order' => $node->getAttribute('expressionOrder'),
64-
])
6558
->build(),
6659
];
6760
}

src/Rules/DeadCode/NoopRule.php

-5
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ public function processNode(Node $node, Scope $scope): array
5656
'Expression "%s" on a separate line does not do anything.',
5757
$this->exprPrinter->printExpr($originalExpr),
5858
))->line($expr->getLine())
59-
->identifier('deadCode.noopExpression')
60-
->metadata([
61-
'depth' => $node->getAttribute('statementDepth'),
62-
'order' => $node->getAttribute('statementOrder'),
63-
])
6459
->build(),
6560
];
6661
}

src/Rules/DeadCode/UnreachableStatementRule.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,7 @@ public function getNodeType(): string
2222
public function processNode(Node $node, Scope $scope): array
2323
{
2424
return [
25-
RuleErrorBuilder::message('Unreachable statement - code above always terminates.')
26-
->identifier('deadCode.unreachableStatement')
27-
->metadata([
28-
'depth' => $node->getAttribute('statementDepth'),
29-
'order' => $node->getAttribute('statementOrder'),
30-
])
31-
->build(),
25+
RuleErrorBuilder::message('Unreachable statement - code above always terminates.')->build(),
3226
];
3327
}
3428

src/Rules/DeadCode/UnusedPrivateConstantRule.php

-7
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,6 @@ public function processNode(Node $node, Scope $scope): array
8888
foreach ($constants as $constantName => $constantNode) {
8989
$errors[] = RuleErrorBuilder::message(sprintf('Constant %s::%s is unused.', $classReflection->getDisplayName(), $constantName))
9090
->line($constantNode->getLine())
91-
->identifier('deadCode.unusedClassConstant')
92-
->metadata([
93-
'classOrder' => $node->getClass()->getAttribute('statementOrder'),
94-
'classDepth' => $node->getClass()->getAttribute('statementDepth'),
95-
'classStartLine' => $node->getClass()->getStartLine(),
96-
'constantName' => $constantName,
97-
])
9891
->tip(sprintf('See: %s', 'https://phpstan.org/developing-extensions/always-used-class-constants'))
9992
->build();
10093
}

src/Rules/DeadCode/UnusedPrivateMethodRule.php

-7
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,6 @@ public function processNode(Node $node, Scope $scope): array
154154
}
155155
$errors[] = RuleErrorBuilder::message(sprintf('%s %s::%s() is unused.', $methodType, $classReflection->getDisplayName(), $methodName))
156156
->line($method->getNode()->getLine())
157-
->identifier('deadCode.unusedMethod')
158-
->metadata([
159-
'classOrder' => $node->getClass()->getAttribute('statementOrder'),
160-
'classDepth' => $node->getClass()->getAttribute('statementDepth'),
161-
'classStartLine' => $node->getClass()->getStartLine(),
162-
'methodName' => $methodName,
163-
])
164157
->build();
165158
}
166159

src/Rules/DeadCode/UnusedPrivatePropertyRule.php

-7
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,6 @@ public function processNode(Node $node, Scope $scope): array
175175
if (!$data['written']) {
176176
$errors[] = RuleErrorBuilder::message(sprintf('%s is unused.', $propertyName))
177177
->line($propertyNode->getStartLine())
178-
->identifier('deadCode.unusedProperty')
179-
->metadata([
180-
'classOrder' => $node->getClass()->getAttribute('statementOrder'),
181-
'classDepth' => $node->getClass()->getAttribute('statementDepth'),
182-
'classStartLine' => $node->getClass()->getStartLine(),
183-
'propertyName' => $name,
184-
])
185178
->tip($tip)
186179
->build();
187180
} else {

src/Rules/Exceptions/MissingCheckedExceptionInFunctionThrowsRule.php

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public function processNode(Node $node, Scope $scope): array
4242
$className,
4343
))
4444
->line($throwPointNode->getLine())
45-
->identifier('exceptions.missingThrowsTag')
4645
->build();
4746
}
4847

src/Rules/Exceptions/MissingCheckedExceptionInMethodThrowsRule.php

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public function processNode(Node $node, Scope $scope): array
4343
$className,
4444
))
4545
->line($throwPointNode->getLine())
46-
->identifier('exceptions.missingThrowsTag')
4746
->build();
4847
}
4948

src/Rules/Exceptions/TooWideFunctionThrowTypeRule.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,7 @@ public function processNode(Node $node, Scope $scope): array
4545
'Function %s() has %s in PHPDoc @throws tag but it\'s not thrown.',
4646
$functionReflection->getName(),
4747
$throwClass,
48-
))
49-
->identifier('exceptions.tooWideThrowType')
50-
->metadata([
51-
'exceptionName' => $throwClass,
52-
'statementDepth' => $node->getAttribute('statementDepth'),
53-
'statementOrder' => $node->getAttribute('statementOrder'),
54-
])
55-
->build();
48+
))->build();
5649
}
5750

5851
return $errors;

src/Rules/Exceptions/TooWideMethodThrowTypeRule.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,7 @@ public function processNode(Node $node, Scope $scope): array
6565
$methodReflection->getDeclaringClass()->getDisplayName(),
6666
$methodReflection->getName(),
6767
$throwClass,
68-
))
69-
->identifier('exceptions.tooWideThrowType')
70-
->metadata([
71-
'exceptionName' => $throwClass,
72-
'statementDepth' => $node->getAttribute('statementDepth'),
73-
'statementOrder' => $node->getAttribute('statementOrder'),
74-
])
75-
->build();
68+
))->build();
7669
}
7770

7871
return $errors;

src/Rules/PhpDoc/IncompatiblePhpDocTypeRule.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function processNode(Node $node, Scope $scope): array
7878
'PHPDoc tag %s references unknown parameter: $%s',
7979
$tagName,
8080
$parameterName,
81-
))->identifier('phpDoc.unknownParameter')->metadata(['parameterName' => $parameterName])->build();
81+
))->build();
8282

8383
} elseif (
8484
$this->unresolvableTypeHelper->containsUnresolvableType($phpDocParamType)

src/Rules/Playground/FunctionNeverRule.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function processNode(Node $node, Scope $scope): array
5050
'Function %s() always %s, it should have return type "never".',
5151
$function->getName(),
5252
count($helperResult) === 0 ? 'throws an exception' : 'terminates script execution',
53-
))->identifier('phpstanPlayground.never')->build(),
53+
))->build(),
5454
];
5555
}
5656

src/Rules/Playground/MethodNeverRule.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function processNode(Node $node, Scope $scope): array
5151
$method->getDeclaringClass()->getDisplayName(),
5252
$method->getName(),
5353
count($helperResult) === 0 ? 'throws an exception' : 'terminates script execution',
54-
))->identifier('phpstanPlayground.never')->build(),
54+
))->build(),
5555
];
5656
}
5757

src/Rules/UnusedFunctionParametersCheck.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function getUnusedParameters(
4747
foreach (array_keys($unusedParameters) as $name) {
4848
$errors[] = RuleErrorBuilder::message(
4949
sprintf($unusedParameterMessage, $name),
50-
)->identifier($identifier)->metadata($additionalMetadata + ['variableName' => $name])->build();
50+
)->build();
5151
}
5252

5353
return $errors;

src/Rules/Variables/DefinedVariableRule.php

+1-37
Original file line numberDiff line numberDiff line change
@@ -52,54 +52,18 @@ public function processNode(Node $node, Scope $scope): array
5252
if ($scope->hasVariableType($node->name)->no()) {
5353
return [
5454
RuleErrorBuilder::message(sprintf('Undefined variable: $%s', $node->name))
55-
->identifier('variable.undefined')
56-
->metadata([
57-
'variableName' => $node->name,
58-
'statementDepth' => $node->getAttribute('statementDepth'),
59-
'statementOrder' => $node->getAttribute('statementOrder'),
60-
'depth' => $node->getAttribute('expressionDepth'),
61-
'order' => $node->getAttribute('expressionOrder'),
62-
'variables' => $scope->getDefinedVariables(),
63-
'parentVariables' => $this->getParentVariables($scope),
64-
])
6555
->build(),
6656
];
6757
} elseif (
6858
$this->checkMaybeUndefinedVariables
6959
&& !$scope->hasVariableType($node->name)->yes()
7060
) {
7161
return [
72-
RuleErrorBuilder::message(sprintf('Variable $%s might not be defined.', $node->name))
73-
->identifier('variable.maybeUndefined')
74-
->metadata([
75-
'variableName' => $node->name,
76-
'statementDepth' => $node->getAttribute('statementDepth'),
77-
'statementOrder' => $node->getAttribute('statementOrder'),
78-
'depth' => $node->getAttribute('expressionDepth'),
79-
'order' => $node->getAttribute('expressionOrder'),
80-
'variables' => $scope->getDefinedVariables(),
81-
'parentVariables' => $this->getParentVariables($scope),
82-
])
83-
->build(),
62+
RuleErrorBuilder::message(sprintf('Variable $%s might not be defined.', $node->name))->build(),
8463
];
8564
}
8665

8766
return [];
8867
}
8968

90-
/**
91-
* @return array<int, array<int, string>>
92-
*/
93-
private function getParentVariables(Scope $scope): array
94-
{
95-
$variables = [];
96-
$parent = $scope->getParentScope();
97-
while ($parent !== null) {
98-
$variables[] = $parent->getDefinedVariables();
99-
$parent = $parent->getParentScope();
100-
}
101-
102-
return $variables;
103-
}
104-
10569
}

0 commit comments

Comments
 (0)