Skip to content

Commit 53ac37a

Browse files
committed
Remove ReflectionProvider from EntityData
1 parent ef9c81c commit 53ac37a

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed

extension.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ services:
4848
-
4949
class: mglaman\PHPStanDrupal\Drupal\EntityDataRepository
5050
arguments:
51-
reflectionProvider: @reflectionProvider
5251
entityMapping: %drupal.entityMapping%
5352

5453
-

src/Drupal/EntityData.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
use Drupal\Core\Config\Entity\ConfigEntityStorageInterface;
66
use Drupal\Core\Entity\ContentEntityStorageInterface;
7+
use Drupal\Core\Entity\EntityStorageInterface;
78
use mglaman\PHPStanDrupal\Type\EntityStorage\ConfigEntityStorageType;
89
use mglaman\PHPStanDrupal\Type\EntityStorage\ContentEntityStorageType;
910
use mglaman\PHPStanDrupal\Type\EntityStorage\EntityStorageType;
10-
use PHPStan\Reflection\ReflectionProvider;
11-
use PHPStan\Reflection\ReflectionProviderStaticAccessor;
1211
use PHPStan\Type\ObjectType;
1312

1413
final class EntityData
@@ -29,19 +28,11 @@ final class EntityData
2928
*/
3029
private $storageClassName;
3130

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)
3832
{
3933
$this->entityTypeId = $entityTypeId;
4034
$this->className = $definition['class'] ?? null;
4135
$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;
4536
}
4637

4738
public function getClassType(): ?ObjectType
@@ -57,16 +48,15 @@ public function getStorageType(): ?ObjectType
5748
// $className = reflectedDecision.
5849
return null;
5950
}
60-
if (!$this->reflectionProvider->hasClass($this->storageClassName)) {
51+
52+
$storageType = new ObjectType($this->storageClassName);
53+
if ((new ObjectType(EntityStorageInterface::class))->isSuperTypeOf($storageType)->no()) {
6154
return null;
6255
}
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()) {
6757
return new ConfigEntityStorageType($this->entityTypeId, $this->storageClassName);
6858
}
69-
if ($reflection->implementsInterface(ContentEntityStorageInterface::class)) {
59+
if ((new ObjectType(ContentEntityStorageInterface::class))->isSuperTypeOf($storageType)->yes()) {
7060
return new ContentEntityStorageType($this->entityTypeId, $this->storageClassName);
7161
}
7262
return new EntityStorageType($this->entityTypeId, $this->storageClassName);

src/Drupal/EntityDataRepository.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66

77
final class EntityDataRepository
88
{
9-
/**
10-
* @var ReflectionProvider
11-
*/
12-
private $reflectionProvider;
139

1410
/**
1511
* @var array<string, array<string, string>>
@@ -20,9 +16,8 @@ final class EntityDataRepository
2016
*/
2117
private $entityData;
2218

23-
public function __construct(ReflectionProvider $reflectionProvider, array $entityMapping)
19+
public function __construct(array $entityMapping)
2420
{
25-
$this->reflectionProvider = $reflectionProvider;
2621
$this->entityMapping = $entityMapping;
2722
}
2823

@@ -31,8 +26,7 @@ public function get(string $entityTypeId): EntityData
3126
if (!isset($this->entityData[$entityTypeId])) {
3227
$this->entityData[$entityTypeId] = new EntityData(
3328
$entityTypeId,
34-
$this->entityMapping[$entityTypeId] ?? [],
35-
$this->reflectionProvider
29+
$this->entityMapping[$entityTypeId] ?? []
3630
);
3731
}
3832
return $this->entityData[$entityTypeId];

0 commit comments

Comments
 (0)