We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
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 |
||
24 | class ConnectionBuilderTest extends \PHPUnit_Framework_TestCase |
||
25 | { |
||
26 | private $letters = ['A', 'B', 'C', 'D', 'E']; |
||
27 | |||
28 | View Code Duplication | public function testBasicSlicing() |
|
|
|||
29 | { |
||
30 | $actual = ConnectionBuilder::connectionFromArray($this->letters); |
||
31 | |||
32 | $expected = $this->getExpectedConnection($this->letters, false, false); |
||
33 | |||
34 | $this->assertEquals($expected, $actual); |
||
35 | } |
||
36 | |||
37 | public function testRespectsASmallerFirst() |
||
38 | { |
||
39 | $actual = ConnectionBuilder::connectionFromArray($this->letters, ['first' => 2]); |
||
40 | |||
41 | $expected = $this->getExpectedConnection(['A', 'B'], false, true); |
||
42 | |||
43 | $this->assertEquals($expected, $actual); |
||
44 | } |
||
45 | |||
46 | View Code Duplication | public function testRespectsAnOverlyLargeFirst() |
|
47 | { |
||
48 | $actual = ConnectionBuilder::connectionFromArray($this->letters, ['first' => 10]); |
||
49 | |||
50 | $expected = $this->getExpectedConnection($this->letters, false, false); |
||
51 | |||
52 | $this->assertEquals($expected, $actual); |
||
53 | } |
||
54 | |||
55 | public function testRespectsASmallerLast() |
||
56 | { |
||
57 | $actual = ConnectionBuilder::connectionFromArray($this->letters, ['last' => 2]); |
||
58 | |||
59 | $expected = $this->getExpectedConnection(['D', 'E'], true, false); |
||
60 | |||
61 | $this->assertEquals($expected, $actual); |
||
62 | } |
||
63 | |||
64 | View Code Duplication | public function testRespectsAnOverlyLargeLast() |
|
65 | { |
||
66 | $actual = ConnectionBuilder::connectionFromArray($this->letters, ['last' => 10]); |
||
67 | |||
68 | $expected = $this->getExpectedConnection($this->letters, false, false); |
||
69 | |||
70 | $this->assertEquals($expected, $actual); |
||
71 | } |
||
72 | |||
73 | public function testRespectsFirstAndAfter() |
||
74 | { |
||
75 | $actual = ConnectionBuilder::connectionFromArray($this->letters, ['first' => 2, 'after' => 'YXJyYXljb25uZWN0aW9uOjE=']); |
||
76 | |||
77 | $expected = $this->getExpectedConnection(['C', 'D'], false, true); |
||
78 | |||
79 | $this->assertEquals($expected, $actual); |
||
80 | } |
||
81 | |||
82 | View Code Duplication | public function testRespectsFirstAndAfterWithLongFirst() |
|
83 | { |
||
84 | $actual = ConnectionBuilder::connectionFromArray($this->letters, ['first' => 10, 'after' => 'YXJyYXljb25uZWN0aW9uOjE=']); |
||
85 | |||
86 | $expected = $this->getExpectedConnection(['C', 'D', 'E'], false, false); |
||
87 | |||
88 | $this->assertEquals($expected, $actual); |
||
89 | } |
||
90 | |||
91 | public function testRespectsLastAndBefore() |
||
99 | |||
100 | View Code Duplication | public function testRespectsLastAndBeforeWithLongLast() |
|
101 | { |
||
102 | $actual = ConnectionBuilder::connectionFromArray($this->letters, ['last' => 10, 'before' => 'YXJyYXljb25uZWN0aW9uOjM=']); |
||
103 | |||
104 | $expected = $this->getExpectedConnection(['A', 'B', 'C'], false, false); |
||
105 | |||
106 | $this->assertEquals($expected, $actual); |
||
107 | } |
||
108 | |||
109 | View Code Duplication | public function testRespectsFirstAndAfterAndBeforeTooFew() |
|
110 | { |
||
111 | $actual = ConnectionBuilder::connectionFromArray( |
||
112 | $this->letters, |
||
113 | ['first' => 2, 'after' => 'YXJyYXljb25uZWN0aW9uOjA=', 'before' => 'YXJyYXljb25uZWN0aW9uOjQ='] |
||
114 | ); |
||
115 | |||
116 | $expected = $this->getExpectedConnection(['B', 'C'], false, true); |
||
117 | |||
118 | $this->assertEquals($expected, $actual); |
||
119 | } |
||
120 | |||
121 | View Code Duplication | public function testRespectsFirstAndAfterAndBeforeTooMany() |
|
122 | { |
||
123 | $actual = ConnectionBuilder::connectionFromArray( |
||
124 | $this->letters, |
||
125 | ['first' => 4, 'after' => 'YXJyYXljb25uZWN0aW9uOjA=', 'before' => 'YXJyYXljb25uZWN0aW9uOjQ='] |
||
126 | ); |
||
127 | |||
128 | $expected = $this->getExpectedConnection(['B', 'C', 'D'], false, false); |
||
129 | |||
130 | $this->assertEquals($expected, $actual); |
||
131 | } |
||
132 | |||
133 | View Code Duplication | public function testRespectsFirstAndAfterAndBeforeExactlyRight() |
|
134 | { |
||
135 | $actual = ConnectionBuilder::connectionFromArray( |
||
136 | $this->letters, |
||
137 | ['first' => 3, 'after' => 'YXJyYXljb25uZWN0aW9uOjA=', 'before' => 'YXJyYXljb25uZWN0aW9uOjQ='] |
||
138 | ); |
||
139 | |||
140 | $expected = $this->getExpectedConnection(['B', 'C', 'D'], false, false); |
||
141 | |||
142 | $this->assertEquals($expected, $actual); |
||
143 | } |
||
144 | |||
145 | View Code Duplication | public function testRespectsLastAndAfterAndBeforeTooFew() |
|
146 | { |
||
147 | $actual = ConnectionBuilder::connectionFromArray( |
||
148 | $this->letters, |
||
149 | ['last' => 2, 'after' => 'YXJyYXljb25uZWN0aW9uOjA=', 'before' => 'YXJyYXljb25uZWN0aW9uOjQ='] |
||
150 | ); |
||
151 | |||
152 | $expected = $this->getExpectedConnection(['C', 'D'], true, false); |
||
153 | |||
154 | $this->assertEquals($expected, $actual); |
||
155 | } |
||
156 | |||
157 | View Code Duplication | public function testRespectsLastAndAfterAndBeforeTooMany() |
|
158 | { |
||
159 | $actual = ConnectionBuilder::connectionFromArray( |
||
160 | $this->letters, |
||
161 | ['last' => 4, 'after' => 'YXJyYXljb25uZWN0aW9uOjA=', 'before' => 'YXJyYXljb25uZWN0aW9uOjQ='] |
||
162 | ); |
||
163 | |||
164 | $expected = $this->getExpectedConnection(['B', 'C', 'D'], false, false); |
||
165 | |||
166 | $this->assertEquals($expected, $actual); |
||
167 | } |
||
168 | |||
169 | View Code Duplication | public function testRespectsLastAndAfterAndBeforeExactlyRight() |
|
180 | |||
181 | /** |
||
182 | * @expectedException \InvalidArgumentException |
||
183 | * @expectedExceptionMessage Argument "first" must be a non-negative integer |
||
184 | */ |
||
185 | public function testThrowsAnErrorIfFirstLessThan0() |
||
186 | { |
||
187 | ConnectionBuilder::connectionFromArray( |
||
188 | $this->letters, |
||
189 | ['first' => -1] |
||
190 | ); |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * @expectedException \InvalidArgumentException |
||
195 | * @expectedExceptionMessage Argument "last" must be a non-negative integer |
||
196 | */ |
||
197 | public function testThrowsAnErrorIfLastLessThan0() |
||
204 | |||
205 | public function testReturnsNoElementsIfFirstIs0() |
||
220 | |||
221 | public function testReturnsAllElementsIfCursorsAreInvalid() |
||
232 | |||
233 | public function testReturnsAllElementsIfCursorsAreOnTheOutside() |
||
244 | |||
245 | public function testReturnsNoElementsIfCursorsCross() |
||
256 | |||
257 | public function testReturnsAnEdgesCursorGivenAnArrayAndAMemberObject() |
||
263 | |||
264 | public function testReturnsAnEdgesCursorGivenAnArrayAndANonMemberObject() |
||
270 | |||
271 | private function getExpectedConnection(array $wantedEdges, $hasPreviousPage, $hasNextPage) |
||
293 | } |
||
294 |
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.