Test Failed
Pull Request — master (#37)
by Divine Niiquaye
02:55
created

Tagged   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getValues() 0 3 1
A __construct() 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\Attribute;
19
20
use Rade\DI\AbstractContainer;
21
use Rade\DI\Definitions\TaggedLocator;
22
23
/**
24
 * Creates a lazy iterator by tag name.
25
 *
26
 * @author Divine Niiquaye Ibok <[email protected]>
27
 */
28
#[\Attribute(\Attribute::TARGET_PARAMETER)]
29
final class Tagged
30
{
31
    private TaggedLocator $value;
32
33
    /**
34
     * @param string            $tag                   The name of the tag identifying the target services
35
     * @param string|null       $indexAttribute        The name of the attribute that defines the key referencing each service in the tagged collection
36
     * @param bool              $needsIndexes          Whether indexes are required and should be generated when computing the map
37
     * @param array<int,string> $exclude               Services to exclude from the iterator
38
     */
39
    public function __construct(string $tag, string $indexAttribute = null, bool $needsIndexes = false, array $exclude = [])
40
    {
41
        $this->value = new TaggedLocator($tag, $indexAttribute, $needsIndexes, $exclude);
42
    }
43
44
    public function getValues(AbstractContainer $container): array
45
    {
46
        return $this->value->resolve($container);
47
    }
48
}
49