Booleans::normalize()   B
last analyzed

Complexity

Conditions 7
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 7

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 12
c 0
b 0
f 0
ccs 8
cts 8
cp 1
rs 8.8333
cc 7
nc 4
nop 2
crap 7
1
<?php
2
3
namespace kalanis\Pohoda\Common\OptionsResolver\Normalizers;
4
5
final class Booleans extends AbstractNormalizer
6
{
7 51
    public function normalize(mixed $options, mixed $value): string
8
    {
9 51
        if ($this->nullable && empty($value) && !\is_bool($value)) {
10 2
            return '';
11
        }
12 51
        if (\is_bool($value)) {
13 35
            return $this->whichResult($value);
14
        }
15 18
        if (\is_string($value)) {
16 17
            return $this->whichResult(!empty($value) && 'false' !== \strtolower($value));
17
        }
18 1
        return $this->whichResult(!empty($value));
19
    }
20
21 51
    protected function whichResult(bool $value): string
22
    {
23 51
        return $value ? 'true' : 'false';
24
    }
25
}
26