Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/Rules/Classes/ClassExtendsInternalClassRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ private function buildError(?string $currentClassName, string $extendedClassName
'%s extends @internal class %s.',
$currentClassName !== null ? sprintf('Class %s', $currentClassName) : 'Anonymous class',
$extendedClassName
));
))
->identifier('class.extendsInternalClass');
}
}
14 changes: 11 additions & 3 deletions src/Rules/Classes/PluginManagerInspectionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleError;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\ObjectType;
use function sprintf;

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

if (!$hasAlterInfoSet) {
$errors[] = 'Plugin definitions cannot be altered.';
$errors[] = RuleErrorBuilder::message('Plugin definitions cannot be altered.')
->identifier('plugin.manager.alterInfoMissing')
->build();
}

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

if ($constructor->getDeclaringClass()->getName() !== $fqn) {
$errors[] = sprintf('%s must override __construct if using YAML plugins.', $fqn);
$errors[] = RuleErrorBuilder::message(sprintf('%s must override __construct if using YAML plugins.', $fqn))
->identifier('plugin.manager.yamlPluginConstructor')
->build();
} else {
foreach ($class->stmts as $stmt) {
if ($stmt instanceof Node\Stmt\ClassMethod && $stmt->name->toString() === '__construct') {
Expand All @@ -130,7 +136,9 @@ private function inspectYamlPluginManager(Node\Stmt\Class_ $class): array
&& ((string)$constructorStmt->class === 'parent')
&& $constructorStmt->name instanceof Node\Identifier
&& $constructorStmt->name->name === '__construct') {
$errors[] = sprintf('YAML plugin managers should not invoke its parent constructor.');
$errors[] = RuleErrorBuilder::message('YAML plugin managers should not invoke its parent constructor.')
->identifier('plugin.manager.yamlPluginConstructor')
->build();
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/Rules/Deprecations/AccessDeprecatedConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use function array_merge;
use function explode;
use function sprintf;
Expand Down Expand Up @@ -124,7 +125,9 @@ public function processNode(Node $node, Scope $scope): array
$constantName = $this->reflectionProvider->resolveConstantName($node->name, $scope);
if (isset($deprecatedConstants[$constantName])) {
return [
sprintf('Call to deprecated constant %s: %s', $constantName, $deprecatedConstants[$constantName])
RuleErrorBuilder::message(sprintf('Call to deprecated constant %s: %s', $constantName, $deprecatedConstants[$constantName]))
->identifier('constant.deprecated')
->build()
];
}
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function processNode(Node $node, Scope $scope): array
return [
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')
->line($node->getStartLine())
->identifier('drupal.deprecated.pluginConfigurationContextKey')
->build()
];
}
Expand Down
5 changes: 4 additions & 1 deletion src/Rules/Deprecations/ConfigEntityConfigExportRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PHPStan\PhpDoc\ResolvedPhpDocBlock;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\ShouldNotHappenException;
use function preg_match;

Expand All @@ -32,7 +33,9 @@ protected function doProcessNode(ClassReflection $reflection, Node\Stmt\Class_ $
}
if ($hasMatch === 0) {
return [
'Configuration entity must define a `config_export` key. See https://www.drupal.org/node/2481909',
RuleErrorBuilder::message('Configuration entity must define a `config_export` key. See https://www.drupal.org/node/2481909')
->identifier('drupal.deprecated.configEntityConfigExportKey')
->build(),
];
}
return [];
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Deprecations/DeprecatedHookImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private function buildError(string $function_name, string $hook_name, ?string $d
return [
RuleErrorBuilder::message(
"Function $function_name implements $hook_name which is deprecated$deprecated_description",
)->build()
)->identifier('drupal.deprecated.hook')->build()
];
}
}
7 changes: 6 additions & 1 deletion src/Rules/Deprecations/GetDeprecatedServiceRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;

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

$service = $this->serviceMap->getService($serviceName->value);
if (($service instanceof DrupalServiceDefinition) && $service->isDeprecated()) {
return [$service->getDeprecatedDescription()];
return [
RuleErrorBuilder::message($service->getDeprecatedDescription())
->identifier('drupal.deprecated.service')
->build()
];
}

