Completed
Pull Request — master (#29)
by Jitendra
01:45
created

Argument   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 11 2
A prepDefault() 0 4 4
1
<?php
2
3
namespace Ahc\Cli\Input;
4
5
/**
6
 * Cli Option.
7
 *
8
 * @author  Jitendra Adhikari <[email protected]>
9
 * @license MIT
10
 *
11
 * @link    https://github.com/adhocore/cli
12
 */
13
class Argument extends Parameter
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    protected function parse(string $arg)
19
    {
20
        $this->name = $name = \str_replace(['<', '>', '[', ']', '.'], '', $arg);
21
22
        // Format is "name:default+value1,default+value2" ('+' => ' ')!
23
        if (\strpos($name, ':') !== false) {
24
            $name                             = \str_replace('+', ' ', $name);
25
            list($this->name, $this->default) = \explode(':', $name, 2);
26
        }
27
28
        $this->prepDefault();
29
    }
30
31
    protected function prepDefault()
32
    {
33
        if ($this->variadic && $this->default && !\is_array($this->default)) {
34
            $this->default = \explode(',', $this->default, 2);
35
        }
36
    }
37
}
38