class StaticServiceDeprecatedServiceRule
@implements Rule<Node\Expr\StaticCall>
Hierarchy
- class \mglaman\PHPStanDrupal\Rules\Deprecations\StaticServiceDeprecatedServiceRule implements \PHPStan\Rules\Rule
Expanded class hierarchy of StaticServiceDeprecatedServiceRule
File
-
vendor/
mglaman/ phpstan-drupal/ src/ Rules/ Deprecations/ StaticServiceDeprecatedServiceRule.php, line 14
Namespace
mglaman\PHPStanDrupal\Rules\DeprecationsView source
final class StaticServiceDeprecatedServiceRule implements Rule {
/**
* @var ServiceMap
*/
private $serviceMap;
public function __construct(ServiceMap $serviceMap) {
$this->serviceMap = $serviceMap;
}
public function getNodeType() : string {
return Node\Expr\StaticCall::class;
}
public function processNode(Node $node, Scope $scope) : array {
if (!$node->name instanceof Node\Identifier) {
return [];
}
$method_name = $node->name
->toString();
if ($method_name !== 'service') {
return [];
}
$class = $node->class;
if ($class instanceof Node\Name) {
$calledOnType = $scope->resolveTypeByName($class);
}
else {
$calledOnType = $scope->getType($class);
}
$methodReflection = $scope->getMethodReflection($calledOnType, $node->name
->toString());
if ($methodReflection === null) {
return [];
}
$declaringClass = $methodReflection->getDeclaringClass();
if ($declaringClass->getName() !== 'Drupal') {
return [];
}
$serviceNameArg = $node->args[0];
assert($serviceNameArg instanceof Node\Arg);
$serviceName = $serviceNameArg->value;
// @todo check if var, otherwise throw.
// ACTUALLY what if it was a constant? can we use a resolver.
if (!$serviceName instanceof Node\Scalar\String_) {
return [];
}
$service = $this->serviceMap
->getService($serviceName->value);
if ($service instanceof DrupalServiceDefinition && $service->isDeprecated()) {
return [
$service->getDeprecatedDescription(),
];
}
return [];
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
StaticServiceDeprecatedServiceRule::$serviceMap | private | property | |
StaticServiceDeprecatedServiceRule::getNodeType | public | function | |
StaticServiceDeprecatedServiceRule::processNode | public | function | |
StaticServiceDeprecatedServiceRule::__construct | public | function |