Conditions | 20 |
Paths | 384 |
Total Lines | 101 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
115 | public function listContents($depth = 0, $filter = null, $type = 'all', $asHandlers = false) |
||
116 | { |
||
117 | $pattern = $this->path.'/*'; |
||
118 | |||
119 | if (is_array($filter)) |
||
120 | { |
||
121 | $filters = $filter; |
||
122 | $filter = new Filter; |
||
123 | |||
124 | foreach ($filters as $f => $type) |
||
125 | { |
||
126 | if ( ! is_int($f)) |
||
127 | { |
||
128 | $f = $type; |
||
129 | $type = null; |
||
130 | } |
||
131 | |||
132 | $expected = true; |
||
133 | |||
134 | if (strpos($f, '!') === 0) |
||
135 | { |
||
136 | $f = substr($f, 1); |
||
137 | $expected = false; |
||
138 | } |
||
139 | |||
140 | $filter->addFilter($f, $expected, $type); |
||
141 | } |
||
142 | } |
||
143 | |||
144 | if ($filter instanceof \Closure) |
||
145 | { |
||
146 | $callback = $filter; |
||
147 | $filter = new Filter(); |
||
148 | $callback($filter); |
||
149 | } |
||
150 | |||
151 | if ( ! $filter) |
||
152 | { |
||
153 | $filter = new Filter; |
||
154 | } |
||
155 | |||
156 | $flags = GLOB_MARK; |
||
157 | |||
158 | if ($type === 'file' and ! pathinfo($pattern, PATHINFO_EXTENSION)) |
||
159 | { |
||
160 | // Add an extension wildcard |
||
161 | $pattern .= '.*'; |
||
162 | } |
||
163 | elseif ($type === 'dir') |
||
164 | { |
||
165 | $flags = GLOB_MARK | GLOB_ONLYDIR; |
||
166 | } |
||
167 | |||
168 | $contents = glob($pattern, $flags); |
||
169 | |||
170 | // Filter the content. |
||
171 | $contents = $filter->filter($contents); |
||
172 | |||
173 | // Lower the depth for a recursive call |
||
174 | if ($depth and $depth !== true) |
||
175 | { |
||
176 | $depth--; |
||
177 | } |
||
178 | |||
179 | $formatted = array(); |
||
180 | |||
181 | foreach ($contents as $item) |
||
182 | { |
||
183 | if ($filter->isCorrectType('dir', $item)) |
||
184 | { |
||
185 | $_contents = array(); |
||
186 | |||
187 | if (($depth === true or $depth === 0) and ! $asHandlers) |
||
188 | { |
||
189 | $dir = new Directory($item); |
||
190 | |||
191 | $_contents = $dir->listContents($item, $filter, $depth, $type); |
||
192 | } |
||
193 | |||
194 | if ($asHandlers) |
||
195 | { |
||
196 | $formatted[] = new Directory($item); |
||
197 | } |
||
198 | else |
||
199 | { |
||
200 | $formatted[$item] = $_contents; |
||
201 | } |
||
202 | } |
||
203 | elseif ($filter->isCorrectType('file', $item)) |
||
204 | { |
||
205 | if ($asHandlers) |
||
206 | { |
||
207 | $item = new File($item); |
||
208 | } |
||
209 | |||
210 | $formatted[] = $item; |
||
211 | } |
||
212 | } |
||
213 | |||
214 | return $formatted; |
||
215 | } |
||
216 | } |
||
217 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.