@@ -65,53 +65,27 @@ protected function validateItems(&$value, $schema = null, JsonPointer $path = nu
6565 {
6666 if (is_object ($ schema ->items )) {
6767 // just one type definition for the whole array
68+ foreach ($ value as $ k => &$ v ) {
69+ $ initErrors = $ this ->getErrors ();
6870
69- if (isset ($ schema ->items ->type )
70- && (
71- $ schema ->items ->type == 'string '
72- || $ schema ->items ->type == 'number '
73- || $ schema ->items ->type == 'integer '
74- )
75- && !isset ($ schema ->additionalItems )
76- ) {
77- // performance optimization
78- $ type = $ schema ->items ->type ;
79- $ typeValidator = $ this ->factory ->createInstanceFor ('type ' );
80- $ validator = $ this ->factory ->createInstanceFor ($ type === 'integer ' ? 'number ' : $ type );
81-
82- foreach ($ value as $ k => &$ v ) {
83- $ k_path = $ this ->incrementPath ($ path , $ k );
84- $ typeValidator ->check ($ v , $ schema ->items , $ k_path , $ i );
71+ // First check if its defined in "items"
72+ $ this ->checkUndefined ($ v , $ schema ->items , $ path , $ k );
8573
86- $ validator ->check ($ v , $ schema ->items , $ k_path , $ i );
74+ // Recheck with "additionalItems" if the first test fails
75+ if (count ($ initErrors ) < count ($ this ->getErrors ()) && (isset ($ schema ->additionalItems ) && $ schema ->additionalItems !== false )) {
76+ $ secondErrors = $ this ->getErrors ();
77+ $ this ->checkUndefined ($ v , $ schema ->additionalItems , $ path , $ k );
8778 }
88- unset($ v ); /* remove dangling reference to prevent any future bugs
89- * caused by accidentally using $v elsewhere */
90- $ this ->addErrors ($ typeValidator ->getErrors ());
91- $ this ->addErrors ($ validator ->getErrors ());
92- } else {
93- foreach ($ value as $ k => &$ v ) {
94- $ initErrors = $ this ->getErrors ();
95-
96- // First check if its defined in "items"
97- $ this ->checkUndefined ($ v , $ schema ->items , $ path , $ k );
98-
99- // Recheck with "additionalItems" if the first test fails
100- if (count ($ initErrors ) < count ($ this ->getErrors ()) && (isset ($ schema ->additionalItems ) && $ schema ->additionalItems !== false )) {
101- $ secondErrors = $ this ->getErrors ();
102- $ this ->checkUndefined ($ v , $ schema ->additionalItems , $ path , $ k );
103- }
10479
105- // Reset errors if needed
106- if (isset ($ secondErrors ) && count ($ secondErrors ) < count ($ this ->getErrors ())) {
107- $ this ->errors = $ secondErrors ;
108- } elseif (isset ($ secondErrors ) && count ($ secondErrors ) === count ($ this ->getErrors ())) {
109- $ this ->errors = $ initErrors ;
110- }
80+ // Reset errors if needed
81+ if (isset ($ secondErrors ) && count ($ secondErrors ) < count ($ this ->getErrors ())) {
82+ $ this ->errors = $ secondErrors ;
83+ } elseif (isset ($ secondErrors ) && count ($ secondErrors ) === count ($ this ->getErrors ())) {
84+ $ this ->errors = $ initErrors ;
11185 }
112- unset($ v ); /* remove dangling reference to prevent any future bugs
113- * caused by accidentally using $v elsewhere */
11486 }
87+ unset($ v ); /* remove dangling reference to prevent any future bugs
88+ * caused by accidentally using $v elsewhere */
11589 } else {
11690 // Defined item type definitions
11791 foreach ($ value as $ k => &$ v ) {
0 commit comments