4
4
5
5
use Drupal \Core \Config \Entity \ConfigEntityStorageInterface ;
6
6
use Drupal \Core \Entity \ContentEntityStorageInterface ;
7
+ use Drupal \Core \Entity \EntityStorageInterface ;
7
8
use mglaman \PHPStanDrupal \Type \EntityStorage \ConfigEntityStorageType ;
8
9
use mglaman \PHPStanDrupal \Type \EntityStorage \ContentEntityStorageType ;
9
10
use mglaman \PHPStanDrupal \Type \EntityStorage \EntityStorageType ;
10
- use PHPStan \Reflection \ReflectionProvider ;
11
- use PHPStan \Reflection \ReflectionProviderStaticAccessor ;
12
11
use PHPStan \Type \ObjectType ;
13
12
14
13
final class EntityData
@@ -29,19 +28,11 @@ final class EntityData
29
28
*/
30
29
private $ storageClassName ;
31
30
32
- /**
33
- * @var ReflectionProvider
34
- */
35
- private $ reflectionProvider ;
36
-
37
- public function __construct (string $ entityTypeId , array $ definition , ReflectionProvider $ reflectionProvider )
31
+ public function __construct (string $ entityTypeId , array $ definition )
38
32
{
39
33
$ this ->entityTypeId = $ entityTypeId ;
40
34
$ this ->className = $ definition ['class ' ] ?? null ;
41
35
$ this ->storageClassName = $ definition ['storage ' ] ?? null ;
42
- // \PHPStan\Reflection\ReflectionProviderStaticAccessor::getInstance is not covered by the backward
43
- // compatibility promise of PHPStan, so we must add it to our value object.
44
- $ this ->reflectionProvider = $ reflectionProvider ;
45
36
}
46
37
47
38
public function getClassType (): ?ObjectType
@@ -57,16 +48,15 @@ public function getStorageType(): ?ObjectType
57
48
// $className = reflectedDecision.
58
49
return null ;
59
50
}
60
- if (!$ this ->reflectionProvider ->hasClass ($ this ->storageClassName )) {
51
+
52
+ $ storageType = new ObjectType ($ this ->storageClassName );
53
+ if ((new ObjectType (EntityStorageInterface::class))->isSuperTypeOf ($ storageType )->no ()) {
61
54
return null ;
62
55
}
63
-
64
- // @todo drop reflectionProvider for ObjectType isSuperTypeOf
65
- $ reflection = $ this ->reflectionProvider ->getClass ($ this ->storageClassName );
66
- if ($ reflection ->implementsInterface (ConfigEntityStorageInterface::class)) {
56
+ if ((new ObjectType (ConfigEntityStorageInterface::class))->isSuperTypeOf ($ storageType )->yes ()) {
67
57
return new ConfigEntityStorageType ($ this ->entityTypeId , $ this ->storageClassName );
68
58
}
69
- if ($ reflection -> implementsInterface ( ContentEntityStorageInterface::class)) {
59
+ if (( new ObjectType ( ContentEntityStorageInterface::class))-> isSuperTypeOf ( $ storageType )-> yes ( )) {
70
60
return new ContentEntityStorageType ($ this ->entityTypeId , $ this ->storageClassName );
71
61
}
72
62
return new EntityStorageType ($ this ->entityTypeId , $ this ->storageClassName );
0 commit comments