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

BoolType   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 72
Duplicated Lines 44.44 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 0
dl 32
loc 72
ccs 20
cts 24
cp 0.8333
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A toInt() 0 4 1
A toYesNo() 0 4 1
A convertToSQL() 16 16 4
A convertToPHP() 16 16 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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