Skip to content

Commit 53772ee

Browse files
committed
Add rule identifiers
1 parent 2bc25a5 commit 53772ee

24 files changed

+81
-12
lines changed

src/Rules/Classes/ClassExtendsInternalClassRule.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ private function buildError(?string $currentClassName, string $extendedClassName
7676
'%s extends @internal class %s.',
7777
$currentClassName !== null ? sprintf('Class %s', $currentClassName) : 'Anonymous class',
7878
$extendedClassName
79-
));
79+
))
80+
->identifier('class.extendsInternalClass');
8081
}
8182
}

src/Rules/Classes/PluginManagerInspectionRule.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\ReflectionProvider;
88
use PHPStan\Rules\Rule;
9+
use PHPStan\Rules\RuleError;
10+
use PHPStan\Rules\RuleErrorBuilder;
911
use PHPStan\Type\ObjectType;
1012
use function sprintf;
1113

@@ -67,7 +69,9 @@ public function processNode(Node $node, Scope $scope): array
6769
}
6870

6971
if (!$hasAlterInfoSet) {
70-
$errors[] = 'Plugin definitions cannot be altered.';
72+
$errors[] = RuleErrorBuilder::message('Plugin definitions cannot be altered.')
73+
->identifier('plugin.manager.alterInfoMissing')
74+
->build();
7175
}
7276

7377
return $errors;
@@ -117,7 +121,9 @@ private function inspectYamlPluginManager(Node\Stmt\Class_ $class): array
117121
$constructor = $reflection->getConstructor();
118122

119123
if ($constructor->getDeclaringClass()->getName() !== $fqn) {
120-
$errors[] = sprintf('%s must override __construct if using YAML plugins.', $fqn);
124+
$errors[] = RuleErrorBuilder::message(sprintf('%s must override __construct if using YAML plugins.', $fqn))
125+
->identifier('plugin.manager.yamlPluginConstructor')
126+
->build();
121127
} else {
122128
foreach ($class->stmts as $stmt) {
123129
if ($stmt instanceof Node\Stmt\ClassMethod && $stmt->name->toString() === '__construct') {
@@ -130,7 +136,9 @@ private function inspectYamlPluginManager(Node\Stmt\Class_ $class): array
130136
&& ((string)$constructorStmt->class === 'parent')
131137
&& $constructorStmt->name instanceof Node\Identifier
132138
&& $constructorStmt->name->name === '__construct') {
133-
$errors[] = sprintf('YAML plugin managers should not invoke its parent constructor.');
139+
$errors[] = RuleErrorBuilder::message('YAML plugin managers should not invoke its parent constructor.')
140+
->identifier('plugin.manager.yamlPluginConstructor')
141+
->build();
134142
}
135143
}
136144
}

src/Rules/Deprecations/AccessDeprecatedConstant.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPStan\Analyser\Scope;
99
use PHPStan\Reflection\ReflectionProvider;
1010
use PHPStan\Rules\Rule;
11+
use PHPStan\Rules\RuleErrorBuilder;
1112
use function array_merge;
1213
use function explode;
1314
use function sprintf;
@@ -124,7 +125,9 @@ public function processNode(Node $node, Scope $scope): array
124125
$constantName = $this->reflectionProvider->resolveConstantName($node->name, $scope);
125126
if (isset($deprecatedConstants[$constantName])) {
126127
return [
127-
sprintf('Call to deprecated constant %s: %s', $constantName, $deprecatedConstants[$constantName])
128+
RuleErrorBuilder::message(sprintf('Call to deprecated constant %s: %s', $constantName, $deprecatedConstants[$constantName]))
129+
->identifier('constant.deprecated')
130+
->build()
128131
];
129132
}
130133
return [];

src/Rules/Deprecations/ConditionManagerCreateInstanceContextConfigurationRule.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function processNode(Node $node, Scope $scope): array
5151
return [
5252
RuleErrorBuilder::message('Passing context values to plugins via configuration is deprecated in drupal:9.1.0 and will be removed before drupal:10.0.0. Instead, call ::setContextValue() on the plugin itself. See https://www.drupal.org/node/3120980')
5353
->line($node->getStartLine())
54+
->identifier('drupal.deprecated.pluginConfigurationContextKey')
5455
->build()
5556
];
5657
}

src/Rules/Deprecations/ConfigEntityConfigExportRule.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPStan\PhpDoc\ResolvedPhpDocBlock;
88
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
99
use PHPStan\Reflection\ClassReflection;
10+
use PHPStan\Rules\RuleErrorBuilder;
1011
use PHPStan\ShouldNotHappenException;
1112
use function preg_match;
1213

