1111 */
1212class ArrayList extends Validator
1313{
14- /**
15- * @var ?Validator
16- */
17- protected ?Validator $ validator ;
18-
1914 /**
2015 * @var Validator
2116 */
22- protected Validator $ cleanValidator ;
17+ protected Validator $ validator ;
2318
2419 /**
2520 * @var int
@@ -36,7 +31,7 @@ class ArrayList extends Validator
3631 */
3732 public function __construct (Validator $ validator , int $ length = 0 )
3833 {
39- $ this ->cleanValidator = $ validator ;
34+ $ this ->validator = $ validator ;
4035 $ this ->length = $ length ;
4136 }
4237
@@ -55,7 +50,7 @@ public function getDescription(): string
5550 $ msg .= ' no longer than ' . $ this ->length . ' items ' ;
5651 }
5752
58- if ($ this -> validator != null && !empty ($ this ->validator ->getDescription ())) {
53+ if (!empty ($ this ->validator ->getDescription ())) {
5954 $ msg .= ' and ' . $ this ->validator ->getDescription ();
6055 }
6156
@@ -83,7 +78,7 @@ public function isArray(): bool
8378 */
8479 public function getType (): string
8580 {
86- return $ this ->cleanValidator ->getType ();
81+ return $ this ->validator ->getType ();
8782 }
8883
8984 /**
@@ -93,7 +88,7 @@ public function getType(): string
9388 */
9489 public function getValidator (): Validator
9590 {
96- return $ this ->cleanValidator ;
91+ return $ this ->validator ;
9792 }
9893
9994 /**
@@ -106,24 +101,20 @@ public function getValidator(): Validator
106101 */
107102 public function isValid (mixed $ value ): bool
108103 {
109- $ this ->validator = null ;
110-
111104 if (!\is_array ($ value )) {
112105 return false ;
113106 }
114107
115- if ($ this ->length && \count ($ value ) > $ this ->length ) {
116- return false ;
117- }
118-
119- $ this ->validator = clone $ this ->cleanValidator ;
120-
121108 foreach ($ value as $ element ) {
122109 if (!$ this ->validator ->isValid ($ element )) {
123110 return false ;
124111 }
125112 }
126113
114+ if ($ this ->length && \count ($ value ) > $ this ->length ) {
115+ return false ;
116+ }
117+
127118 return true ;
128119 }
129120}
0 commit comments