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 |
||
16 | class GraphControllerTest extends TestCase |
||
17 | { |
||
18 | private $friendsQuery = <<<EOF |
||
19 | query FriendsQuery { |
||
20 | user { |
||
21 | friends(first: 2) { |
||
22 | totalCount |
||
23 | edges { |
||
24 | friendshipTime |
||
25 | node { |
||
26 | name |
||
27 | } |
||
28 | } |
||
29 | } |
||
30 | } |
||
31 | } |
||
32 | EOF; |
||
33 | |||
34 | private $friendsTotalCountQuery = <<<EOF |
||
35 | query FriendsTotalCountQuery { |
||
36 | user { |
||
37 | friends { |
||
38 | totalCount |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 | EOF; |
||
43 | |||
44 | private $expectedData = [ |
||
45 | 'user' => [ |
||
46 | 'friends' => [ |
||
47 | 'totalCount' => 4, |
||
48 | 'edges' => [ |
||
49 | [ |
||
50 | 'friendshipTime' => 'Yesterday', |
||
51 | 'node' => [ |
||
52 | 'name' => 'Nick', |
||
53 | ], |
||
54 | ], |
||
55 | [ |
||
56 | 'friendshipTime' => 'Yesterday', |
||
57 | 'node' => [ |
||
58 | 'name' => 'Lee', |
||
59 | ], |
||
60 | ], |
||
61 | ], |
||
62 | ], |
||
63 | ], |
||
64 | ]; |
||
65 | |||
66 | public function testEndpointAction() |
||
74 | |||
75 | /** |
||
76 | * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException |
||
77 | * @expectedExceptionMessage Must provide query parameter |
||
78 | */ |
||
79 | public function testEndpointWithEmptyQuery() |
||
85 | |||
86 | /** |
||
87 | * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException |
||
88 | * @expectedExceptionMessage POST body sent invalid JSON |
||
89 | */ |
||
90 | public function testEndpointWithInvalidBodyQuery() |
||
96 | |||
97 | View Code Duplication | public function testEndpointActionWithVariables() |
|
121 | |||
122 | /** |
||
123 | * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException |
||
124 | * @expectedExceptionMessage Variables are invalid JSON |
||
125 | */ |
||
126 | View Code Duplication | public function testEndpointActionWithInvalidVariables() |
|
140 | |||
141 | public function testEndpointActionWithOperationName() |
||
151 | |||
152 | public function testBatchEndpointAction() |
||
176 | |||
177 | /** |
||
178 | * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException |
||
179 | * @expectedExceptionMessage Must provide at least one valid query. |
||
180 | */ |
||
181 | public function testBatchEndpointWithEmptyQuery() |
||
187 | |||
188 | /** |
||
189 | * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException |
||
190 | * @expectedExceptionMessage Only request with content type "application/json" is accepted. |
||
191 | */ |
||
192 | public function testBatchEndpointWrongContentType() |
||
198 | |||
199 | /** |
||
200 | * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException |
||
201 | * @expectedExceptionMessage POST body sent invalid JSON |
||
202 | */ |
||
203 | public function testBatchEndpointWithInvalidJson() |
||
209 | |||
210 | /** |
||
211 | * @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException |
||
212 | * @expectedExceptionMessage 1 is not a valid query |
||
213 | */ |
||
214 | public function testBatchEndpointWithInvalidQuery() |
||
220 | } |
||
221 |
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.