FillHandler   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
eloc 18
c 1
b 0
f 0
dl 0
loc 49
ccs 18
cts 18
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 25 9
A getValue() 0 3 1
A getLabel() 0 3 1
A getAttributes() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Enjoys\Forms;
6
7
class FillHandler
8
{
9
    private array $attributes = [];
10
11
    private mixed $value = null;
12
    private ?string $label = null;
13
14
15 75
    public function __construct(mixed $value, mixed $label, bool $useTitleAsValue = false)
16
    {
17 75
        if (is_array($label)) {
18 32
            $this->label = (string)($label[0] ?? null);
19
20 32
            if (isset($label[1]) && is_array($label[1])) {
21 31
                $this->attributes = $label[1];
22
            }
23
        }
24
25 75
        $this->label ??= (string)$label;
26
27
        /** @since 2.4.0 */
28 75
        if (is_string($value)) {
29 31
            $this->value = \trim($value);
30
        }
31
32
        /** @since 2.4.0 */
33 75
        if (is_int($value) && $useTitleAsValue) {
34 28
            $this->value = $this->label;
35
        }
36
37
        /** @since 3.4.0 */
38 75
        if (is_int($value) && !$useTitleAsValue) {
39 17
            $this->value = $value;
40
        }
41
    }
42
43 75
    public function getAttributes(): array
44
    {
45 75
        return $this->attributes;
46
    }
47
48 75
    public function getValue(): ?string
49
    {
50 75
        return (string)$this->value;
51
    }
52
53 75
    public function getLabel(): ?string
54
    {
55 75
        return $this->label;
56
    }
57
}
58