Argument   A
last analyzed

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
/*
4
 * This file is part of the PHP-CLI package.
5
 *
6
 * (c) Jitendra Adhikari <[email protected]>
7
 *     <https://github.com/adhocore>
8
 *
9
 * Licensed under MIT license.
10
 */
11
12
namespace Ahc\Cli\Input;
13
14
/**
15
 * Cli Option.
16
 *
17
 * @author  Jitendra Adhikari <[email protected]>
18
 * @license MIT
19
 *
20
 * @link    https://github.com/adhocore/cli
21
 */
22
class Argument extends Parameter
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function parse(string $arg)
28
    {
29
        $this->name = $name = \str_replace(['<', '>', '[', ']', '.'], '', $arg);
30
31
        // Format is "name:default+value1,default+value2" ('+' => ' ')!
32
        if (\strpos($name, ':') !== false) {
33
            $name                             = \str_replace('+', ' ', $name);
34
            list($this->name, $this->default) = \explode(':', $name, 2);
35
        }
36
37
        $this->prepDefault();
38
    }
39
40
    protected function prepDefault()
41
    {
42
        if ($this->variadic && $this->default && !\is_array($this->default)) {
43
            $this->default = \explode(',', $this->default, 2);
44
        }
45
    }
46
}
47