Arr::parse()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 0
1
<?php namespace nyx\console\input\formats;
2
3
// Internal dependencies
4
use nyx\console;
5
6
/**
7
 * Array Input
8
 *
9
 * @version     0.1.0
10
 * @author      Michal Chojnacki <[email protected]>
11
 * @copyright   2012-2017 Nyx Dev Team
12
 * @link        https://github.com/unyx/nyx
13
 */
14
class Arr extends console\Input
15
{
16
    /**
17
     * Constructs a new Array Input instance.
18
     *
19
     * @param   iterable    $parameters     A map of input parameters (name => value).
20
     */
21
    public function __construct(iterable $parameters)
22
    {
23
        $this->raw = $parameters instanceof interfaces\Tokens ? $parameters : new tokens\Arr($parameters);
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    protected function parse() : console\Input
30
    {
31
        foreach ($this->raw as $name => $value) {
32
            if (0 === strpos($name, '--')) {
33
                $this->options()->set(substr($name, 2), $value);
34
            } elseif ('-' === $name[0]) {
35
                $this->options()->set(substr($name, 1), $value);
36
            } else {
37
                $this->arguments()->set($name, $value);
38
            }
39
        }
40
41
        return $this;
42
    }
43
}
44