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\ReflectionCode
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;
}