return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\ShouldNotHappenException;
use function preg_match;

Expand All @@ -30,7 +31,9 @@ protected function doProcessNode(ClassReflection $reflection, Node\Stmt\Class_ $
}
if ($hasMatch === 1) {
return [
'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.',
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.')
->identifier('drupal.deprecated.pluginAnnotationContextKey')
->build(),
];
}
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;

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

$service = $this->serviceMap->getService($serviceName->value);
if (($service instanceof DrupalServiceDefinition) && $service->isDeprecated()) {
return [$service->getDeprecatedDescription()];
return [
RuleErrorBuilder::message($service->getDeprecatedDescription())
->identifier('drupal.deprecated.service')
->build()
];
}

return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,20 @@ public function processNode(Node $node, Scope $scope): array
return [
RuleErrorBuilder::message(
sprintf('The core dependency symfony-cmf/routing is deprecated and %s::%s is not supported.', $className, $constantName)
)->tip('Change record: https://www.drupal.org/node/3151009')->build(),
)
->tip('Change record: https://www.drupal.org/node/3151009')
->identifier('drupal.deprecated.dependency')
->build(),
];
}

return [
RuleErrorBuilder::message(
sprintf('%s::%s is deprecated and removed in Drupal 10. Use \Drupal\Core\Routing\RouteObjectInterface::%2$s instead.', $className, $constantName)
)->tip('Change record: https://www.drupal.org/node/3151009')->build(),
)
->tip('Change record: https://www.drupal.org/node/3151009')
->identifier('drupal.deprecated.class')
->build(),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function processNode(Node $node, Scope $scope): array
foreach ($parameter->getType()->getReferencedClasses() as $referencedClass) {
$referencedClassType = new ObjectType($referencedClass);
if ($cmfRouteObjectInterfaceType->equals($referencedClassType)) {
// @todo identifier
$errors[] = RuleErrorBuilder::message(
sprintf(
$errorMessage,
Expand All @@ -68,6 +69,7 @@ public function processNode(Node $node, Scope $scope): array
)
)->tip('Change record: https://www.drupal.org/node/3151009')->build();
} elseif ($cmfRouteProviderInterfaceType->equals($referencedClassType)) {
// @todo identifier
$errors[] = RuleErrorBuilder::message(
sprintf(
$errorMessage,
Expand All @@ -78,6 +80,7 @@ public function processNode(Node $node, Scope $scope): array
)
)->tip('Change record: https://www.drupal.org/node/3151009')->build();
} elseif ($cmfLazyRouteCollectionType->equals($referencedClassType)) {
// @todo identifier
$errors[] = RuleErrorBuilder::message(
sprintf(
$errorMessage,
Expand All @@ -96,6 +99,7 @@ public function processNode(Node $node, Scope $scope): array
foreach ($returnClasses as $returnClass) {
$returnType = new ObjectType($returnClass);
if ($cmfRouteObjectInterfaceType->equals($returnType)) {
// @todo identifier
$errors[] = RuleErrorBuilder::message(
sprintf(
$errorMessage,
Expand All @@ -106,6 +110,7 @@ public function processNode(Node $node, Scope $scope): array
)
)->tip('Change record: https://www.drupal.org/node/3151009')->build();
} elseif ($cmfRouteProviderInterfaceType->equals($returnType)) {
// @todo identifier
$errors[] = RuleErrorBuilder::message(
sprintf(
$errorMessage,
Expand All @@ -116,6 +121,7 @@ public function processNode(Node $node, Scope $scope): array
)
)->tip('Change record: https://www.drupal.org/node/3151009')->build();
} elseif ($cmfLazyRouteCollectionType->equals($returnType)) {
// @todo identifier
$errors[] = RuleErrorBuilder::message(
sprintf(
$errorMessage,
Expand Down
1 change: 1 addition & 0 deletions src/Rules/Drupal/AccessResultConditionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function processNode(Node $node, Scope $scope): array
$rightType = $this->treatPhpDocTypesAsCertain ? $scope->getType($condition->right) : $scope->getNativeType($condition->right);

return [
// @todo identifier
RuleErrorBuilder::message(sprintf(
'Strict comparison using %s between %s and %s will always evaluate to %s.',
$condition->getOperatorSigil(),
Expand Down
1 change: 1 addition & 0 deletions src/Rules/Drupal/Coder/DiscouragedFunctionsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function processNode(Node $node, Scope $scope): array
];

if (in_array($name, $discouragedFunctions, true)) {
// @todo identifier
return [sprintf('Calls to function %s should not exist.', $name)];
}
return [];
Expand Down
2 changes: 2 additions & 0 deletions src/Rules/Drupal/DependencySerializationTraitPropertyRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function processNode(Node $node, Scope $scope): array

$errors = [];
if ($node->isPrivate()) {
// @todo identifier
$errors[] = RuleErrorBuilder::message(
sprintf(
'%s does not support private properties.',
Expand All @@ -38,6 +39,7 @@ public function processNode(Node $node, Scope $scope): array
)->tip('See https://www.drupal.org/node/3110266')->build();
}
if ($node->isReadOnly()) {
// @todo identifier
$errors[] = RuleErrorBuilder::message(
sprintf(
'Read-only properties are incompatible with %s.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function processNode(Node $node, Scope $scope): array
}

return [
// @todo identifier
RuleErrorBuilder::message(
'Relying on entity queries to check access by default is deprecated in drupal:9.2.0 and an error will be thrown from drupal:10.0.0. Call \Drupal\Core\Entity\Query\QueryInterface::accessCheck() with TRUE or FALSE to specify whether access should be checked.'
)->tip('See https://www.drupal.org/node/3201242')->build(),
Expand Down
1 change: 1 addition & 0 deletions src/Rules/Drupal/GlobalDrupalDependencyInjectionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

// @todo identifier
return [
'\Drupal calls should be avoided in classes, use dependency injection instead'
];
Expand Down
2 changes: 2 additions & 0 deletions src/Rules/Drupal/LoadIncludes.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function processNode(Node $node, Scope $scope): array
$module = $this->extensionMap->getModule($moduleName);
if ($module === null) {
return [
// @todo identifier
RuleErrorBuilder::message(sprintf(
'File %s could not be loaded from %s::loadInclude because %s module is not found.',
$filename,
Expand Down Expand Up @@ -80,6 +81,7 @@ public function processNode(Node $node, Scope $scope): array
];
} catch (Throwable $e) {
return [
// @todo identifier
RuleErrorBuilder::message(sprintf(
'A file could not be loaded from %s::loadInclude',
ModuleHandlerInterface::class
Expand Down
3 changes: 3 additions & 0 deletions src/Rules/Drupal/ModuleLoadInclude.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function processNode(Node $node, Scope $scope): array
$module = $this->extensionMap->getModule($moduleName);
if ($module === null) {
return [
// @todo identifier
RuleErrorBuilder::message(sprintf(
'File %s could not be loaded from module_load_include because %s module is not found.',
$filename,
Expand All @@ -62,6 +63,7 @@ public function processNode(Node $node, Scope $scope): array
return [];
}
return [
// @todo identifier
RuleErrorBuilder::message(sprintf(
'File %s could not be loaded from module_load_include.',
$module->getPath() . '/' . $filename
Expand All @@ -71,6 +73,7 @@ public function processNode(Node $node, Scope $scope): array
];
} catch (Throwable $e) {
return [
// @todo identifier
RuleErrorBuilder::message('A file could not be loaded from module_load_include')
->line($node->getStartLine())
->build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ public function processNode(Node $node, Scope $scope): array

$errors = [];
if (!$hasCacheBackendSet) {
// @todo identifier
$errors[] = 'Missing cache backend declaration for performance.';
}
foreach ($misnamedCacheTagWarnings as $cacheTagWarning) {
// @todo identifier
$errors[] = sprintf('%s cache tag might be unclear and does not contain the cache key in it.', $cacheTagWarning);
}

Expand Down
Loading