Passed
Push — master ( 2f01ca...ac7767 )
by PHPinnacle
06:39
created

Arguments   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
dl 0
loc 73
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A list() 0 3 1
A empty() 0 3 1
A inject() 0 9 2
A getIterator() 0 3 1
A count() 0 3 1
A __construct() 0 3 1
A merge() 0 3 1
1
<?php
2
/**
3
 * This file is part of PHPinnacle/Ensign.
4
 *
5
 * (c) PHPinnacle Team <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types = 1);
12
13
namespace PHPinnacle\Ensign;
14
15
final class Arguments implements \IteratorAggregate, \Countable
16
{
17
    /**
18
     * @var array
19
     */
20
    private $list;
21
22
    /**
23
     * @param array $list
24
     */
25 15
    private function __construct(array $list)
26
    {
27 15
        $this->list = $list;
28 15
    }
29
30
    /**
31
     * @return self
32
     */
33 10
    public static function empty(): self
34
    {
35 10
        return new self([]);
36
    }
37
38
    /**
39
     * @param array $arguments
40
     *
41
     * @return self
42
     */
43 13
    public static function list(array $arguments): self
44
    {
45 13
        return new self($arguments);
46
    }
47
48
    /**
49
     * @param Arguments $other
50
     *
51
     * @return self
52
     */
53 1
    public function merge(Arguments $other): self
54
    {
55 1
        return self::list(\array_replace($this->list, $other->list));
56
    }
57
58
    /**
59
     * @param Arguments $other
60
     *
61
     * @return self
62
     */
63 10
    public function inject(Arguments $other): self
64
    {
65 10
        $list = $this->list;
66
67 10
        foreach ($other->list as $position => $argument) {
68 3
            \array_splice($list, $position, 0, [$argument]);
69
        }
70
71 10
        return self::list($list);
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77 2
    public function count()
78
    {
79 2
        return \count($this->list);
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85 13
    public function getIterator()
86
    {
87 13
        yield from $this->list;
88 13
    }
89
}
90