TagHelper::toTag()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

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
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
7
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
8
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
9
 *
10
 * Copyright (c) 2024 Mykhailo Shtanko [email protected]
11
 *
12
 * For the full copyright and license information, please view the LICENSE.MD
13
 * file that was distributed with this source code.
14
 */
15
16
namespace FRZB\Component\DependencyInjection\Helper;
17
18
use Fp\Collections\ArrayList;
19
use FRZB\Component\DependencyInjection\Attribute\AsTagged;
20
use JetBrains\PhpStorm\Immutable;
21
22
/** @internal */
23
#[Immutable]
24
final class TagHelper
25
{
26
    private function __construct() {}
27
28
    public static function toTagRepresentation(AsTagged $tag): array
29
    {
30
        return [$tag->{$tag::getNameProperty()} => [PropertyHelper::mapProperties($tag, [$tag::getNameProperty()])]];
31
    }
32
33
    public static function toTag(AsTagged $tag): array
34
    {
35
        return PropertyHelper::mapProperties($tag, [$tag::getNameProperty()]);
36
    }
37
38
    public static function mapTags(AsTagged ...$tags): array
39
    {
40
        return ArrayList::collect($tags)
41
            ->map(self::toTagRepresentation(...))
42
            ->toMergedArray()
43
        ;
44
    }
45
}
46