Arr   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 14 4
A __construct() 0 4 2
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