| Total Complexity | 9 |
| Total Lines | 69 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | class Option extends Parameter |
||
| 23 | { |
||
| 24 | /** @var string Short name */ |
||
| 25 | protected $short = ''; |
||
| 26 | |||
| 27 | /** @var string Long name */ |
||
| 28 | protected $long = ''; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * {@inheritdoc} |
||
| 32 | */ |
||
| 33 | protected function parse(string $raw) |
||
| 34 | { |
||
| 35 | if (\strpos($raw, '-with-') !== false) { |
||
| 36 | $this->default = false; |
||
| 37 | } elseif (\strpos($raw, '-no-') !== false) { |
||
| 38 | $this->default = true; |
||
| 39 | } |
||
| 40 | |||
| 41 | $parts = \preg_split('/[\s,\|]+/', $raw); |
||
| 42 | |||
| 43 | $this->short = $this->long = $parts[0]; |
||
| 44 | if (isset($parts[1])) { |
||
| 45 | $this->long = $parts[1]; |
||
| 46 | } |
||
| 47 | |||
| 48 | $this->name = \str_replace(['--', 'no-', 'with-'], '', $this->long); |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Get long name. |
||
| 53 | * |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | public function long(): string |
||
| 57 | { |
||
| 58 | return $this->long; |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Get short name. |
||
| 63 | * |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | public function short(): string |
||
| 67 | { |
||
| 68 | return $this->short; |
||
| 69 | } |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Test if this option matches given arg. |
||
| 73 | * |
||
| 74 | * @param string $arg |
||
| 75 | * |
||
| 76 | * @return bool |
||
| 77 | */ |
||
| 78 | public function is(string $arg): bool |
||
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Check if the option is boolean type. |
||
| 85 | * |
||
| 86 | * @return bool |
||
| 87 | */ |
||
| 88 | public function bool(): bool |
||
| 93 |