Test Failed
Push — master ( 2ca085...e04cac )
by Kirill
03:23
created

HasArguments::getIterator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 10
cc 2
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\Reflection\Invocation\Behaviour;
11
12
use Railt\Reflection\Contracts\Invocation\Behaviour\ProvidesArguments;
13
14
/**
15
 * Trait HasArguments
16
 */
17
trait HasArguments
18
{
19
    /**
20
     * @var array
21
     */
22
    protected $arguments = [];
23
24
    /**
25
     * @return \Traversable
26
     */
27
    public function getIterator(): \Traversable
28
    {
29
        foreach ($this->arguments as $name => $value) {
30
            yield $name => $value;
31
        }
32
    }
33
34
    /**
35
     * @param string|int $offset
36
     * @return bool
37
     */
38
    public function offsetExists($offset): bool
39
    {
40
        return $this->hasArgument($offset);
41
    }
42
43
    /**
44
     * @param string|int $name
45
     * @return bool
46
     */
47
    public function hasArgument($name): bool
48
    {
49
        return isset($this->arguments[$name]) && \array_key_exists($name, $this->arguments);
50
    }
51
52
    /**
53
     * @param mixed $offset
54
     * @return mixed|null
55
     */
56
    public function offsetGet($offset)
57
    {
58
        return $this->getArgument($offset);
59
    }
60
61
    /**
62
     * @param string|int $name
63
     * @return mixed|null
64
     */
65
    public function getArgument($name)
66
    {
67
        return $this->arguments[$name] ?? null;
68
    }
69
70
    /**
71
     * @param string|int $offset
72
     * @param mixed $value
73
     */
74
    public function offsetSet($offset, $value): void
75
    {
76
        $this->withArgument($offset, $value);
77
    }
78
79
    /**
80
     * @param string|int $name
81
     * @param mixed $value
82
     * @return ProvidesArguments
83
     */
84
    public function withArgument($name, $value): ProvidesArguments
85
    {
86
        $this->arguments[$name] = $value;
87
88
        return $this;
89
    }
90
91
    /**
92
     * @param string|int $offset
93
     */
94
    public function offsetUnset($offset): void
95
    {
96
        unset($this->arguments[$offset]);
97
    }
98
99
    /**
100
     * @return iterable
101
     */
102
    public function getArguments(): iterable
103
    {
104
        return $this->arguments;
105
    }
106
}
107