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