| Conditions | 10 |
| Paths | 54 |
| Total Lines | 35 |
| Code Lines | 20 |
| 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 |
||
| 43 | private function setIndexed(string $entityType, string $path, string $index, $value): void |
||
| 44 | { |
||
| 45 | $field = null; |
||
| 46 | if (strpos($index, '.') > 0) { |
||
| 47 | [$index, $field] = explode('.', $index, 2); |
||
| 48 | } |
||
| 49 | |||
| 50 | $targetIndex = $index; |
||
| 51 | if (!is_numeric($targetIndex)) { |
||
| 52 | if (\is_array($value)) { |
||
| 53 | $value['type'] = $targetIndex; |
||
| 54 | } |
||
| 55 | $targetIndex = null; |
||
| 56 | if (isset($this->data[$entityType][$path])) { |
||
| 57 | foreach ((array)$this->data[$entityType][$path] as $nodeIndex => $node) { |
||
| 58 | if (isset($node['type']) && $node['type'] === $index) { |
||
| 59 | $targetIndex = $nodeIndex; |
||
| 60 | break; |
||
| 61 | } |
||
| 62 | } |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 66 | // No index found, new entry |
||
| 67 | if ($targetIndex === null) { |
||
| 68 | $this->addNewEntry($entityType, $path, $field, $index, $value); |
||
| 69 | return; |
||
| 70 | } |
||
| 71 | |||
| 72 | // Use found index |
||
| 73 | if ($field === null) { |
||
| 74 | $this->data[$entityType][$path][$targetIndex] = $value; |
||
| 75 | return; |
||
| 76 | } |
||
| 77 | $this->data[$entityType][$path][$targetIndex][$field] = $value; |
||
| 78 | } |
||
| 106 |