We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 10 |
| Paths | 1 |
| Total Lines | 57 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 38 |
| CRAP Score | 10 |
| 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 |
||
| 131 | 5 | private function resolveAccessAndWrapResolveCallback($expression, callable $resolveCallback = null) |
|
| 132 | { |
||
| 133 | return function () use ($expression, $resolveCallback) { |
||
| 134 | 5 | $args = func_get_args(); |
|
| 135 | |||
| 136 | 5 | $result = null !== $resolveCallback ? call_user_func_array($resolveCallback, $args) : null; |
|
| 137 | |||
| 138 | 5 | $values = call_user_func_array([$this, 'solveResolveCallbackArgs'], $args); |
|
| 139 | |||
| 140 | $checkAccess = function ($object, $throwException = false) use ($expression, $values) { |
||
| 141 | try { |
||
| 142 | 5 | $access = $this->solveUsingExpressionLanguageIfNeeded( |
|
| 143 | 5 | $expression, |
|
| 144 | 5 | array_merge($values, ['object' => $object]) |
|
| 145 | 5 | ); |
|
| 146 | 5 | } catch (\Exception $e) { |
|
| 147 | 1 | $access = false; |
|
| 148 | } |
||
| 149 | |||
| 150 | 5 | if ($throwException && !$access) { |
|
| 151 | 2 | throw new UserError('Access denied to this field.'); |
|
| 152 | } |
||
| 153 | |||
| 154 | 3 | return $access; |
|
| 155 | 5 | }; |
|
| 156 | |||
| 157 | 5 | switch (true) { |
|
| 158 | 5 | case is_array($result) || $result instanceof \ArrayAccess: |
|
| 159 | 1 | $result = array_filter( |
|
| 160 | 1 | array_map( |
|
| 161 | function ($object) use ($checkAccess) { |
||
| 162 | 1 | return $checkAccess($object) ? $object : null; |
|
| 163 | 1 | }, |
|
| 164 | $result |
||
| 165 | 1 | ) |
|
| 166 | 1 | ); |
|
| 167 | 1 | break; |
|
| 168 | |||
| 169 | 4 | case $result instanceof Connection: |
|
| 170 | 1 | $result->edges = array_map( |
|
| 171 | 1 | function (Edge $edge) use ($checkAccess) { |
|
| 172 | 1 | $edge->node = $checkAccess($edge->node) ? $edge->node : null; |
|
| 173 | |||
| 174 | 1 | return $edge; |
|
| 175 | 1 | }, |
|
| 176 | 1 | $result->edges |
|
| 177 | 1 | ); |
|
| 178 | 1 | break; |
|
| 179 | |||
| 180 | 3 | default: |
|
| 181 | 3 | $checkAccess($result, true); |
|
| 182 | 1 | break; |
|
| 183 | 3 | } |
|
| 184 | |||
| 185 | 3 | return $result; |
|
| 186 | 5 | }; |
|
| 187 | } |
||
| 188 | } |
||
| 189 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.