Completed
Push — master ( 52e4fc...6ea5e4 )
by Rasmus
03:58
created

BoolType::toInt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace mindplay\sql\types;
4
5
use InvalidArgumentException;
6
use mindplay\sql\model\Type;
7
8
class BoolType implements Type
9
{
10
    /**
11
     * @var mixed
12
     */
13
    private $true_value;
14
15
    /**
16
     * @var mixed
17
     */
18
    private $false_value;
19
20
    /**
21
     * @param mixed $true_value
22
     * @param mixed $false_value
23
     */
24 1
    public function __construct($true_value = true, $false_value = false)
25
    {
26 1
        $this->true_value = $true_value;
27 1
        $this->false_value = $false_value;
28 1
    }
29
30
    /**
31
     * @return BoolType
32
     */
33 1
    public static function toInt()
34
    {
35 1
        return new BoolType(1, 0);
36
    }
37
38
    /**
39
     * @return BoolType
40
     */
41 1
    public static function toYesNo()
42
    {
43 1
        return new BoolType("yes", "no");
44
    }
45
46 1 View Code Duplication
    public function convertToSQL($value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
    {
48 1
        if ($value === null) {
49
            return null;
50
        }
51
52 1
        if ($value === true) {
53 1
            return $this->true_value;
54
        }
55
56 1
        if ($value === false) {
57 1
            return $this->false_value;
58
        }
59
60
        throw new InvalidArgumentException("unexpected value: " . print_r($value));
61
    }
62
63 1 View Code Duplication
    public function convertToPHP($value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65 1
        if ($value === null) {
66
            return null;
67
        }
68
69 1
        if ($value === $this->true_value) {
70 1
            return true;
71
        }
72
73 1
        if ($value === $this->false_value) {
74 1
            return false;
75
        }
76
77
        throw new InvalidArgumentException("unexpected value: " . print_r($value));
78
    }
79
}
80