Skip to content

Commit 3cfe56b

Browse files
committed
Add rule identifiers
1 parent 2bc25a5 commit 3cfe56b

13 files changed

+41
-7
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function processNode(Node $node, Scope $scope): array
6767
}
6868

6969
if (!$hasAlterInfoSet) {
70+
// @todo identifier
7071
$errors[] = 'Plugin definitions cannot be altered.';
7172
}
7273

@@ -117,6 +118,7 @@ private function inspectYamlPluginManager(Node\Stmt\Class_ $class): array
117118
$constructor = $reflection->getConstructor();
118119

119120
if ($constructor->getDeclaringClass()->getName() !== $fqn) {
121+
// @todo identifier
120122
$errors[] = sprintf('%s must override __construct if using YAML plugins.', $fqn);
121123
} else {
122124
foreach ($class->stmts as $stmt) {
@@ -130,6 +132,7 @@ private function inspectYamlPluginManager(Node\Stmt\Class_ $class): array
130132
&& ((string)$constructorStmt->class === 'parent')
131133
&& $constructorStmt->name instanceof Node\Identifier
132134
&& $constructorStmt->name->name === '__construct') {
135+
// @todo identifier
133136
$errors[] = sprintf('YAML plugin managers should not invoke its parent constructor.');
134137
}
135138
}

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ public function processNode(Node $node, Scope $scope): array
5757

5858
$coreRouteObjectInterfaceType = new ObjectType(RouteObjectInterface::class);
5959
if (!$coreRouteObjectInterfaceType->hasConstant($constantName)->yes()) {
60+
// @todo identifier
6061
return [
6162
RuleErrorBuilder::message(
6263
sprintf('The core dependency symfony-cmf/routing is deprecated and %s::%s is not supported.', $className, $constantName)
6364
)->tip('Change record: https://www.drupal.org/node/3151009')->build(),
6465
];
6566
}
6667

68+
// @todo identifier
6769
return [
6870
RuleErrorBuilder::message(
6971
sprintf('%s::%s is deprecated and removed in Drupal 10. Use \Drupal\Core\Routing\RouteObjectInterface::%2$s instead.', $className, $constantName)

0 commit comments

Comments
 (0)