function UsageOfDeprecatedCastRule::processNode
File
-
vendor/
phpstan/ phpstan-deprecation-rules/ src/ Rules/ Deprecations/ UsageOfDeprecatedCastRule.php, line 31
Class
- UsageOfDeprecatedCastRule
- @implements Rule<Cast>
Namespace
PHPStan\Rules\DeprecationsCode
public function processNode(Node $node, Scope $scope) : array {
if ($this->deprecatedScopeHelper
->isScopeDeprecated($scope)) {
return [];
}
$castedType = $scope->getType($node->expr);
if (!$castedType->hasMethod('__toString')
->yes()) {
return [];
}
$method = $castedType->getMethod('__toString', $scope);
if (!$method->isDeprecated()
->yes()) {
return [];
}
$description = $method->getDeprecatedDescription();
if ($description === null) {
return [
RuleErrorBuilder::message(sprintf('Casting class %s to string is deprecated.', $method->getDeclaringClass()
->getName()))
->identifier('class.toStringDeprecated')
->build(),
];
}
return [
RuleErrorBuilder::message(sprintf("Casting class %s to string is deprecated.:\n%s", $method->getDeclaringClass()
->getName(), $description))
->identifier('class.toStringDeprecated')
->build(),
];
}