@@ -35,20 +35,35 @@ final class ModelBehaviorsExtension implements MethodsClassReflectionExtension
35
35
/**
36
36
* @param array<string> $behaviorPaths
37
37
*/
38
- public function __construct (ReflectionProvider $ reflectionProvider , array $ behaviorPaths )
39
- {
38
+ public function __construct (
39
+ ReflectionProvider $ reflectionProvider ,
40
+ array $ behaviorPaths
41
+ ) {
40
42
$ this ->reflectionProvider = $ reflectionProvider ;
41
43
$ this ->behaviorPaths = $ behaviorPaths ;
42
44
}
43
45
44
- public function hasMethod (ClassReflection $ classReflection , string $ methodName ): bool
45
- {
46
+ /**
47
+ * @throws Exception
48
+ */
49
+ public function hasMethod (
50
+ ClassReflection $ classReflection ,
51
+ string $ methodName
52
+ ): bool {
46
53
return $ classReflection ->is ('Model ' )
47
- && in_array ($ methodName , array_map ([$ this , 'getMethodReflectionName ' ], $ this ->getBehaviorMethods ()));
54
+ && in_array (
55
+ $ methodName ,
56
+ array_map (
57
+ [$ this , 'getMethodReflectionName ' ],
58
+ $ this ->getBehaviorMethods ()
59
+ )
60
+ );
48
61
}
49
62
50
- public function getMethod (ClassReflection $ classReflection , string $ methodName ): MethodReflection
51
- {
63
+ public function getMethod (
64
+ ClassReflection $ classReflection ,
65
+ string $ methodName
66
+ ): MethodReflection {
52
67
$ methodReflections = array_filter (
53
68
$ this ->getBehaviorMethods (),
54
69
static function (MethodReflection $ methodReflection ) use ($ methodName ) {
@@ -101,8 +116,9 @@ private function getBehaviorMethods(): array
101
116
*
102
117
* @return array<MethodReflection>
103
118
*/
104
- private function getModelBehaviorMethods (ClassReflection $ classReflection ): array
105
- {
119
+ private function getModelBehaviorMethods (
120
+ ClassReflection $ classReflection
121
+ ): array {
106
122
$ methodNames = array_map (
107
123
[$ this , 'getMethodReflectionName ' ],
108
124
$ classReflection ->getNativeReflection ()->getMethods ()
@@ -115,8 +131,9 @@ private function getModelBehaviorMethods(ClassReflection $classReflection): arra
115
131
return array_map ([$ this , 'wrapBehaviorMethod ' ], $ methodReflections );
116
132
}
117
133
118
- private function filterBehaviorMethods (ExtendedMethodReflection $ methodReflection ): bool
119
- {
134
+ private function filterBehaviorMethods (
135
+ ExtendedMethodReflection $ methodReflection
136
+ ): bool {
120
137
return $ methodReflection ->isPublic ()
121
138
&& ! $ methodReflection ->isStatic ()
122
139
&& array_filter (
@@ -125,17 +142,19 @@ private function filterBehaviorMethods(ExtendedMethodReflection $methodReflectio
125
142
);
126
143
}
127
144
128
- private function filterBehaviorMethodVariants (ParametersAcceptor $ parametersAcceptor ): bool
129
- {
145
+ private function filterBehaviorMethodVariants (
146
+ ParametersAcceptor $ parametersAcceptor
147
+ ): bool {
130
148
$ parameters = $ parametersAcceptor ->getParameters ();
131
149
/** @var ParameterReflection|null $firstParameter */
132
150
$ firstParameter = array_shift ($ parameters );
133
151
return $ firstParameter
134
152
&& ! $ firstParameter ->getType ()->isSuperTypeOf (new ObjectType ('Model ' ))->no ();
135
153
}
136
154
137
- private function wrapBehaviorMethod (MethodReflection $ methodReflection ): MethodReflection
138
- {
155
+ private function wrapBehaviorMethod (
156
+ MethodReflection $ methodReflection
157
+ ): MethodReflection {
139
158
return new ModelBehaviorMethodWrapper ($ methodReflection );
140
159
}
141
160
0 commit comments