TagReference::isTagAlias()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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