Passed
Pull Request — master (#739)
by Michael
02:38
created

BooleanStringFormatter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A toBoolean() 0 17 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Tools;
6
7
use function strtolower;
8
9
/**
10
 * The BooleanStringFormatter class is responsible for formatting a string boolean representation to a PHP boolean value.
11
 * It is used in the XmlConfiguration class to convert the string XML boolean value to a PHP boolean value.
12
 *
13
 * @see Doctrine\Migrations\Configuration\XmlConfiguration
14
 *
15
 * @internal
16
 */
17
class BooleanStringFormatter
18
{
19 12
    public static function toBoolean(string $value, bool $default) : bool
20
    {
21 12
        switch (strtolower($value)) {
22 12
            case 'true':
23 12
                return true;
24
25 1
            case '1':
26 1
                return true;
27
28 1
            case 'false':
29 1
                return false;
30
31 1
            case '0':
32 1
                return false;
33
34
            default:
35 1
                return $default;
36
        }
37
    }
38
}
39