1111 */
1212class Password implements Input
1313{
14- /**
15- * @var InputIO
16- */
17- private $ inputIO ;
18-
19- /**
20- * @var string
21- */
22- private $ promptText = 'Enter password: ' ;
23-
24- /**
25- * @var string
26- */
27- private $ validationFailedText = 'Invalid password, try again ' ;
28-
29- /**
30- * @var string
31- */
32- private $ placeholderText = '' ;
33-
34- /**
35- * @var null|callable
36- */
37- private $ validator ;
38-
39- /**
40- * @var MenuStyle
41- */
42- private $ style ;
43-
44- /**
45- * @var int
46- */
47- private $ passwordLength = 16 ;
14+ private InputIO $ inputIO ;
15+
16+ private string $ promptText = 'Enter password: ' ;
17+
18+ private string $ validationFailedText = 'Invalid password, try again ' ;
19+
20+ private string $ placeholderText = '' ;
21+
22+ private \Closure |null $ validator = null ;
23+
24+ private MenuStyle $ style ;
25+
26+ private int $ passwordLength = 16 ;
4827
4928 public function __construct (InputIO $ inputIO , MenuStyle $ style )
5029 {
@@ -90,7 +69,11 @@ public function getPlaceholderText(): string
9069
9170 public function setValidator (callable $ validator ): Input
9271 {
93- $ this ->validator = $ validator ;
72+ if ($ validator instanceof \Closure) {
73+ $ validator = $ validator ->bindTo ($ this );
74+ }
75+
76+ $ this ->validator = $ validator (...);
9477
9578 return $ this ;
9679 }
@@ -105,10 +88,6 @@ public function validate(string $input): bool
10588 if ($ this ->validator ) {
10689 $ validator = $ this ->validator ;
10790
108- if ($ validator instanceof \Closure) {
109- $ validator = $ validator ->bindTo ($ this );
110- }
111-
11291 return $ validator ($ input );
11392 }
11493
0 commit comments