Total Complexity | 6 |
Total Lines | 65 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
8 | class SignatureParser |
||
9 | { |
||
10 | /** |
||
11 | * The command to build. |
||
12 | * |
||
13 | * @var Command |
||
14 | */ |
||
15 | protected $command; |
||
16 | |||
17 | /** |
||
18 | * Construct. |
||
19 | * |
||
20 | * @param Command $command |
||
21 | */ |
||
22 | public function __construct(Command $command) |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * Parse the command signature. |
||
29 | * |
||
30 | * @param string $signature |
||
31 | */ |
||
32 | public function parse($signature) |
||
33 | { |
||
34 | $this->setName($signature); |
||
35 | |||
36 | $argumentsOptions = $this->extractArgumentsOptions($signature); |
||
37 | |||
38 | foreach ($argumentsOptions as $value) { |
||
39 | if (substr($value, 0, 2) !== '--') { |
||
40 | $input = new Argument($value); |
||
41 | } else { |
||
42 | $input = new Option(trim($value, '--')); |
||
43 | } |
||
44 | |||
45 | $this->command->addInput($input->parse()); |
||
46 | } |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Set the command name. |
||
51 | * |
||
52 | * @param string $signature |
||
53 | */ |
||
54 | protected function setName($signature) |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Extract arguments and options from signature. |
||
61 | * |
||
62 | * @param string $signature |
||
63 | * |
||
64 | * @return array |
||
65 | */ |
||
66 | protected function extractArgumentsOptions($signature) |
||
75 |