Total Complexity | 8 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | class IntegerArgumentType extends ArgumentType { |
||
17 | /** |
||
18 | * @internal |
||
19 | */ |
||
20 | function __construct(\CharlotteDunois\Livia\Client $client) { |
||
21 | parent::__construct($client, 'integer'); |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * {@inheritdoc} |
||
26 | * @return bool|string|\React\Promise\ExtendedPromiseInterface |
||
27 | */ |
||
28 | function validate(string $value, \CharlotteDunois\Livia\Commands\Context $context, ?\CharlotteDunois\Livia\Arguments\Argument $arg = null) { |
||
29 | $value = \filter_var($value, \FILTER_VALIDATE_INT); |
||
30 | if($value === false) { |
||
31 | return false; |
||
32 | } |
||
33 | |||
34 | if($arg->min !== null && $value < $arg->min) { |
||
35 | return 'Please enter a number above or exactly '.$arg->min.'.'; |
||
36 | } |
||
37 | |||
38 | if($arg->max !== null && $value > $arg->max) { |
||
39 | return 'Please enter a number below or exactly '.$arg->max.'.'; |
||
40 | } |
||
41 | |||
42 | return true; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | * @return mixed|null|\React\Promise\ExtendedPromiseInterface |
||
48 | */ |
||
49 | function parse(string $value, \CharlotteDunois\Livia\Commands\Context $context, ?\CharlotteDunois\Livia\Arguments\Argument $arg = null) { |
||
51 | } |
||
52 | } |
||
53 |