Total Complexity | 12 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php namespace Tarsana\Command\Helpers; |
||
6 | class SyntaxHelper { |
||
7 | |||
8 | protected static $instance; |
||
9 | |||
10 | public static function instance() : SyntaxHelper |
||
11 | { |
||
12 | if (null === self::$instance) |
||
13 | self::$instance = new SyntaxHelper; |
||
14 | return self::$instance; |
||
15 | } |
||
16 | |||
17 | private function __construct() {} |
||
18 | |||
19 | public function type(Syntax $syntax) : string |
||
20 | { |
||
21 | $class = explode("\\", get_class($syntax)); |
||
22 | return strtolower(substr(array_pop($class), 0, -6)); |
||
23 | } |
||
24 | |||
25 | public function asString(Syntax $syntax) : string |
||
26 | { |
||
27 | $type = $this->type($syntax); |
||
28 | if ($type == 'optional') |
||
29 | return $this->asString($syntax->syntax()); |
||
|
|||
30 | switch ($type) { |
||
31 | case 'object': |
||
32 | return implode( |
||
33 | $syntax->separator(), |
||
34 | array_keys($syntax->fields()) |
||
35 | ); |
||
36 | break; |
||
37 | case 'array': |
||
38 | $text = $this->asString($syntax->syntax()); |
||
39 | return "{$text}{$syntax->separator()}..."; |
||
40 | break; |
||
41 | default: |
||
42 | return $type; |
||
43 | } |
||
44 | } |
||
45 | |||
46 | public function fields(Syntax $syntax) : array |
||
57 | } |
||
58 | |||
59 | } |
||
60 |