Inject::isOptional()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
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
 * @psalm-immutable
17
 */
18
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER)]
19
final class Inject implements InjectInterface
20
{
21
    /**
22
     * If true, and the appropriate binding is not found, the Injector will skip injection of this method or field rather than produce an error.
23
     *
24
     * @var bool
25
     */
26
    public $optional;
27
28
    /**
29
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag) // @phpstan-ignore-line
30
     */
31
    public function __construct(bool $optional = false)
32
    {
33
        $this->optional = $optional;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function isOptional(): bool
40
    {
41
        return $this->optional;
42
    }
43
}
44