Completed
Push — master ( f707f5...a08928 )
by Rasmus
02:27
created

BoolType   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 75
Duplicated Lines 42.67 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 83.33%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A asInt() 0 4 1
A asEnum() 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\model\types;
4
5
use InvalidArgumentException;
6
use mindplay\sql\model\schema\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 asInt()
34
    {
35 1
        return new BoolType(1, 0);
36
    }
37
38
    /**
39
     * @param string $true_value
40
     * @param string $false_value
41
     *
42
     * @return BoolType
43
     */
44 1
    public static function asEnum($true_value, $false_value)
45
    {
46 1
        return new BoolType($true_value, $false_value);
47
    }
48
49 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...
50
    {
51 1
        if ($value === null) {
52
            return null;
53
        }
54
55 1
        if ($value === true) {
56 1
            return $this->true_value;
57
        }
58
59 1
        if ($value === false) {
60 1
            return $this->false_value;
61
        }
62
63
        throw new InvalidArgumentException("unexpected value: " . print_r($value));
64
    }
65
66 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...
67
    {
68 1
        if ($value === null) {
69
            return null;
70
        }
71
72 1
        if ($value === $this->true_value) {
73 1
            return true;
74
        }
75
76 1
        if ($value === $this->false_value) {
77 1
            return false;
78
        }
79
80
        throw new InvalidArgumentException("unexpected value: " . print_r($value));
81
    }
82
}
83