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

Breadcrumb

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

function EntityFieldsViaMagicReflectionExtension::hasProperty

File

vendor/mglaman/phpstan-drupal/src/Reflection/EntityFieldsViaMagicReflectionExtension.php, line 23

Class

EntityFieldsViaMagicReflectionExtension
Allows field access via magic methods

Namespace

mglaman\PHPStanDrupal\Reflection

Code

public function hasProperty(ClassReflection $classReflection, string $propertyName) : bool {
    // @todo Have this run after PHPStan\Reflection\Annotations\AnnotationsPropertiesClassReflectionExtension
    // We should not have to check for the property tags if we could get this to run after PHPStan's
    // existing annotation property reflection.
    if ($classReflection->hasNativeProperty($propertyName) || array_key_exists($propertyName, $classReflection->getPropertyTags())) {
        // Let other parts of PHPStan handle this.
        return false;
    }
    foreach ($classReflection->getAncestors() as $ancestor) {
        if (array_key_exists($propertyName, $ancestor->getPropertyTags())) {
            return false;
        }
    }
    // We need to find a way to parse the entity annotation so that at the minimum the `entity_keys` are
    // supported. The real fix is Drupal developers _really_ need to start writing @property definitions in the
    // class doc if they don't get `get` methods.
    if ($classReflection->implementsInterface('Drupal\\Core\\Entity\\ContentEntityInterface')) {
        // @todo revisit if it's a good idea to be true.
        // Content entities have magical __get... so it is kind of true.
        return true;
    }
    if (self::classObjectIsSuperOfInterface($classReflection->getName(), self::getFieldItemListInterfaceObject())
        ->yes()) {
        return FieldItemListPropertyReflection::canHandleProperty($classReflection, $propertyName);
    }
    return false;
}

API Navigation

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