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

Breadcrumb

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

function PluginAnnotationContextDefinitionsRule::doProcessNode

Overrides DeprecatedAnnotationsRuleBase::doProcessNode

File

vendor/mglaman/phpstan-drupal/src/Rules/Deprecations/PluginAnnotationContextDefinitionsRule.php, line 19

Class

PluginAnnotationContextDefinitionsRule

Namespace

mglaman\PHPStanDrupal\Rules\Deprecations

Code

protected function doProcessNode(ClassReflection $reflection, Node\Stmt\Class_ $node, Scope $scope) : array {
    $annotation = $reflection->getResolvedPhpDoc();
    // Plugins should always be annotated, but maybe this class is missing its
    // annotation since it swaps an existing one.
    if ($annotation === null) {
        return [];
    }
    $hasMatch = preg_match('/context\\s?=\\s?{/', $annotation->getPhpDocString());
    if ($hasMatch === false) {
        throw new ShouldNotHappenException('Unexpected error when trying to run match on phpDoc string.');
    }
    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.',
        ];
    }
    return [];
}

API Navigation

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