StubAttributeFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 32
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A createAttributes() 0 18 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\TestDouble\Html\Component;
6
7
use AbterPhp\Framework\Html\Attribute;
8
use AbterPhp\Framework\Html\Helper\Attributes;
9
10
class StubAttributeFactory
11
{
12
    public const ATTRIBUTE_FOO = 'foo';
13
    public const ATTRIBUTE_BAR = 'bar';
14
15
    public const VALUE_FOO     = 'foo';
16
    public const VALUE_BAZ     = 'baz';
17
    public const VALUE_BAR_BAZ = 'bar baz';
18
19
    /**
20
     * @param array<string,string[]> $extraAttributes
21
     *
22
     * @return array<string,Attribute>
23
     */
24
    public static function createAttributes(array $extraAttributes = []): array
25
    {
26
        $attributes = [
27
            static::ATTRIBUTE_FOO => [static::VALUE_FOO, static::VALUE_BAZ],
28
            static::ATTRIBUTE_BAR => [static::VALUE_BAR_BAZ],
29
        ];
30
31
        foreach ($extraAttributes as $k => $v) {
32
            if (!array_key_exists($k, $attributes)) {
33
                $attributes[$k] = $v;
34
                continue;
35
            }
36
            foreach ($v as $v2) {
37
                $attributes[$k][] = $v2;
38
            }
39
        }
40
41
        return Attributes::fromArray($attributes);
42
    }
43
}
44