@@ -44,14 +44,7 @@ public function __construct(ReflectionProvider $reflectionProvider, array $behav
44
44
public function hasMethod (ClassReflection $ classReflection , string $ methodName ): bool
45
45
{
46
46
return $ classReflection ->is ('Model ' )
47
- && count (
48
- array_filter (
49
- $ this ->getBehaviorMethods (),
50
- static function (MethodReflection $ methodReflection ) use ($ methodName ) {
51
- return $ methodReflection ->getName () === $ methodName ;
52
- }
53
- )
54
- ) > 0 ;
47
+ && in_array ($ methodName , array_map ([$ this , 'getMethodReflectionName ' ], $ this ->getBehaviorMethods ()));
55
48
}
56
49
57
50
public function getMethod (ClassReflection $ classReflection , string $ methodName ): MethodReflection
@@ -104,29 +97,48 @@ private function getBehaviorMethods(): array
104
97
*/
105
98
private function getModelBehaviorMethods (ClassReflection $ classReflection ): array
106
99
{
107
- $ methodNames = array_map (static function (ReflectionMethod $ methodReflection ) {
108
- return $ methodReflection ->getName ();
109
- }, $ classReflection ->getNativeReflection ()->getMethods ());
100
+ $ methodNames = array_map (
101
+ [$ this , 'getMethodReflectionName ' ],
102
+ $ classReflection ->getNativeReflection ()->getMethods ()
103
+ );
110
104
/** @var array<ExtendedMethodReflection> $methodReflections */
111
105
$ methodReflections = array_filter (
112
106
array_map ([$ classReflection , 'getNativeMethod ' ], $ methodNames ),
113
- static function (ExtendedMethodReflection $ methodReflection ) {
114
- return $ methodReflection ->isPublic ()
115
- && ! $ methodReflection ->isStatic ()
116
- && array_filter (
117
- $ methodReflection ->getVariants (),
118
- static function (ParametersAcceptor $ parametersAcceptor ) {
119
- $ parameters = $ parametersAcceptor ->getParameters ();
120
- /** @var ParameterReflection|null $firstParameter */
121
- $ firstParameter = array_shift ($ parameters );
122
- return $ firstParameter
123
- && ! $ firstParameter ->getType ()->isSuperTypeOf (new ObjectType ('Model ' ))->no ();
124
- }
125
- );
126
- }
107
+ [$ this , 'filterBehaviorMethods ' ]
127
108
);
128
- return array_map (static function (ExtendedMethodReflection $ methodReflection ) {
129
- return new ModelBehaviorMethodWrapper ($ methodReflection );
130
- }, $ methodReflections );
109
+ return array_map ([$ this , 'wrapBehaviorMethod ' ], $ methodReflections );
110
+ }
111
+
112
+ private function filterBehaviorMethods (ExtendedMethodReflection $ methodReflection ): bool
113
+ {
114
+ return $ methodReflection ->isPublic ()
115
+ && ! $ methodReflection ->isStatic ()
116
+ && array_filter (
117
+ $ methodReflection ->getVariants (),
118
+ [$ this , 'filterBehaviorMethodVariants ' ]
119
+ );
120
+ }
121
+
122
+ private function filterBehaviorMethodVariants (ParametersAcceptor $ parametersAcceptor ): bool
123
+ {
124
+ $ parameters = $ parametersAcceptor ->getParameters ();
125
+ /** @var ParameterReflection|null $firstParameter */
126
+ $ firstParameter = array_shift ($ parameters );
127
+ return $ firstParameter
128
+ && ! $ firstParameter ->getType ()->isSuperTypeOf (new ObjectType ('Model ' ))->no ();
129
+ }
130
+
131
+ private function wrapBehaviorMethod (MethodReflection $ methodReflection ): MethodReflection
132
+ {
133
+ return new ModelBehaviorMethodWrapper ($ methodReflection );
134
+ }
135
+
136
+ /**
137
+ * @param MethodReflection|ReflectionMethod $methodReflection
138
+ * @return string
139
+ */
140
+ private function getMethodReflectionName ($ methodReflection ): string
141
+ {
142
+ return $ methodReflection ->getName ();
131
143
}
132
144
}
0 commit comments