BooleanStringFormatter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A toBoolean() 0 15 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
 * @internal
14
 *
15
 * @see Doctrine\Migrations\Configuration\XmlConfiguration
16
 */
17
class BooleanStringFormatter
18
{
19 3
    public static function toBoolean(string $value, bool $default) : bool
20
    {
21 3
        switch (strtolower($value)) {
22 3
            case 'true':
23 3
                return true;
24 1
            case '1':
25 1
                return true;
26 1
            case 'false':
27 1
                return false;
28 1
            case '0':
29 1
                return false;
30
            default:
31 1
                return $default;
32
        }
33
    }
34
}
35