Test Failed
Pull Request — master (#37)
by Divine Niiquaye
03:19
created

ParameterTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 9
c 2
b 0
f 0
dl 0
loc 52
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A arg() 0 5 1
A getArguments() 0 3 1
A args() 0 7 2
A hasArguments() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of DivineNii opensource projects.
7
 *
8
 * PHP version 7.4 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2021 DivineNii (https://divinenii.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace Rade\DI\Definitions\Traits;
19
20
/**
21
 * This trait adds arguments functionality to the service definition.
22
 *
23
 * @author Divine Niiquaye Ibok <[email protected]>
24
 */
25
trait ParameterTrait
26
{
27
    /** @var array<int|string,mixed> */
28
    private array $arguments = [];
29
30
    /**
31
     * Sets/Replace one argument to pass to the service constructor/factory method.
32
     *
33
     * @param int|string $name
34
     * @param mixed      $value
35
     *
36
     * @return $this
37
     */
38
    public function arg($name, $value)
39
    {
40
        $this->arguments[$name] = $value;
41
42
        return $this;
43
    }
44
45
    /**
46
     * Sets the arguments to pass to the service constructor/factory method.
47
     *
48
     * @param array<int|string,mixed> $arguments
49
     *
50
     * @return $this
51
     */
52
    public function args(array $arguments)
53
    {
54
        foreach ($arguments as $name => $value) {
55
            $this->arguments[$name] = $value;
56
        }
57
58
        return $this;
59
    }
60
61
    /**
62
     * Whether this definition has constructor/factory arguments.
63
     */
64
    public function hasArguments(): bool
65
    {
66
        return !empty($this->arguments);
67
    }
68
69
    /**
70
     * Get the definition's arguments.
71
     *
72
     * @return array<int|string,mixed>
73
     */
74
    public function getArguments(): array
75
    {
76
        return $this->arguments;
77
    }
78
}
79