Completed
Push — demo ( a8654a...497fd3 )
by Akihito
02:16 queued 17s
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 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\Di\Di;
6
7
use Attribute;
8
9
/**
10
 * Annotates your class methods into which the Injector should inject values
11
 *
12
 * @Annotation
13
 * @Target("METHOD")
14
 */
15
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_PARAMETER)]
16
final class Inject implements InjectInterface
17
{
18
    /**
19
     * If true, and the appropriate binding is not found, the Injector will skip injection of this method or field rather than produce an error.
20
     *
21
     * @var bool
22
     */
23
    public $optional = false;
24
25
    /**
26
     * @param array{optional?: bool} $values
27
     */
28
    public function __construct(array $values = [], bool $optional = false)
29
    {
30
        $this->optional = $values['optional'] ?? $optional;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function isOptional(): bool
37
    {
38
        return $this->optional;
39
    }
40
}
41