TagReference   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 24
ccs 10
cts 10
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isTagAlias() 0 3 1
A to() 0 3 1
A extractTagFromAlias() 0 6 2
A __construct() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Di\Reference;
6
7
use Yiisoft\Definitions\Reference;
8
9
/**
10
 * TagReference is a helper class used to specify a reference to a tag.
11
 * For example, `TagReference::to('my-tag')` specifies a reference to all services that are tagged with `tag@my-tag`.
12
 */
13
final class TagReference
14
{
15
    private const PREFIX = 'tag@';
16
17 1
    private function __construct()
18
    {
19 1
    }
20
21 1
    public static function to(string $tag): Reference
22
    {
23 1
        return Reference::to(self::PREFIX . $tag);
24
    }
25
26 13
    public static function extractTagFromAlias(string $alias): string
27
    {
28 13
        if (!str_starts_with($alias, self::PREFIX)) {
29 2
            throw new \InvalidArgumentException(sprintf('Alias "%s" is not a tag alias.', $alias));
30
        }
31 11
        return substr($alias, 4);
32
    }
33
34 132
    public static function isTagAlias(string $id): bool
35
    {
36 132
        return str_starts_with($id, self::PREFIX);
37
    }
38
}
39