Total Complexity | 12 |
Total Lines | 86 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
15 | class KeepOptions |
||
16 | { |
||
17 | /** |
||
18 | * @var null|bool |
||
19 | */ |
||
20 | public $errorKeep; |
||
21 | |||
22 | /** |
||
23 | * @var null|bool |
||
24 | */ |
||
25 | public $keep; |
||
26 | |||
27 | /** |
||
28 | * @var Args |
||
29 | */ |
||
30 | private $args; |
||
31 | |||
32 | /** |
||
33 | * @param Args $args |
||
34 | * |
||
35 | * @return KeepOptions |
||
36 | */ |
||
37 | 1 | public static function bind(Args $args) |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * @param Args $args |
||
44 | */ |
||
45 | 8 | public function __construct(Args $args) |
|
48 | } |
||
49 | |||
50 | /** |
||
51 | * @throws StatusException w/ conflicting arguments |
||
52 | * |
||
53 | * @return KeepOptions |
||
54 | */ |
||
55 | 1 | public function run() |
|
56 | { |
||
57 | 1 | list($this->errorKeep, $this->keep) = $this->parse($this->args); |
|
58 | |||
59 | 1 | return $this; |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * Parse keep arguments |
||
64 | * |
||
65 | * @param Args $args |
||
66 | * |
||
67 | * @throws \InvalidArgumentException |
||
68 | * @throws StatusException |
||
69 | * |
||
70 | * @return array |
||
71 | */ |
||
72 | 8 | public function parse(Args $args) |
|
73 | { |
||
74 | 8 | $errorKeep = $args->hasOption('error-keep'); |
|
75 | |||
76 | 8 | $keep = $args->hasOption('keep'); |
|
77 | |||
78 | 8 | $noKeep = $args->hasOption('no-keep'); |
|
79 | |||
80 | 8 | if ($keep && $noKeep) { |
|
81 | 1 | throw new StatusException('--keep and --no-keep are exclusive', 1); |
|
82 | } |
||
83 | |||
84 | 7 | if ($keep && $errorKeep) { |
|
85 | 1 | throw new StatusException('--keep and --error-keep are exclusive', 1); |
|
86 | } |
||
87 | |||
88 | 6 | if ($noKeep && $errorKeep) { |
|
89 | 1 | throw new StatusException('--error-keep and --no-keep are exclusive', 1); |
|
90 | } |
||
91 | |||
92 | 5 | return array($errorKeep, $keep && !$noKeep); |
|
93 | } |
||
94 | |||
95 | /** |
||
96 | * @return bool |
||
97 | */ |
||
98 | 1 | public function hasErrorKeep() |
|
101 | } |
||
102 | } |
||
103 |