WhereTokenCollectionUnitTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 159
Duplicated Lines 59.12 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 94
loc 159
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A toString_WithOneLevelAndFiltering() 15 15 1
A toString_WithOneLevelOrFiltering() 15 15 1
A toString_WithTwoLevelAndFiltering() 15 15 1
A toString_WithTwoLevelOrFiltering() 15 15 1
A toString_WithTwoLevelAndNestedNull() 15 15 1
A getBindingsList_WithOneLevel() 19 19 1
A getBindingsList_WithTwoLevel() 0 21 1

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 Hgraca\MicroDbal\Test\Crud\QueryBuilder\Sql;
4
5
use Hgraca\MicroDbal\Crud\QueryBuilder\Sql\WhereToken;
6
use Hgraca\MicroDbal\Crud\QueryBuilder\Sql\WhereTokenCollection;
7
use PHPUnit_Framework_TestCase;
8
9
final class WhereTokenCollectionUnitTest extends PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * @test
13
     *
14
     * @small
15
     */
16 View Code Duplication
    public function toString_WithOneLevelAndFiltering()
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...
17
    {
18
        $whereToken = [
19
            'id' => 1,
20
            'dummy_column_1' => 'some text',
21
            'dummy_column_2' => null,
22
        ];
23
24
        $whereTokenCollection = new WhereTokenCollection($whereToken);
25
26
        self::assertEquals(
27
            '`id`=' . WhereToken::BINDING_PREFIX . '0 AND `dummy_column_1`=' . WhereToken::BINDING_PREFIX . '1 AND `dummy_column_2` IS ' . WhereToken::BINDING_PREFIX . '2',
28
            $whereTokenCollection->toString()
29
        );
30
    }
31
32
    /**
33
     * @test
34
     *
35
     * @small
36
     */
37 View Code Duplication
    public function toString_WithOneLevelOrFiltering()
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...
38
    {
39
        $whereToken = [
40
            'id' => 1,
41
            'dummy_column_1' => 'some text',
42
            'dummy_column_2' => null,
43
        ];
44
45
        $whereTokenCollection = new WhereTokenCollection($whereToken, WhereTokenCollection::OPERATION_OR);
46
47
        self::assertEquals(
48
            '`id`=' . WhereToken::BINDING_PREFIX . '0 OR `dummy_column_1`=' . WhereToken::BINDING_PREFIX . '1 OR `dummy_column_2` IS ' . WhereToken::BINDING_PREFIX . '2',
49
            $whereTokenCollection->toString()
50
        );
51
    }
52
53
    /**
54
     * @test
55
     *
56
     * @small
57
     */
58 View Code Duplication
    public function toString_WithTwoLevelAndFiltering()
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...
59
    {
60
        $whereToken = [
61
            'id' => [1, 2, 3],
62
            'dummy_column_1' => 'some text',
63
            'dummy_column_2' => null,
64
        ];
65
66
        $whereTokenCollection = new WhereTokenCollection($whereToken);
67
68
        self::assertEquals(
69
            '(`id`=' . WhereToken::BINDING_PREFIX . '0 OR `id`=' . WhereToken::BINDING_PREFIX . '1 OR `id`=' . WhereToken::BINDING_PREFIX . '2) AND `dummy_column_1`=' . WhereToken::BINDING_PREFIX . '3 AND `dummy_column_2` IS ' . WhereToken::BINDING_PREFIX . '4',
70
            $whereTokenCollection->toString()
71
        );
72
    }
73
74
    /**
75
     * @test
76
     *
77
     * @small
78
     */
79 View Code Duplication
    public function toString_WithTwoLevelOrFiltering()
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...
80
    {
81
        $whereToken = [
82
            'id' => [1, 2, 3],
83
            'dummy_column_1' => 'some text',
84
            'dummy_column_2' => null,
85
        ];
86
87
        $whereTokenCollection = new WhereTokenCollection($whereToken, WhereTokenCollection::OPERATION_OR);
88
89
        self::assertEquals(
90
            '(`id`=' . WhereToken::BINDING_PREFIX . '0 AND `id`=' . WhereToken::BINDING_PREFIX . '1 AND `id`=' . WhereToken::BINDING_PREFIX . '2) OR `dummy_column_1`=' . WhereToken::BINDING_PREFIX . '3 OR `dummy_column_2` IS ' . WhereToken::BINDING_PREFIX . '4',
91
            $whereTokenCollection->toString()
92
        );
93
    }
94
95
    /**
96
     * @test
97
     *
98
     * @small
99
     */
100 View Code Duplication
    public function toString_WithTwoLevelAndNestedNull()
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...
101
    {
102
        $whereToken = [
103
            'id' => [1, null, 3],
104
            'dummy_column_1' => 'some text',
105
            'dummy_column_2' => null,
106
        ];
107
108
        $whereTokenCollection = new WhereTokenCollection($whereToken);
109
110
        self::assertEquals(
111
            '(`id`=' . WhereToken::BINDING_PREFIX . '0 OR `id` IS ' . WhereToken::BINDING_PREFIX . '1 OR `id`=' . WhereToken::BINDING_PREFIX . '2) AND `dummy_column_1`=' . WhereToken::BINDING_PREFIX . '3 AND `dummy_column_2` IS ' . WhereToken::BINDING_PREFIX . '4',
112
            $whereTokenCollection->toString()
113
        );
114
    }
115
116
    /**
117
     * @test
118
     *
119
     * @small
120
     */
121 View Code Duplication
    public function getBindingsList_WithOneLevel()
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...
122
    {
123
        $whereToken = [
124
            'id' => 1,
125
            'dummy_column_1' => 'some text',
126
            'dummy_column_2' => null,
127
        ];
128
129
        $whereTokenCollection = new WhereTokenCollection($whereToken);
130
131
        self::assertEquals(
132
            [
133
                ':w0' => 1,
134
                ':w1' => 'some text',
135
                ':w2' => null,
136
            ],
137
            $whereTokenCollection->getBindingsList()
138
        );
139
    }
140
141
    /**
142
     * @test
143
     *
144
     * @small
145
     */
146
    public function getBindingsList_WithTwoLevel()
147
    {
148
        $whereToken = [
149
            'id' => [1, 2, 3],
150
            'dummy_column_1' => 'some text',
151
            'dummy_column_2' => null,
152
        ];
153
154
        $whereTokenCollection = new WhereTokenCollection($whereToken);
155
156
        self::assertEquals(
157
            [
158
                ':w0' => 1,
159
                ':w1' => 2,
160
                ':w2' => 3,
161
                ':w3' => 'some text',
162
                ':w4' => null,
163
            ],
164
            $whereTokenCollection->getBindingsList()
165
        );
166
    }
167
}
168