Conditions | 12 |
Paths | 17 |
Total Lines | 40 |
Code Lines | 25 |
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 |
||
97 | public function accept(VisitorInterface $visitor, ?string $key = null, array $path = []): ?array |
||
98 | { |
||
99 | /** @noinspection PhpParamsInspection */ |
||
100 | if (null === ($enterResult = $visitor->enterNode($this, $key, $path))) { |
||
|
|||
101 | return null; |
||
102 | } |
||
103 | |||
104 | $edited = $enterResult; |
||
105 | foreach (self::$kindToNodesToVisitMap[$this->getKind()] as $name) { |
||
106 | unset($edited[$name]); |
||
107 | $value = $this->{$name}; |
||
108 | if (\is_array($value) && !empty($value)) { |
||
109 | $path[] = $name; |
||
110 | $i = 0; |
||
111 | foreach ($value as $v) { |
||
112 | if ($v instanceof AcceptVisitorInterface) { |
||
113 | $path[] = $i; |
||
114 | if (null !== ($result = $v->accept($visitor, $i, $path))) { |
||
115 | $edited[$name][$i] = $result; |
||
116 | $i++; |
||
117 | } |
||
118 | $path = \array_slice($path, 0, count($path) - 1); |
||
119 | } |
||
120 | } |
||
121 | $path = \array_slice($path, 0, count($path) - 1); |
||
122 | } elseif ($value instanceof AcceptVisitorInterface) { |
||
123 | $path[] = $name; |
||
124 | if (null !== ($result = $value->accept($visitor, $name, $path))) { |
||
125 | $edited[$name] = $result; |
||
126 | } |
||
127 | $path = \array_slice($path, 0, count($path) - 1); |
||
128 | } |
||
129 | } |
||
130 | |||
131 | /** @noinspection PhpParamsInspection */ |
||
132 | if (null === ($leaveResult = $visitor->leaveNode($this, $key, $path))) { |
||
133 | return null; |
||
134 | } |
||
135 | |||
136 | return array_merge($leaveResult, \is_array($edited) ? $edited : []); |
||
137 | } |
||
139 |