| Conditions | 11 |
| Paths | 24 |
| Total Lines | 40 |
| Code Lines | 31 |
| 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 |
||
| 89 | public function generateCompleteItems(): void |
||
| 90 | { |
||
| 91 | // Gather up all of the globals to parse |
||
| 92 | $globals = array_merge( |
||
| 93 | $this->twigGlobals, |
||
| 94 | $this->elementRouteGlobals, |
||
| 95 | $this->additionalGlobals, |
||
| 96 | $this->overrideValues() |
||
| 97 | ); |
||
| 98 | foreach ($globals as $key => $value) { |
||
| 99 | if (!in_array($key, parent::EXCLUDED_PROPERTY_NAMES, true)) { |
||
| 100 | $type = gettype($value); |
||
| 101 | switch ($type) { |
||
| 102 | case 'object': |
||
| 103 | $this->parseObject($key, $value, 0); |
||
| 104 | break; |
||
| 105 | |||
| 106 | case 'array': |
||
| 107 | case 'boolean': |
||
| 108 | case 'double': |
||
| 109 | case 'integer': |
||
| 110 | case 'string': |
||
| 111 | $kind = CompleteItemKind::VariableKind; |
||
| 112 | $path = $key; |
||
| 113 | $normalizedKey = preg_replace("/[^A-Za-z]/", '', $key); |
||
| 114 | if (ctype_upper($normalizedKey)) { |
||
| 115 | $kind = CompleteItemKind::ConstantKind; |
||
| 116 | } |
||
| 117 | // If this is an array, JSON-encode the keys. In the future, we could recursively parse the array |
||
| 118 | // To allow for nested values |
||
| 119 | if (is_array($value)) { |
||
| 120 | $value = json_encode(array_keys($value)); |
||
| 121 | } |
||
| 122 | CompleteItem::create() |
||
| 123 | ->detail((string)$value) |
||
| 124 | ->kind($kind) |
||
| 125 | ->label((string)$key) |
||
| 126 | ->insertText((string)$key) |
||
| 127 | ->add($this, $path); |
||
| 128 | break; |
||
| 129 | } |
||
| 170 |