Passed
Push — master ( 0cfc7e...b88fc1 )
by Tom
03:33 queued 42s
created

Collector::collect()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 4
nop 1
dl 0
loc 14
ccs 10
cts 10
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\Cli\Args;
6
7
/**
8
 * Class Collector
9
 *
10
 * Collect arguments and their values from on Args to a new one.
11
 * consuming them.
12
 *
13
 * @package Ktomk\Pipelines\Cli\Args
14
 */
15
class Collector extends Args
16
{
17
    /**
18
     * @var Args
19
     */
20
    private $args;
21
22 3
    public function __construct(Args $args)
23
    {
24 3
        $this->args = $args;
25 3
    }
26
27
    /**
28
     * @param string|string[] $option one or more options to collect
29
     *
30
     * @throws \Ktomk\Pipelines\Cli\ArgsException
31
     */
32 1
    public function collect($option)
33
    {
34
        /** @var OptionFilterIterator|OptionIterator $options */
35 1
        $options = new OptionFilterIterator($this->args, $option);
36 1
        $consume = array();
37 1
        foreach ($options as $index => $option) {
38 1
            $this->arguments[] = $option;
39 1
            $consume[] = $index;
40 1
            $this->arguments[] = $options->getArgument();
41 1
            $consume[] = $index + 1;
42
        }
43
44 1
        foreach ($consume as $index) {
45 1
            unset($this->args->arguments[$index]);
46
        }
47 1
    }
48
49
    /**
50
     * @return array
51
     */
52 1
    public function getArgs()
53
    {
54 1
        return $this->arguments;
55
    }
56
}
57