@@ -15,6 +15,7 @@ final class ArrayMatcher extends Matcher
15
15
{
16
16
const PATTERN = 'array ' ;
17
17
const UNBOUNDED_PATTERN = '@...@ ' ;
18
+ const UNIVERSAL_KEY = '@*@ ' ;
18
19
19
20
private $ propertyMatcher ;
20
21
@@ -70,18 +71,20 @@ private function iterateMatch(array $values, array $patterns, string $parentPath
70
71
foreach ($ values as $ key => $ value ) {
71
72
$ path = $ this ->formatAccessPath ($ key );
72
73
73
- if ($ this ->shouldSkippValueMatchingFor ($ pattern )) {
74
+ if ($ this ->shouldSkipValueMatchingFor ($ pattern )) {
74
75
continue ;
75
76
}
76
77
77
78
if ($ this ->valueExist ($ path , $ patterns )) {
78
79
$ pattern = $ this ->getValueByPath ($ patterns , $ path );
80
+ } elseif (isset ($ patterns [self ::UNIVERSAL_KEY ])) {
81
+ $ pattern = $ patterns [self ::UNIVERSAL_KEY ];
79
82
} else {
80
83
$ this ->setMissingElementInError ('pattern ' , $ this ->formatFullPath ($ parentPath , $ path ));
81
84
return false ;
82
85
}
83
86
84
- if ($ this ->shouldSkippValueMatchingFor ($ pattern )) {
87
+ if ($ this ->shouldSkipValueMatchingFor ($ pattern )) {
85
88
continue ;
86
89
}
87
90
@@ -138,9 +141,13 @@ function ($item) use ($skipPattern) {
138
141
return true ;
139
142
}
140
143
141
- private function findNotExistingKeys (array $ pattern , array $ values ) : array
144
+ private function findNotExistingKeys (array $ patterns , array $ values ) : array
142
145
{
143
- $ notExistingKeys = \array_diff_key ($ pattern , $ values );
146
+ if (isset ($ patterns [self ::UNIVERSAL_KEY ])) {
147
+ return [];
148
+ }
149
+
150
+ $ notExistingKeys = \array_diff_key ($ patterns , $ values );
144
151
145
152
return \array_filter ($ notExistingKeys , function ($ pattern ) use ($ values ) {
146
153
if (\is_array ($ pattern )) {
@@ -230,7 +237,7 @@ private function formatFullPath(string $parentPath, string $path) : string
230
237
return \sprintf ('%s%s ' , $ parentPath , $ path );
231
238
}
232
239
233
- private function shouldSkippValueMatchingFor ($ lastPattern ) : bool
240
+ private function shouldSkipValueMatchingFor ($ lastPattern ) : bool
234
241
{
235
242
return $ lastPattern === self ::UNBOUNDED_PATTERN ;
236
243
}
0 commit comments