Conditions | 12 |
Paths | 506 |
Total Lines | 50 |
Code Lines | 27 |
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 |
||
17 | public function processPayload($payload, $variables = [], $visitors = []) { |
||
18 | $this->data = []; |
||
19 | |||
20 | try { |
||
21 | $this->parseAndCreateRequest($payload, $variables); |
||
22 | |||
23 | if (!empty($reducers)) { |
||
|
|||
24 | $schema = $this->executionContext->getSchema(); |
||
25 | $request = $this->executionContext->getRequest(); |
||
26 | $reducer = new QueryReducer($schema, $request); |
||
27 | |||
28 | foreach ($visitors as $visitor) { |
||
29 | $reducer->reduceQuery($visitor); |
||
30 | } |
||
31 | } |
||
32 | |||
33 | $operations = $this->executionContext->getRequest()->getAllOperations(); |
||
34 | foreach ($operations as $query) { |
||
35 | if ($operationResult = $this->resolveQuery($query)) { |
||
36 | $this->data = array_replace_recursive($this->data, $operationResult); |
||
37 | }; |
||
38 | } |
||
39 | |||
40 | // If the processor found any deferred results, resolve them now. |
||
41 | if (!empty($this->data) && (!empty($this->deferredResultsLeaf) || !empty($this->deferredResultsComplex))) { |
||
42 | try { |
||
43 | while ($deferredResolver = array_shift($this->deferredResultsComplex)) { |
||
44 | $deferredResolver->resolve(); |
||
45 | } |
||
46 | |||
47 | // Deferred scalar and enum fields should be resolved last to |
||
48 | // pick up as many as possible for a single batch. |
||
49 | while ($deferredResolver = array_shift($this->deferredResultsLeaf)) { |
||
50 | $deferredResolver->resolve(); |
||
51 | } |
||
52 | } |
||
53 | catch (\Exception $exception) { |
||
54 | $this->executionContext->addError($exception); |
||
55 | } |
||
56 | finally { |
||
57 | $this->data = static::unpackDeferredResults($this->data); |
||
58 | } |
||
59 | } |
||
60 | } |
||
61 | catch (\Exception $exception) { |
||
62 | $this->executionContext->addError($exception); |
||
63 | } |
||
64 | |||
65 | return $this; |
||
66 | } |
||
67 | |||
95 | } |
This check looks for calls to
isset(...)
orempty()
on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.