Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. UsageOfDeprecatedCastRule.php

function UsageOfDeprecatedCastRule::processNode

File

vendor/phpstan/phpstan-deprecation-rules/src/Rules/Deprecations/UsageOfDeprecatedCastRule.php, line 31

Class

UsageOfDeprecatedCastRule
@implements Rule<Cast>

Namespace

PHPStan\Rules\Deprecations

Code

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(),
    ];
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal