@@ -26,21 +26,25 @@ public static function is(string $name) : bool
26
26
return self ::NAME === $ name ;
27
27
}
28
28
29
- public function __construct (string $ pattern , bool $ isStrict = true )
29
+ /**
30
+ * @param array|string $pattern array to be matched or json-encoded string
31
+ */
32
+ public function __construct ($ pattern , bool $ isStrict = true )
30
33
{
31
- if (!\is_string ($ pattern )) {
32
- throw new \InvalidArgumentException ('Repeat pattern must be a string. ' );
33
- }
34
-
35
34
$ this ->pattern = $ pattern ;
36
35
$ this ->isStrict = $ isStrict ;
37
36
$ this ->isScalar = true ;
38
37
39
- $ json = \json_decode ($ pattern , true );
40
-
41
- if ($ json !== null && \json_last_error () === JSON_ERROR_NONE ) {
42
- $ this ->pattern = $ json ;
38
+ if (\is_string ($ pattern )) {
39
+ $ json = \json_decode ($ pattern , true );
40
+ if ($ json !== null && \json_last_error () === JSON_ERROR_NONE ) {
41
+ $ this ->pattern = $ json ;
42
+ $ this ->isScalar = false ;
43
+ }
44
+ } elseif (\is_array ($ pattern )) {
43
45
$ this ->isScalar = false ;
46
+ } else {
47
+ throw new \InvalidArgumentException ('Repeat pattern must be a string or an array. ' );
44
48
}
45
49
}
46
50
@@ -80,11 +84,6 @@ private function matchScalar(array $values, Matcher $matcher) : bool
80
84
return true ;
81
85
}
82
86
83
- /**
84
- * @param array $values
85
- * @param Matcher $matcher
86
- * @return bool
87
- */
88
87
private function matchJson (array $ values , Matcher $ matcher ) : bool
89
88
{
90
89
$ patternKeys = \array_keys ($ this ->pattern );
0 commit comments