| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 83 | public function testCustomTypes() |
||
| 84 | { |
||
| 85 | $authorType = null; |
||
| 86 | |||
| 87 | $userInterface = new ObjectType([ |
||
| 88 | 'name' => 'UserInterface', |
||
| 89 | 'fields' => [ |
||
| 90 | 'name' => new StringType(), |
||
| 91 | ], |
||
| 92 | 'resolveType' => function () use ($authorType) { |
||
| 93 | return $authorType; |
||
| 94 | } |
||
| 95 | ]); |
||
| 96 | |||
| 97 | $authorType = new ObjectType([ |
||
| 98 | 'name' => 'Author', |
||
| 99 | 'fields' => [ |
||
| 100 | 'name' => new StringType(), |
||
| 101 | ], |
||
| 102 | 'interfaces' => [$userInterface] |
||
| 103 | ]); |
||
| 104 | |||
| 105 | $schema = new Schema([ |
||
| 106 | 'query' => new ObjectType([ |
||
| 107 | 'name' => 'QueryType', |
||
| 108 | 'fields' => [ |
||
| 109 | 'user' => [ |
||
| 110 | 'type' => $userInterface, |
||
| 111 | 'resolve' => function () { |
||
| 112 | return [ |
||
| 113 | 'name' => 'Alex' |
||
| 114 | ]; |
||
| 115 | } |
||
| 116 | ] |
||
| 117 | ] |
||
| 118 | ]) |
||
| 119 | ]); |
||
| 120 | $schema->getTypesList()->addType($authorType); |
||
| 121 | $processor = new Processor($schema); |
||
| 122 | $processor->processPayload('{ user { name } }'); |
||
| 123 | $this->assertEquals(['data' => ['user' => ['name' => 'Alex']]], $processor->getResponseData()); |
||
| 124 | |||
| 125 | $processor->processPayload('{ |
||
| 126 | __schema { |
||
| 127 | types { |
||
| 128 | name |
||
| 129 | } |
||
| 130 | } |
||
| 131 | }'); |
||
| 132 | $data = $processor->getResponseData(); |
||
| 133 | $this->assertArraySubset([11 => ['name' => 'Author']], $data['data']['__schema']['types']); |
||
| 134 | } |
||
| 135 | |||
| 137 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.