Lines 0.00% 0 / 5
Functions and Methods 0.00% 0 / 2
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
BooleanSpelling 0.00% 0 / 5 0.00% 0 / 2 30 0.00% 0 / 1
 __construct 0.00% 0 / 1 0.00% 0 / 1 2
 tryParseBoolean 0.00% 0 / 4 0.00% 0 / 1 20
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Config;
6
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}