Lines 0.00% 0 / 5
Methods 0.00% 0 / 2
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 __construct 0.00% 0 / 1 0.00% 0 / 1 2
 tryParseBoolean 0.00% 0 / 4 0.00% 0 / 1 20
7final class BooleanSpelling
8{
9    private const array TRUE_SPELLINGS = ['true', '1', 'yes', 'on'];
10
11    private const array FALSE_SPELLINGS = ['false', '0', 'no', 'off'];
12
13    private function __construct() {}
14
15    public static function tryParseBoolean(string $raw): ?bool
16    {
17        $spelling = strtolower(trim($raw));
18
19        return match (true) {
20            \in_array($spelling, self::TRUE_SPELLINGS, true) => true,
21            \in_array($spelling, self::FALSE_SPELLINGS, true) => false,
22            default => null,
23        };
24    }
25}