@@ -73,6 +73,7 @@ private function getOnValidate(\ReflectionMethod $method)
7373 * @param \ReflectionMethod $onFailure
7474 *
7575 * @return bool|mixed|InvalidArgumentException
76+ *
7677 * @throws \Exception
7778 */
7879 private function validate (MethodInvocation $ invocation , \ReflectionMethod $ onValidate , \ReflectionMethod $ onFailure = null )
@@ -139,19 +140,42 @@ private function findOnMethods(\ReflectionClass $class, Valid $valid)
139140 $ onValidateMethod = $ onFailureMethod = null ;
140141 foreach ($ class ->getMethods () as $ method ) {
141142 $ annotations = $ this ->reader ->getMethodAnnotations ($ method );
142- foreach ($ annotations as $ annotation ) {
143- if ($ this ->isOnValidateFound ($ annotation , $ valid , $ onValidateMethod )) {
144- $ onValidateMethod = $ method ;
145- }
146- if ($ this ->isOnFailureFound ($ annotation , $ valid , $ onFailureMethod )) {
147- $ onFailureMethod = $ method ;
148- }
149- }
143+ list ($ onValidateMethod , $ onFailureMethod ) = $ this ->scanAnnotation ($ valid , $ annotations , $ method ,
144+ $ onValidateMethod , $ onFailureMethod
145+ );
150146 }
151147
152148 return [$ onValidateMethod , $ onFailureMethod ];
153149 }
154150
151+ /**
152+ * @param Valid $valid
153+ * @param array $annotations
154+ * @param \ReflectionMethod $method
155+ * @param \ReflectionMethod $onValidateMethod
156+ * @param \ReflectionMethod $onFailureMethod
157+ *
158+ * @return array
159+ */
160+ private function scanAnnotation (
161+ Valid $ valid ,
162+ array $ annotations ,
163+ \ReflectionMethod $ method ,
164+ \ReflectionMethod $ onValidateMethod = null ,
165+ \ReflectionMethod $ onFailureMethod = null
166+ ) {
167+ foreach ($ annotations as $ annotation ) {
168+ if ($ this ->isOnValidateFound ($ annotation , $ valid , $ onValidateMethod )) {
169+ $ onValidateMethod = $ method ;
170+ }
171+ if ($ this ->isOnFailureFound ($ annotation , $ valid , $ onFailureMethod )) {
172+ $ onFailureMethod = $ method ;
173+ }
174+ }
175+
176+ return [$ onValidateMethod ,$ onFailureMethod ];
177+ }
178+
155179 /**
156180 * @param object $annotation
157181 * @param Valid $valid
0 commit comments