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

Arguments::empty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 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