Skip to content

Commit bd192c1

Browse files
committed
Make the Meta utility class work with the ClassMetadata interface, not the concrete implementation
1 parent d44adc6 commit bd192c1

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -576,12 +576,6 @@ parameters:
576576
count: 1
577577
path: src/Timestampable/Mapping/Driver/Yaml.php
578578

579-
-
580-
message: '#^Call to function method_exists\(\) with ''Doctrine\\\\ORM\\\\Mapping\\\\ClassMetadata'' and ''getPropertyAccessor'' will always evaluate to true\.$#'
581-
identifier: function.alreadyNarrowedType
582-
count: 1
583-
path: src/Tool/ORM/Entity/Meta.php
584-
585579
-
586580
message: '#^Call to function property_exists\(\) with \$this\(Gedmo\\Translatable\\Hydrator\\ORM\\ObjectHydrator\) and ''_em'' will always evaluate to false\.$#'
587581
identifier: function.impossibleType

src/Tool/ORM/Entity/Meta.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,26 @@
99

1010
namespace Gedmo\Tool\ORM\Entity;
1111

12-
use Doctrine\ORM\Mapping\ClassMetadata;
1312
use Doctrine\ORM\Mapping\PropertyAccessors\PropertyAccessor;
13+
use Doctrine\Persistence\Mapping\ClassMetadata;
1414

1515
class Meta
1616
{
1717
/**
1818
* @param ClassMetadata<object> $meta
19+
*
20+
* @return \ReflectionProperty|PropertyAccessor|null
1921
*/
20-
public static function getProperty(ClassMetadata $meta, string $propertyName): \ReflectionProperty|PropertyAccessor|null
22+
public static function getProperty(ClassMetadata $meta, string $propertyName)
2123
{
22-
if (method_exists(ClassMetadata::class, 'getPropertyAccessor')) {
24+
if (method_exists($meta, 'getPropertyAccessor')) {
2325
return $meta->getPropertyAccessor($propertyName);
2426
}
2527

26-
return $meta->getReflectionProperty($propertyName);
28+
if (method_exists($meta, 'getReflectionProperty')) {
29+
return $meta->getReflectionProperty($propertyName);
30+
}
31+
32+
throw new \RuntimeException('Unable to determine property accessor for class '.get_class($meta));
2733
}
2834
}

0 commit comments

Comments
 (0)