| Conditions | 1 |
| Paths | 1 |
| Total Lines | 68 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 93 | public function queries() |
||
| 94 | { |
||
| 95 | return [ |
||
| 96 | [ |
||
| 97 | '{ nonNullScalar }', |
||
| 98 | [ |
||
| 99 | 'data' => [ |
||
| 100 | 'nonNullScalar' => null |
||
| 101 | ], |
||
| 102 | 'errors' => [ |
||
| 103 | [ |
||
| 104 | 'message' => 'Cannot return null for non-nullable field "nonNullScalar"' |
||
| 105 | ] |
||
| 106 | ] |
||
| 107 | ] |
||
| 108 | ], |
||
| 109 | |||
| 110 | [ |
||
| 111 | '{ nonNullList }', |
||
| 112 | [ |
||
| 113 | 'data' => [ |
||
| 114 | 'nonNullList' => null |
||
| 115 | ], |
||
| 116 | 'errors' => [ |
||
| 117 | [ |
||
| 118 | 'message' => 'Cannot return null for non-nullable field "nonNullList"' |
||
| 119 | ] |
||
| 120 | ] |
||
| 121 | ] |
||
| 122 | ], |
||
| 123 | |||
| 124 | [ |
||
| 125 | '{ nonNullListOfNpnNull }', |
||
| 126 | [ |
||
| 127 | 'data' => [ |
||
| 128 | 'nonNullListOfNpnNull' => [1, null] |
||
| 129 | ], |
||
| 130 | 'errors' => [ |
||
| 131 | [ |
||
| 132 | 'message' => 'Cannot return null for non-nullable field "nonNullListOfNpnNull"' |
||
| 133 | ] |
||
| 134 | ] |
||
| 135 | ] |
||
| 136 | ], |
||
| 137 | |||
| 138 | [ |
||
| 139 | '{ user {id, name} }', |
||
| 140 | [ |
||
| 141 | 'data' => [ |
||
| 142 | 'user' => [ |
||
| 143 | 'id' => '6cfb044c-9c0a-4ddd-9ef8-a0b940818db3', |
||
| 144 | 'name' => 'Alex' |
||
| 145 | ] |
||
| 146 | ] |
||
| 147 | ] |
||
| 148 | ], |
||
| 149 | [ |
||
| 150 | '{ user { __typename } }', |
||
| 151 | [ |
||
| 152 | 'data' => [ |
||
| 153 | 'user' => [ |
||
| 154 | '__typename' => 'User' |
||
| 155 | ] |
||
| 156 | ] |
||
| 157 | ] |
||
| 158 | ] |
||
| 159 | ]; |
||
| 160 | } |
||
| 161 | |||
| 162 | } |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.