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

Breadcrumb

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

class PluginAnnotationContextDefinitionsRule

Hierarchy

  • class \mglaman\PHPStanDrupal\Rules\Deprecations\DeprecatedAnnotationsRuleBase implements \PHPStan\Rules\Rule
    • class \mglaman\PHPStanDrupal\Rules\Deprecations\PluginAnnotationContextDefinitionsRule extends \mglaman\PHPStanDrupal\Rules\Deprecations\DeprecatedAnnotationsRuleBase

Expanded class hierarchy of PluginAnnotationContextDefinitionsRule

File

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

Namespace

mglaman\PHPStanDrupal\Rules\Deprecations
View source
final class PluginAnnotationContextDefinitionsRule extends DeprecatedAnnotationsRuleBase {
    protected function getExpectedInterface() : string {
        return 'Drupal\\Component\\Plugin\\ContextAwarePluginInterface';
    }
    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 [];
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
DeprecatedAnnotationsRuleBase::$reflectionProvider protected property
DeprecatedAnnotationsRuleBase::getNodeType public function
DeprecatedAnnotationsRuleBase::processNode public function
DeprecatedAnnotationsRuleBase::__construct public function
PluginAnnotationContextDefinitionsRule::doProcessNode protected function Overrides DeprecatedAnnotationsRuleBase::doProcessNode
PluginAnnotationContextDefinitionsRule::getExpectedInterface protected function Overrides DeprecatedAnnotationsRuleBase::getExpectedInterface
RSS feed
Powered by Drupal