Completed
Push — 2.x ( 8f6930...447f85 )
by Akihito
01:14
created

Inject::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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