Total Complexity | 8 |
Total Lines | 64 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class CallbackOptionHandler implements OptionHandler |
||
9 | { |
||
10 | |||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $option; |
||
15 | |||
16 | /** |
||
17 | * @var callable |
||
18 | */ |
||
19 | protected $callable; |
||
20 | |||
21 | /** |
||
22 | * |
||
23 | * @param string $option |
||
24 | * @param callable $callable |
||
25 | */ |
||
26 | 1 | public function __construct( |
|
27 | string $option, |
||
28 | callable $callable, |
||
29 | ) { |
||
30 | 1 | $this->option = $option; |
|
31 | 1 | $this->callable = $callable; |
|
32 | } |
||
33 | |||
34 | 1 | public function setOption($option): OptionHandler |
|
35 | { |
||
36 | 1 | $this->option = $option; |
|
37 | |||
38 | 1 | return $this; |
|
39 | } |
||
40 | |||
41 | /** |
||
42 | * Check to see if the required option is present and has a value |
||
43 | * If false is returned then the callback is not executed |
||
44 | * |
||
45 | * @param InterceptedCommand $intercepted |
||
46 | * @return boolean |
||
47 | */ |
||
48 | 1 | public function check(InterceptedCommand $intercepted): bool |
|
49 | { |
||
50 | if ( |
||
51 | 1 | $intercepted->getInput()->hasOption($this->option) |
|
52 | // If the option has a value or does not accept a value |
||
53 | 1 | && ($intercepted->getInput()->getOption($this->option) |
|
54 | 1 | || !$intercepted->getArtisan()->getDefinition()->getOption($this->option)->acceptValue()) |
|
55 | ) { |
||
56 | 1 | return true; |
|
57 | } |
||
58 | 1 | return false; |
|
59 | |||
60 | } |
||
61 | |||
62 | /** |
||
63 | * The handle function will execute the stored closure |
||
64 | * |
||
65 | * @param InterceptedCommand $intercepted |
||
66 | * @return void |
||
67 | */ |
||
68 | 1 | public function handle(InterceptedCommand $intercepted): void |
|
72 | } |
||
73 | } |
||
74 | } |
||
75 |