@@ -32,7 +33,9 @@ protected function doProcessNode(ClassReflection $reflection, Node\Stmt\Class_ $
3233
}
3334
if ($hasMatch === 0) {
3435
return [
35-
'Configuration entity must define a `config_export` key. See https://www.drupal.org/node/2481909',
36+
RuleErrorBuilder::message('Configuration entity must define a `config_export` key. See https://www.drupal.org/node/2481909')
37+
->identifier('drupal.deprecated.configEntityConfigExportKey')
38+
->build(),
3639
];
3740
}
3841
return [];

src/Rules/Deprecations/DeprecatedHookImplementation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private function buildError(string $function_name, string $hook_name, ?string $d
9898
return [
9999
RuleErrorBuilder::message(
100100
"Function $function_name implements $hook_name which is deprecated$deprecated_description",
101-
)->build()
101+
)->identifier('drupal.deprecated.hook')->build()
102102
];
103103
}
104104
}

src/Rules/Deprecations/GetDeprecatedServiceRule.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\Node;
88
use PHPStan\Analyser\Scope;
99
use PHPStan\Rules\Rule;
10+
use PHPStan\Rules\RuleErrorBuilder;
1011

1112
/**
1213
* @implements Rule<Node\Expr\MethodCall>
@@ -57,7 +58,11 @@ public function processNode(Node $node, Scope $scope): array
5758

5859
$service = $this->serviceMap->getService($serviceName->value);
5960
if (($service instanceof DrupalServiceDefinition) && $service->isDeprecated()) {
60-
return [$service->getDeprecatedDescription()];
61+
return [
62+
RuleErrorBuilder::message($service->getDeprecatedDescription())
63+
->identifier('drupal.deprecated.service')
64+
->build()
65+
];
6166
}
6267

6368
return [];

src/Rules/Deprecations/PluginAnnotationContextDefinitionsRule.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PhpParser\Node;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\ClassReflection;
8+
use PHPStan\Rules\RuleErrorBuilder;
89
use PHPStan\ShouldNotHappenException;
910
use function preg_match;
1011

@@ -30,7 +31,9 @@ protected function doProcessNode(ClassReflection $reflection, Node\Stmt\Class_ $
3031
}
3132
if ($hasMatch === 1) {
3233
return [
33-
'Providing context definitions via the "context" key is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use the "context_definitions" key instead.',
34+
RuleErrorBuilder::message('Providing context definitions via the "context" key is deprecated in Drupal 8.7.x and will be removed before Drupal 9.0.0. Use the "context_definitions" key instead.')
35+
->identifier('drupal.deprecated.pluginAnnotationContextKey')
36+
->build(),
3437
];
3538
}
3639
return [];

src/Rules/Deprecations/StaticServiceDeprecatedServiceRule.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\Node;
88
use PHPStan\Analyser\Scope;
99
use PHPStan\Rules\Rule;
10+
use PHPStan\Rules\RuleErrorBuilder;
1011

1112
/**
1213
* @implements Rule<Node\Expr\StaticCall>
@@ -66,7 +67,11 @@ public function processNode(Node $node, Scope $scope): array
6667

6768
$service = $this->serviceMap->getService($serviceName->value);
6869
if (($service instanceof DrupalServiceDefinition) && $service->isDeprecated()) {
69-
return [$service->getDeprecatedDescription()];
70+
return [
71+
RuleErrorBuilder::message($service->getDeprecatedDescription())
72+
->identifier('drupal.deprecated.service')
73+
->build()
74+
];
7075
}
7176

7277
return [];

src/Rules/Deprecations/SymfonyCmfRouteObjectInterfaceConstantsRule.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,20 @@ public function processNode(Node $node, Scope $scope): array
6060
return [
6161
RuleErrorBuilder::message(
6262
sprintf('The core dependency symfony-cmf/routing is deprecated and %s::%s is not supported.', $className, $constantName)
63-
)->tip('Change record: https://www.drupal.org/node/3151009')->build(),
63+
)
64+
->tip('Change record: https://www.drupal.org/node/3151009')
65+
->identifier('drupal.deprecated.dependency')
66+
->build(),
6467
];
6568
}
6669

6770
return [
6871
RuleErrorBuilder::message(
6972
sprintf('%s::%s is deprecated and removed in Drupal 10. Use \Drupal\Core\Routing\RouteObjectInterface::%2$s instead.', $className, $constantName)
70-
)->tip('Change record: https://www.drupal.org/node/3151009')->build(),
73+
)
74+
->tip('Change record: https://www.drupal.org/node/3151009')
75+
->identifier('drupal.deprecated.class')
76+
->build(),
7177
];
7278
}
7379
}

0 commit comments

Comments
 (0)