Conditions | 5 |
Paths | 4 |
Total Lines | 22 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 16 |
CRAP Score | 5.005 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
17 | 4 | public function parse(string $input): ParsedCommand |
|
18 | { |
||
19 | 4 | $pattern = '#(?<cmd>^"[^"]*"|\S*) *(?<prm>.*)?#'; |
|
20 | 4 | ||
21 | $matches = array(); |
||
22 | 4 | if (! preg_match($pattern, $input, $matches)) { |
|
23 | 4 | throw new ParserException("Could not parse command"); |
|
24 | } |
||
25 | $cmd = $matches['cmd']; |
||
26 | 4 | ||
27 | $args = $this->parseSentence($matches['prm']); |
||
28 | 4 | ||
29 | 4 | $tmp = array(); |
|
30 | 2 | foreach ($args as $arg) { |
|
31 | 2 | if (is_string($arg) && ! empty($arg)) { |
|
32 | 2 | $tmp[] = $arg; |
|
33 | 2 | } |
|
34 | 2 | } |
|
35 | 2 | $args = $tmp; |
|
36 | |||
37 | 2 | return new ParsedCommand($cmd, $args); |
|
38 | 2 | } |
|
39 | 2 | ||
62 |