Skip to content

Commit 6d17808

Browse files
committed
Add more native types
1 parent 272798a commit 6d17808

18 files changed

+121
-329
lines changed

src/Dialogue/CancellableConfirm.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
*/
1313
class CancellableConfirm extends Dialogue
1414
{
15-
/**
16-
* @var bool
17-
*/
18-
private $confirm = true;
15+
private bool $confirm = true;
1916

2017
/**
2118
* Display confirmation with a button with the given text

src/Dialogue/Dialogue.php

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,19 @@
1414
*/
1515
abstract class Dialogue
1616
{
17-
/**
18-
* @var MenuStyle
19-
*/
20-
protected $style;
17+
protected MenuStyle $style;
2118

22-
/**
23-
* @var CliMenu
24-
*/
25-
protected $parentMenu;
19+
protected CliMenu $parentMenu;
2620

27-
/**
28-
* @var Terminal
29-
*/
30-
protected $terminal;
21+
protected Terminal $terminal;
3122

32-
/**
33-
* @var string $text
34-
*/
35-
protected $text;
23+
protected string $text;
3624

37-
/**
38-
* @var bool $cancellable
39-
*/
40-
protected $cancellable;
25+
protected bool $cancellable;
4126

42-
/**
43-
* @var int
44-
*/
45-
protected $x;
27+
protected int $x;
4628

47-
/**
48-
* @var int
49-
*/
50-
protected $y;
29+
protected int $y;
5130

5231
public function __construct(
5332
CliMenu $parentMenu,

src/Input/InputResult.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
*/
1010
class InputResult
1111
{
12-
/**
13-
* @var string
14-
*/
15-
private $input;
12+
private string $input;
1613

1714
public function __construct(string $input)
1815
{

src/Input/Number.php

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,17 @@
1212
*/
1313
class Number implements Input
1414
{
15-
/**
16-
* @var InputIO
17-
*/
18-
private $inputIO;
19-
20-
/**
21-
* @var string
22-
*/
23-
private $promptText = 'Enter a number:';
24-
25-
/**
26-
* @var string
27-
*/
28-
private $validationFailedText = 'Not a valid number, try again';
29-
30-
/**
31-
* @var string
32-
*/
33-
private $placeholderText = '';
34-
35-
/**
36-
* @var null|callable
37-
*/
38-
private $validator;
39-
40-
/**
41-
* @var MenuStyle
42-
*/
43-
private $style;
15+
private InputIO $inputIO;
16+
17+
private string $promptText = 'Enter a number:';
18+
19+
private string $validationFailedText = 'Not a valid number, try again';
20+
21+
private string $placeholderText = '';
22+
23+
private \Closure|null $validator = null;
24+
25+
private MenuStyle $style;
4426

4527
public function __construct(InputIO $inputIO, MenuStyle $style)
4628
{
@@ -86,7 +68,11 @@ public function getPlaceholderText(): string
8668

8769
public function setValidator(callable $validator): Input
8870
{
89-
$this->validator = $validator;
71+
if ($validator instanceof \Closure) {
72+
$validator = $validator->bindTo($this);
73+
}
74+
75+
$this->validator = $validator(...);
9076

9177
return $this;
9278
}
@@ -109,10 +95,6 @@ public function validate(string $input): bool
10995
if ($this->validator) {
11096
$validator = $this->validator;
11197

112-
if ($validator instanceof \Closure) {
113-
$validator = $validator->bindTo($this);
114-
}
115-
11698
return $validator($input);
11799
}
118100

src/Input/Password.php

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,19 @@
1111
*/
1212
class 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

src/Input/Text.php

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,17 @@
1111
*/
1212
class Text implements Input
1313
{
14-
/**
15-
* @var InputIO
16-
*/
17-
private $inputIO;
18-
19-
/**
20-
* @var string
21-
*/
22-
private $promptText = 'Enter text:';
23-
24-
/**
25-
* @var string
26-
*/
27-
private $validationFailedText = 'Invalid, 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;
14+
private InputIO $inputIO;
15+
16+
private string $promptText = 'Enter text:';
17+
18+
private string $validationFailedText = 'Invalid, try again';
19+
20+
private string $placeholderText = '';
21+
22+
private \Closure|null $validator = null;
23+
24+
private MenuStyle $style;
4325

4426
public function __construct(InputIO $inputIO, MenuStyle $style)
4527
{
@@ -85,7 +67,11 @@ public function getPlaceholderText(): string
8567

8668
public function setValidator(callable $validator): Input
8769
{
88-
$this->validator = $validator;
70+
if ($validator instanceof \Closure) {
71+
$validator = $validator->bindTo($this);
72+
}
73+
74+
$this->validator = $validator(...);
8975

9076
return $this;
9177
}
@@ -100,10 +86,6 @@ public function validate(string $input): bool
10086
if ($this->validator) {
10187
$validator = $this->validator;
10288

103-
if ($validator instanceof \Closure) {
104-
$validator = $validator->bindTo($this);
105-
}
106-
10789
return $validator($input);
10890
}
10991

src/MenuItem/AsciiArtItem.php

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,15 @@ class AsciiArtItem implements MenuItemInterface
2121
public const POSITION_LEFT = 'left';
2222
public const POSITION_RIGHT = 'right';
2323

24-
/**
25-
* @var string
26-
*/
27-
private $text;
24+
private string $text;
2825

29-
/**
30-
* @var string
31-
*/
32-
private $position;
26+
private string $position;
3327

34-
/**
35-
* @var string
36-
*/
37-
private $alternateText;
28+
private string$alternateText;
3829

39-
/**
40-
* @var int
41-
*/
42-
private $artLength;
30+
private int $artLength;
4331

44-
/**
45-
* @var DefaultStyle
46-
*/
47-
private $style;
32+
private DefaultStyle $style;
4833

4934
public function __construct(string $text, string $position = self::POSITION_CENTER, string $alt = '')
5035
{

src/MenuItem/CheckboxItem.php

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,20 @@ class CheckboxItem implements MenuItemInterface
1414
/**
1515
* @var string
1616
*/
17-
private $text;
17+
private string $text;
1818

19-
/**
20-
* @var callable
21-
*/
22-
private $selectAction;
19+
private \Closure $selectAction;
2320

24-
/**
25-
* @var bool
26-
*/
27-
private $showItemExtra;
21+
private bool $showItemExtra;
2822

29-
/**
30-
* @var bool
31-
*/
32-
private $disabled;
23+
private bool $disabled;
3324

3425
/**
3526
* The current checkbox state
36-
*
37-
* @var bool
3827
*/
39-
private $checked = false;
28+
private bool $checked = false;
4029

41-
/**
42-
* @var CheckboxStyle
43-
*/
44-
private $style;
30+
private CheckboxStyle $style;
4531

4632
public function __construct(
4733
string $text,
@@ -50,7 +36,7 @@ public function __construct(
5036
bool $disabled = false
5137
) {
5238
$this->text = $text;
53-
$this->selectAction = $selectAction;
39+
$this->selectAction = $selectAction(...);
5440
$this->showItemExtra = $showItemExtra;
5541
$this->disabled = $disabled;
5642

0 commit comments

Comments
 (0)