Passed
Pull Request — master (#1)
by PHPinnacle
03:30
created

Arguments::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

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 1
nc 1
nop 1
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 16
    public function __construct(array $list)
26
    {
27 16
        $this->list = $list;
28 16
    }
29
30
    /**
31
     * @return self
32
     */
33 11
    public static function empty(): self
34
    {
35 11
        return new self([]);
36
    }
37
38
    /**
39
     * @param Arguments $other
40
     *
41
     * @return self
42
     */
43 1
    public function merge(Arguments $other): self
44
    {
45 1
        return new self(\array_replace($this->list, $other->list));
46
    }
47
48
    /**
49
     * @param Arguments $other
50
     *
51
     * @return self
52
     */
53 11
    public function inject(Arguments $other): self
54
    {
55 11
        $list = $this->list;
56
57 11
        foreach ($other->list as $position => $argument) {
58 3
            \array_splice($list, $position, 0, [$argument]);
59
        }
60
61 11
        return new self($list);
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 2
    public function count()
68
    {
69 2
        return \count($this->list);
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75 14
    public function getIterator()
76
    {
77 14
        yield from $this->list;
78 14
    }
79
}
80