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