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

BoolDataField::valueToBoolean()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 6
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 10
ccs 7
cts 7
cp 1
crap 3
rs 10
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