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

Breadcrumb

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

class EntityFieldMethodsViaMagicReflectionExtension

Allows some common methods on fields.

Hierarchy

  • class \mglaman\PHPStanDrupal\Reflection\EntityFieldMethodsViaMagicReflectionExtension implements \PHPStan\Reflection\MethodsClassReflectionExtension

Expanded class hierarchy of EntityFieldMethodsViaMagicReflectionExtension

File

vendor/mglaman/phpstan-drupal/src/Reflection/EntityFieldMethodsViaMagicReflectionExtension.php, line 14

Namespace

mglaman\PHPStanDrupal\Reflection
View source
class EntityFieldMethodsViaMagicReflectionExtension implements MethodsClassReflectionExtension {
    public function hasMethod(ClassReflection $classReflection, string $methodName) : bool {
        if ($classReflection->hasNativeMethod($methodName) || array_key_exists($methodName, $classReflection->getMethodTags())) {
            // Let other parts of PHPStan handle this.
            return false;
        }
        $interfaceObject = new ObjectType('Drupal\\Core\\Field\\FieldItemListInterface');
        $objectType = new ObjectType($classReflection->getName());
        if (!$interfaceObject->isSuperTypeOf($objectType)
            ->yes()) {
            return false;
        }
        if ($methodName === 'referencedEntities') {
            return true;
        }
        return false;
    }
    public function getMethod(ClassReflection $classReflection, string $methodName) : MethodReflection {
        if ($methodName === 'referencedEntities') {
            $entityReferenceFieldItemListInterfaceType = new ObjectType('Drupal\\Core\\Field\\EntityReferenceFieldItemListInterface');
            $classReflection = $entityReferenceFieldItemListInterfaceType->getClassReflection();
            assert($classReflection !== null);
        }
        return new FieldItemListMethodReflection($classReflection, $methodName);
    }

}

Members

Title Sort descending Modifiers Object type Summary
EntityFieldMethodsViaMagicReflectionExtension::getMethod public function
EntityFieldMethodsViaMagicReflectionExtension::hasMethod public function

API Navigation

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