7
7
use Psr \Container \ContainerInterface as Container ;
8
8
9
9
/**
10
- * @psalm -import-type ExtendingService from \Inpsyde\Modularity\Module\ExtendingModule
10
+ * @phpstan -import-type ExtendingService from \Inpsyde\Modularity\Module\ExtendingModule
11
11
*/
12
12
class ServiceExtensions
13
13
{
@@ -20,6 +20,7 @@ class ServiceExtensions
20
20
21
21
/**
22
22
* @param string $type
23
+ *
23
24
* @return string
24
25
*/
25
26
final public static function typeId (string $ type ): string
@@ -30,18 +31,22 @@ final public static function typeId(string $type): string
30
31
/**
31
32
* @param string $extensionId
32
33
* @param ExtendingService $extender
34
+ *
33
35
* @return static
34
36
*/
35
37
public function add (string $ extensionId , callable $ extender ): ServiceExtensions
36
38
{
37
- isset ($ this ->extensions [$ extensionId ]) or $ this ->extensions [$ extensionId ] = [];
39
+ if (!isset ($ this ->extensions [$ extensionId ])) {
40
+ $ this ->extensions [$ extensionId ] = [];
41
+ }
38
42
$ this ->extensions [$ extensionId ][] = $ extender ;
39
43
40
44
return $ this ;
41
45
}
42
46
43
47
/**
44
48
* @param string $extensionId
49
+ *
45
50
* @return bool
46
51
*/
47
52
public function has (string $ extensionId ): bool
@@ -53,6 +58,7 @@ public function has(string $extensionId): bool
53
58
* @param mixed $service
54
59
* @param string $id
55
60
* @param Container $container
61
+ *
56
62
* @return mixed
57
63
*/
58
64
final public function resolve ($ service , string $ id , Container $ container )
@@ -68,6 +74,7 @@ final public function resolve($service, string $id, Container $container)
68
74
* @param string $id
69
75
* @param mixed $service
70
76
* @param Container $container
77
+ *
71
78
* @return mixed
72
79
*/
73
80
protected function resolveById (string $ id , $ service , Container $ container )
@@ -83,7 +90,8 @@ protected function resolveById(string $id, $service, Container $container)
83
90
* @param string $className
84
91
* @param object $service
85
92
* @param Container $container
86
- * @param array $extendedClasses
93
+ * @param string[] $extendedClasses
94
+ *
87
95
* @return mixed
88
96
*
89
97
* phpcs:disable Generic.Metrics.CyclomaticComplexity
@@ -110,8 +118,7 @@ protected function resolveByType(
110
118
}
111
119
112
120
// 2nd group of extensions: targeting parent classes
113
- $ parents = class_parents ($ service , false );
114
- ($ parents === false ) and $ parents = [];
121
+ $ parents = class_parents ($ service , false ) ?: [];
115
122
foreach ($ parents as $ parentName ) {
116
123
$ byParent = $ this ->extensions [self ::typeId ($ parentName )] ?? null ;
117
124
if (($ byParent !== null ) && ($ byParent !== [])) {
@@ -120,8 +127,7 @@ protected function resolveByType(
120
127
}
121
128
122
129
// 3rd group of extensions: targeting implemented interfaces
123
- $ interfaces = class_implements ($ service , false );
124
- ($ interfaces === false ) and $ interfaces = [];
130
+ $ interfaces = class_implements ($ service , false ) ?: [];
125
131
foreach ($ interfaces as $ interfaceName ) {
126
132
$ byInterface = $ this ->extensions [self ::typeId ($ interfaceName )] ?? null ;
127
133
if (($ byInterface !== null ) && ($ byInterface !== [])) {
@@ -163,6 +169,7 @@ protected function resolveByType(
163
169
* @param object $service
164
170
* @param Container $container
165
171
* @param list<ExtendingService> $extenders
172
+ *
166
173
* @return list{mixed, int}
167
174
*/
168
175
private function extendByType (
0 commit comments