Conditions | 10 |
Paths | 5 |
Total Lines | 29 |
Code Lines | 20 |
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 |
||
51 | public function getContext() { |
||
52 | $request = $this->requestStack->getCurrentRequest(); |
||
53 | if (isset($this->contextCache[$request])) { |
||
54 | return $this->contextCache[$request]; |
||
55 | } |
||
56 | |||
57 | $hash = ''; |
||
58 | if ($request->attributes->has('query')) { |
||
59 | $hash = $this->contextCache[$request] = $this->getHash( |
||
60 | $request->attributes->get('schema') ?: '', |
||
61 | $request->attributes->get('query') ?: '', |
||
62 | $request->attributes->get('variables') ?: [] |
||
63 | ); |
||
64 | } |
||
65 | else if ($request->attributes->has('queries')) { |
||
66 | $queries = $request->attributes->get('queries'); |
||
67 | $schema = $request->attributes->get('schema') ?: ''; |
||
68 | |||
69 | return hash('sha256', json_encode(array_map(function($item) use ($schema) { |
||
70 | return $this->getHash( |
||
71 | $schema, |
||
72 | !empty($item['query']) ? $item['query'] : '', |
||
73 | !empty($item['variables']) ? $item['variables'] : [] |
||
74 | ); |
||
75 | }, $queries))); |
||
76 | } |
||
77 | |||
78 | return $this->contextCache[$request] = $hash; |
||
79 | } |
||
80 | |||
116 |