@@ -23,10 +23,10 @@ trait Base
2323 private bool $ required = false ;
2424 private mixed $ default = null ;
2525
26- /** @var ?callable */
27- private $ before ;
26+ /** @var ?\Closure(mixed): mixed */
27+ private ? \ Closure $ before = null ;
2828
29- /** @var callable[] */
29+ /** @var array<\Closure(mixed, Context): mixed> */
3030 private array $ transforms = [];
3131 private ?string $ deprecated = null ;
3232
@@ -45,9 +45,10 @@ public function required(bool $state = true): self
4545 }
4646
4747
48+ /** @param callable(mixed): mixed $handler */
4849 public function before (callable $ handler ): self
4950 {
50- $ this ->before = $ handler ;
51+ $ this ->before = $ handler(...) ;
5152 return $ this ;
5253 }
5354
@@ -58,16 +59,19 @@ public function castTo(string $type): self
5859 }
5960
6061
62+ /** @param callable(mixed, Context): mixed $handler */
6163 public function transform (callable $ handler ): self
6264 {
63- $ this ->transforms [] = $ handler ;
65+ $ this ->transforms [] = $ handler(...) ;
6466 return $ this ;
6567 }
6668
6769
70+ /** @param callable(mixed): bool $handler */
6871 public function assert (callable $ handler , ?string $ description = null ): self
6972 {
7073 $ expected = $ description ?? (is_string ($ handler ) ? "$ handler() " : '# ' . count ($ this ->transforms ));
74+ $ handler = $ handler (...);
7175 return $ this ->transform (function ($ value , Context $ context ) use ($ handler , $ description , $ expected ) {
7276 if ($ handler ($ value )) {
7377 return $ value ;
0 commit comments