@@ -427,7 +427,7 @@ protected function &readProperty(&$objectOrArray, $property, $isIndex)
427
427
*
428
428
* @param object|array $objectOrArray The object or array to write to.
429
429
* @param string $property The property to write.
430
- * @param string $singular The singular form of the property name or null.
430
+ * @param string|null $singular The singular form of the property name or null.
431
431
* @param Boolean $isIndex Whether to interpret the property as index.
432
432
* @param mixed $value The value to write.
433
433
*
@@ -526,7 +526,7 @@ protected function camelize($string)
526
526
* Searches for add and remove methods.
527
527
*
528
528
* @param \ReflectionClass $reflClass The reflection class for the given object
529
- * @param string $singular The singular form of the property name or null.
529
+ * @param string|null $singular The singular form of the property name or null.
530
530
*
531
531
* @return array|null An array containin the adder and remover when found, null otherwise.
532
532
*
@@ -555,42 +555,32 @@ private function findAdderAndRemover(\ReflectionClass $reflClass, $singular)
555
555
}
556
556
557
557
return array ($ addMethod , $ removeMethod );
558
- } else {
559
- // The plural form is the last element of the property path
560
- $ plural = ucfirst ($ this ->elements [$ this ->length - 1 ]);
561
-
562
- // Any of the two methods is required, but not yet known
563
- $ singulars = (array ) FormUtil::singularify ($ plural );
564
-
565
- foreach ($ singulars as $ singular ) {
566
- $ methodsFound = 0 ;
567
- $ addMethodFound = false ;
568
- $ addMethodName = 'add ' . $ singular ;
569
- $ removeMethodName = 'remove ' . $ singular ;
570
-
571
- if ($ this ->isAccessible ($ reflClass , $ addMethodName , 1 )) {
572
- $ addMethod = $ addMethodName ;
573
- $ addMethodFound = true ;
574
- $ methodsFound ++;
575
- }
558
+ }
576
559
577
- if ($ this ->isAccessible ($ reflClass , $ removeMethodName , 1 )) {
578
- $ removeMethod = $ removeMethodName ;
579
- $ methodsFound ++;
580
- }
560
+ // The plural form is the last element of the property path
561
+ $ plural = ucfirst ($ this ->elements [$ this ->length - 1 ]);
581
562
582
- if (2 == $ methodsFound ) {
583
- return array ($ addMethod , $ removeMethod );
584
- }
563
+ // Any of the two methods is required, but not yet known
564
+ $ singulars = (array ) FormUtil::singularify ($ plural );
585
565
586
- if (1 == $ methodsFound ) {
587
- throw new InvalidPropertyException (sprintf (
588
- 'Found the public method "%s", but did not find a public "%s" on class %s ' ,
589
- $ addMethodFound ? $ addMethodName : $ removeMethodName ,
590
- $ addMethodFound ? $ removeMethodName : $ addMethodName ,
591
- $ reflClass ->getName ()
592
- ));
593
- }
566
+ foreach ($ singulars as $ singular ) {
567
+ $ addMethod = 'add ' . $ singular ;
568
+ $ removeMethod = 'remove ' . $ singular ;
569
+
570
+ $ addMethodFound = $ this ->isAccessible ($ reflClass , $ addMethod , 1 );
571
+ $ removeMethodFound = $ this ->isAccessible ($ reflClass , $ removeMethod , 1 );
572
+
573
+ if ($ addMethodFound && $ removeMethodFound ) {
574
+ return array ($ addMethod , $ removeMethod );
575
+ }
576
+
577
+ if ($ addMethodFound xor $ removeMethodFound ) {
578
+ throw new InvalidPropertyException (sprintf (
579
+ 'Found the public method "%s", but did not find a public "%s" on class %s ' ,
580
+ $ addMethodFound ? $ addMethod : $ removeMethod ,
581
+ $ addMethodFound ? $ removeMethod : $ addMethod ,
582
+ $ reflClass ->getName ()
583
+ ));
594
584
}
595
585
}
596
586
0 commit comments