Test Failed
Push — master ( 97fe68...3f86cd )
by Kirill
42s
created

HasArguments::withoutArgument()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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