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

Argument::default()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
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