Passed
Push — master ( 0e87cd...c4ac3e )
by Carlos C
12:45 queued 01:03
created

BoolDataField   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 26
ccs 9
cts 9
cp 1
rs 10
wmc 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\SatCatalogosPopulate\Database;
6
7
class BoolDataField extends AbstractDataField implements DataFieldInterface
8
{
9
    /**
10
     * @param string[] $trueValues
11
     * @param string[] $falseValues
12
     */
13 144
    public function __construct(
14
        string $name,
15
        private readonly array $trueValues = [],
16
        private readonly array $falseValues = [],
17
        private readonly bool $default = false
18
    ) {
19 144
        parent::__construct($name, $this->valueToBoolean(...));
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected ')' on line 19 at column 60
Loading history...
20
    }
21
22
    /** @param scalar $input */
23 122
    protected function valueToBoolean($input): bool
24
    {
25 122
        $input = trim((string) $input);
26 122
        if (in_array($input, $this->trueValues, true)) {
27 20
            return true;
28
        }
29 122
        if (in_array($input, $this->falseValues, true)) {
30 16
            return false;
31
        }
32 122
        return $this->default;
33
    }
34
}
35