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 |
||
7 | class QueryMaxDepthTest extends TestCase |
||
8 | { |
||
9 | private $userFriendsWithoutViolationQuery = <<<'EOF' |
||
10 | query { |
||
11 | user { |
||
12 | friends(first:1) { |
||
13 | edges { |
||
14 | node { |
||
15 | name |
||
16 | } |
||
17 | } |
||
18 | } |
||
19 | } |
||
20 | } |
||
21 | EOF; |
||
22 | |||
23 | private $userFriendsWithViolationQuery = <<<'EOF' |
||
24 | query { |
||
25 | user { |
||
26 | friends(first: 1) { |
||
27 | edges { |
||
28 | node { |
||
29 | name |
||
30 | friends { |
||
31 | edges { |
||
32 | node { |
||
33 | name |
||
34 | } |
||
35 | } |
||
36 | } |
||
37 | } |
||
38 | } |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 | EOF; |
||
43 | |||
44 | public function testMaxDepthReachLimitation() |
||
45 | { |
||
46 | $expected = [ |
||
47 | 'errors' => [ |
||
48 | [ |
||
49 | 'message' => 'Max query depth should be 3 but got 6.', |
||
50 | 'category' => 'graphql', |
||
51 | ], |
||
52 | ], |
||
53 | ]; |
||
54 | |||
55 | $this->assertResponse($this->userFriendsWithViolationQuery, $expected, self::ANONYMOUS_USER, 'queryMaxDepth'); |
||
56 | } |
||
57 | |||
58 | public function testMaxDepthReachLimitationEnv() |
||
59 | { |
||
60 | $expected = [ |
||
61 | 'errors' => [ |
||
62 | [ |
||
63 | 'message' => 'Max query depth should be 3 but got 6.', |
||
64 | 'category' => 'graphql', |
||
65 | ], |
||
66 | ], |
||
67 | ]; |
||
68 | |||
69 | $this->assertResponse($this->userFriendsWithViolationQuery, $expected, self::ANONYMOUS_USER, 'queryMaxDepthEnv'); |
||
70 | } |
||
71 | |||
72 | public function testComplexityUnderLimitation() |
||
73 | { |
||
74 | $expected = [ |
||
75 | 'data' => [ |
||
76 | 'user' => [ |
||
77 | 'friends' => [ |
||
78 | 'edges' => [ |
||
79 | ['node' => ['name' => 'Nick']], |
||
80 | ], |
||
81 | ], |
||
82 | ], |
||
83 | ], |
||
84 | ]; |
||
85 | |||
86 | $this->assertResponse($this->userFriendsWithoutViolationQuery, $expected, self::ANONYMOUS_USER, 'queryMaxDepth'); |
||
87 | } |
||
88 | } |
||
89 |