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

Breadcrumb

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

class EntityFieldReflection

Allows field access via magic methods

See \Drupal\Core\Entity\ContentEntityBase::__get and ::__set.

Hierarchy

  • class \mglaman\PHPStanDrupal\Reflection\EntityFieldReflection implements \PHPStan\Reflection\PropertyReflection

Expanded class hierarchy of EntityFieldReflection

File

vendor/mglaman/phpstan-drupal/src/Reflection/EntityFieldReflection.php, line 17

Namespace

mglaman\PHPStanDrupal\Reflection
View source
class EntityFieldReflection implements PropertyReflection {
    
    /** @var ClassReflection */
    private $declaringClass;
    
    /** @var string */
    private $propertyName;
    public function __construct(ClassReflection $declaringClass, string $propertyName) {
        $this->declaringClass = $declaringClass;
        $this->propertyName = $propertyName;
    }
    public function getReadableType() : Type {
        if ($this->propertyName === 'original') {
            if ($this->declaringClass
                ->isSubclassOf('Drupal\\Core\\Entity\\ContentEntityInterface')) {
                $objectType = 'Drupal\\Core\\Entity\\ContentEntityInterface';
            }
            elseif ($this->declaringClass
                ->isSubclassOf('Drupal\\Core\\Config\\Entity\\ConfigEntityInterface')) {
                $objectType = 'Drupal\\Core\\Config\\Entity\\ConfigEntityInterface';
            }
            else {
                $objectType = 'Drupal\\Core\\Entity\\EntityInterface';
            }
            return new ObjectType($objectType);
        }
        if ($this->declaringClass
            ->isSubclassOf('Drupal\\Core\\Entity\\ContentEntityInterface')) {
            // Assume the property is a field.
            return new ObjectType('Drupal\\Core\\Field\\FieldItemListInterface');
        }
        return new MixedType();
    }
    public function getWritableType() : Type {
        if ($this->propertyName === 'original') {
            if ($this->declaringClass
                ->isSubclassOf('Drupal\\Core\\Entity\\ContentEntityInterface')) {
                $objectType = 'Drupal\\Core\\Entity\\ContentEntityInterface';
            }
            elseif ($this->declaringClass
                ->isSubclassOf('Drupal\\Core\\Config\\Entity\\ConfigEntityInterface')) {
                $objectType = 'Drupal\\Core\\Config\\Entity\\ConfigEntityInterface';
            }
            else {
                $objectType = 'Drupal\\Core\\Entity\\EntityInterface';
            }
            return new ObjectType($objectType);
        }
        // @todo Drupal allows $entity->field_myfield = 'string'; does this break that?
        if ($this->declaringClass
            ->isSubclassOf('Drupal\\Core\\Entity\\ContentEntityInterface')) {
            // Assume the property is a field.
            return new ObjectType('Drupal\\Core\\Field\\FieldItemListInterface');
        }
        return new MixedType();
    }
    public function canChangeTypeAfterAssignment() : bool {
        return true;
    }
    public function getDeclaringClass() : ClassReflection {
        return $this->declaringClass;
    }
    public function isStatic() : bool {
        return false;
    }
    public function isPrivate() : bool {
        return false;
    }
    public function isPublic() : bool {
        return true;
    }
    public function isReadable() : bool {
        return true;
    }
    public function isWritable() : bool {
        return true;
    }
    public function getDeprecatedDescription() : ?string {
        return null;
    }
    public function getDocComment() : ?string {
        return null;
    }
    public function isDeprecated() : TrinaryLogic {
        return TrinaryLogic::createNo();
    }
    public function isInternal() : TrinaryLogic {
        return TrinaryLogic::createNo();
    }

}

Members

Title Sort descending Modifiers Object type Summary
EntityFieldReflection::$declaringClass private property @var ClassReflection
EntityFieldReflection::$propertyName private property @var string
EntityFieldReflection::canChangeTypeAfterAssignment public function
EntityFieldReflection::getDeclaringClass public function
EntityFieldReflection::getDeprecatedDescription public function
EntityFieldReflection::getDocComment public function
EntityFieldReflection::getReadableType public function
EntityFieldReflection::getWritableType public function
EntityFieldReflection::isDeprecated public function
EntityFieldReflection::isInternal public function
EntityFieldReflection::isPrivate public function
EntityFieldReflection::isPublic public function
EntityFieldReflection::isReadable public function
EntityFieldReflection::isStatic public function
EntityFieldReflection::isWritable public function
EntityFieldReflection::__construct public function

API Navigation

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