Passed
Pull Request — master (#683)
by Jonathan
02:21
created

BooleanStringFormatter::toBoolean()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 5
nop 2
dl 0
loc 17
ccs 11
cts 11
cp 1
crap 5
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Tools;
6
7
use function strtolower;
8
9
class BooleanStringFormatter
10
{
11 12
    public static function toBoolean(string $value, bool $default) : bool
12
    {
13 12
        switch (strtolower($value)) {
14 12
            case 'true':
15 12
                return true;
16
17 1
            case '1':
18 1
                return true;
19
20 1
            case 'false':
21 1
                return false;
22
23 1
            case '0':
24 1
                return false;
25
26
            default:
27 1
                return $default;
28
        }
29
    }
30
}
31