Test Failed
Push — master ( dbe410...b8c007 )
by Kirill
02:19
created

HasArguments::getArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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\Definition\Behaviour;
11
12
use Railt\Reflection\Contracts\Definition\Behaviour\ProvidesArguments;
13
use Railt\Reflection\Definition\Dependent\ArgumentDefinition;
14
use Railt\Reflection\Contracts\Definition\Dependent\ArgumentDefinition as ArgumentDefinitionInterface;
15
use Railt\Reflection\Common\Verifiable;
16
17
/**
18
 * Trait HasArguments
19
 * @mixin ProvidesArguments
20
 */
21
trait HasArguments
22
{
23
    /**
24
     * @var array|ArgumentDefinition[]
25
     */
26
    protected $arguments = [];
27
28
    /**
29
     * @return iterable|ArgumentDefinition[]
30
     */
31
    public function getArguments(): iterable
32
    {
33
        return \array_values($this->arguments);
34
    }
35
36
    /**
37
     * @param string $name
38
     * @return bool
39
     */
40
    public function hasArgument(string $name): bool
41
    {
42
        return isset($this->arguments[$name]);
43
    }
44
45
    /**
46
     * @param string $name
47
     * @return null|ArgumentDefinitionInterface
48
     */
49
    public function getArgument(string $name): ?ArgumentDefinitionInterface
50
    {
51
        return $this->arguments[$name] ?? null;
52
    }
53
54
    /**
55
     * @param ArgumentDefinitionInterface ...$arguments
56
     * @return ProvidesArguments|$this
57
     */
58 9
    public function withArgument(ArgumentDefinitionInterface ...$arguments): ProvidesArguments
59
    {
60 9
        foreach ($arguments as $argument) {
61 9
            if ($argument instanceof Verifiable) {
62 9
                $argument->verify();
63
            }
64
65 9
            $this->arguments[$argument->getName()] = $argument;
66
        }
67
68 9
        return $this;
69
    }
70
}
71