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