File tree Expand file tree Collapse file tree 3 files changed +19
-10
lines changed Expand file tree Collapse file tree 3 files changed +19
-10
lines changed Original file line number Diff line number Diff line change @@ -25,16 +25,18 @@ parameters:
25
25
storage : Drupal\user\UserStorage
26
26
block :
27
27
class : Drupal\block\Entity\Block
28
- storage : Drupal\Core\Config\Entity\ConfigEntityStorage
29
28
parametersSchema :
30
29
drupal : structure ([
31
30
drupal_root : string ()
32
- entityMapping : arrayOf (
31
+ entityMapping : arrayOf (anyOf (
32
+ structure ([
33
+ class : string ()
34
+ ]),
33
35
structure ([
34
36
class : string ()
35
37
storage : string ()
36
38
])
37
- )
39
+ ))
38
40
])
39
41
rules :
40
42
- mglaman\PHPStanDrupal\Rules\Classes\PluginManagerInspectionRule
Original file line number Diff line number Diff line change 2
2
3
3
namespace mglaman \PHPStanDrupal \Drupal ;
4
4
5
+ use Drupal \Core \Config \Entity \ConfigEntityInterface ;
5
6
use Drupal \Core \Config \Entity \ConfigEntityStorageInterface ;
7
+ use Drupal \Core \Entity \ContentEntityInterface ;
6
8
use Drupal \Core \Entity \ContentEntityStorageInterface ;
7
9
use Drupal \Core \Entity \EntityStorageInterface ;
8
10
use mglaman \PHPStanDrupal \Type \EntityStorage \ConfigEntityStorageType ;
@@ -43,10 +45,17 @@ public function getClassType(): ?ObjectType
43
45
public function getStorageType (): ?ObjectType
44
46
{
45
47
if ($ this ->storageClassName === null ) {
46
- // @todo get entity type class reflection and return proper storage for entity type
47
- // example: config storage, sqlcontententitystorage, etc.
48
- // $className = reflectedDecision.
49
- return null ;
48
+ $ classType = $ this ->getClassType ();
49
+ if ($ classType === null ) {
50
+ return null ;
51
+ }
52
+ if ((new ObjectType (ConfigEntityInterface::class))->isSuperTypeOf ($ classType )->yes ()) {
53
+ $ this ->storageClassName = 'Drupal\Core\Config\Entity\ConfigEntityStorage ' ;
54
+ } elseif ((new ObjectType (ContentEntityInterface::class))->isSuperTypeOf ($ classType )->yes ()) {
55
+ $ this ->storageClassName = 'Drupal\Core\Entity\Sql\SqlContentEntityStorage ' ;
56
+ } else {
57
+ return null ;
58
+ }
50
59
}
51
60
52
61
$ storageType = new ObjectType ($ this ->storageClassName );
Original file line number Diff line number Diff line change 12
12
assertType ('Drupal\taxonomy\TermStorage ' , $ etm ->getStorage ('taxonomy_term ' ));
13
13
assertType ('Drupal\Core\Entity\EntityStorageInterface ' , $ etm ->getStorage ('search_api_index ' ));
14
14
assertType ('Drupal\Core\Config\Entity\ConfigEntityStorage ' , $ etm ->getStorage ('block ' ));
15
- // @todo fix this assert with a lookup on known entity class type.
16
- // assertType('Drupal\Core\Entity\Sql\SqlContentEntityStorage', $etm->getStorage('content_entity_using_default_storage'));
17
- assertType ('Drupal\Core\Entity\EntityStorageInterface ' , $ etm ->getStorage ('content_entity_using_default_storage ' ));
15
+ assertType ('Drupal\Core\Entity\Sql\SqlContentEntityStorage ' , $ etm ->getStorage ('content_entity_using_default_storage ' ));
18
16
assertType ('Drupal\phpstan_fixtures\CustomContentEntityStorage ' , $ etm ->getStorage ('content_entity_using_custom_storage ' ));
19
17
assertType ('Drupal\Core\Config\Entity\ConfigEntityStorage ' , $ etm ->getStorage ('config_entity_using_default_storage ' ));
20
18
assertType ('Drupal\phpstan_fixtures\CustomConfigEntityStorage ' , $ etm ->getStorage ('config_entity_using_custom_storage ' ));
You can’t perform that action at this time.
0 commit comments