Inject   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isOptional() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di\Di;
6
7
use Attribute;
8
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
9
10
/**
11
 * Annotates your class methods into which the Injector should inject values
12
 *
13
 * @Annotation
14
 * @Target("METHOD")
15
 * @NamedArgumentConstructor
16
 */
17
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER)]
18
final class Inject implements InjectInterface
19
{
20
    /**
21
     * If true, and the appropriate binding is not found, the Injector will skip injection of this method or field rather than produce an error.
22
     *
23
     * @var bool
24
     */
25
    public $optional = false;
26
27
    /**
28
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
29
     */
30
    public function __construct(bool $optional = false)
31
    {
32
        $this->optional = $optional;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function isOptional(): bool
39
    {
40
        return $this->optional;
41
    }
42
}
43