1111 */
1212class ArrayList extends Validator
1313{
14+ /**
15+ * @var ?Validator
16+ */
17+ protected ?Validator $ validator ;
18+
1419 /**
1520 * @var Validator
1621 */
17- protected Validator $ validator ;
22+ protected Validator $ cleanValidator ;
1823
1924 /**
2025 * @var int
@@ -31,7 +36,7 @@ class ArrayList extends Validator
3136 */
3237 public function __construct (Validator $ validator , int $ length = 0 )
3338 {
34- $ this ->validator = $ validator ;
39+ $ this ->cleanValidator = $ validator ;
3540 $ this ->length = $ length ;
3641 }
3742
@@ -50,7 +55,7 @@ public function getDescription(): string
5055 $ msg .= ' no longer than ' . $ this ->length . ' items ' ;
5156 }
5257
53- if (!empty ($ this ->validator ->getDescription ())) {
58+ if ($ this -> validator != null && !empty ($ this ->validator ->getDescription ())) {
5459 $ msg .= ' and ' . $ this ->validator ->getDescription ();
5560 }
5661
@@ -78,7 +83,7 @@ public function isArray(): bool
7883 */
7984 public function getType (): string
8085 {
81- return $ this ->validator ->getType ();
86+ return $ this ->cleanValidator ->getType ();
8287 }
8388
8489 /**
@@ -88,7 +93,7 @@ public function getType(): string
8893 */
8994 public function getValidator (): Validator
9095 {
91- return $ this ->validator ;
96+ return $ this ->cleanValidator ;
9297 }
9398
9499 /**
@@ -101,6 +106,8 @@ public function getValidator(): Validator
101106 */
102107 public function isValid (mixed $ value ): bool
103108 {
109+ $ this ->validator = null ;
110+
104111 if (!\is_array ($ value )) {
105112 return false ;
106113 }
@@ -109,6 +116,8 @@ public function isValid(mixed $value): bool
109116 return false ;
110117 }
111118
119+ $ this ->validator = clone $ this ->cleanValidator ;
120+
112121 foreach ($ value as $ element ) {
113122 if (!$ this ->validator ->isValid ($ element )) {
114123 return false ;
0 commit comments