Conditions | 25 |
Paths | 4612 |
Total Lines | 117 |
Code Lines | 72 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
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 |
||
189 | protected static function findSource() |
||
190 | { |
||
191 | $traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); |
||
192 | |||
193 | // Not relevant to determine source |
||
194 | $internalClasses = [ |
||
195 | '', |
||
196 | get_called_class(), |
||
197 | // DebugBar |
||
198 | DebugBar::class, |
||
199 | \LeKoala\DebugBar\Middleware\DebugBarMiddleware::class, |
||
200 | // Proxy |
||
201 | ProxyDBExtension::class, |
||
202 | \TractorCow\ClassProxy\Proxied\ProxiedBehaviour::class, |
||
203 | // Orm |
||
204 | \SilverStripe\ORM\Connect\Database::class, |
||
205 | \SilverStripe\ORM\Connect\DBSchemaManager::class, |
||
206 | \SilverStripe\ORM\Connect\MySQLDatabase::class, |
||
207 | \SilverStripe\ORM\Connect\MySQLSchemaManager::class, |
||
208 | \SilverStripe\ORM\DataObjectSchema::class, |
||
209 | \SilverStripe\ORM\DB::class, |
||
210 | \SilverStripe\ORM\Queries\SQLExpression::class, |
||
211 | \SilverStripe\ORM\DataList::class, |
||
212 | \SilverStripe\ORM\DataObject::class, |
||
213 | \SilverStripe\ORM\DataQuery::class, |
||
214 | \SilverStripe\ORM\Queries\SQLSelect::class, |
||
215 | \SilverStripe\ORM\Map::class, |
||
216 | \SilverStripe\ORM\ListDecorator::class, |
||
217 | // Core |
||
218 | \SilverStripe\Control\Director::class, |
||
219 | ]; |
||
220 | |||
221 | $viewerClasses = [ |
||
222 | \SilverStripe\View\SSViewer_DataPresenter::class, |
||
223 | \SilverStripe\View\SSViewer_Scope::class, |
||
|
|||
224 | \SilverStripe\View\SSViewer::class, |
||
225 | \LeKoala\DebugBar\Proxy\SSViewerProxy::class, |
||
226 | \SilverStripe\View\ViewableData::class |
||
227 | ]; |
||
228 | |||
229 | $sources = []; |
||
230 | foreach ($traces as $i => $trace) { |
||
231 | // We need to be able to look ahead one item in the trace, because the class/function values |
||
232 | // are talking about what is being *called* on this line, not the function this line lives in. |
||
233 | if (!isset($traces[$i + 1])) { |
||
234 | break; |
||
235 | } |
||
236 | |||
237 | $file = isset($trace['file']) ? pathinfo($trace['file'], PATHINFO_FILENAME) : null; |
||
238 | $class = isset($traces[$i + 1]['class']) ? $traces[$i + 1]['class'] : null; |
||
239 | $line = isset($trace['line']) ? $trace['line'] : null; |
||
240 | $function = isset($traces[$i + 1]['function']) ? $traces[$i + 1]['function'] : null; |
||
241 | $type = isset($traces[$i + 1]['type']) ? $traces[$i + 1]['type'] : '::'; |
||
242 | |||
243 | /* @var $object SSViewer */ |
||
244 | $object = isset($traces[$i + 1]['object']) ? $traces[$i + 1]['object'] : null; |
||
245 | |||
246 | if (in_array($class, $internalClasses)) { |
||
247 | continue; |
||
248 | } |
||
249 | |||
250 | // Viewer classes need special handling |
||
251 | if (in_array($class, $viewerClasses)) { |
||
252 | if ($function == 'includeGeneratedTemplate') { |
||
253 | $templates = $object->templates(); |
||
254 | |||
255 | $template = null; |
||
256 | if (isset($templates['main'])) { |
||
257 | $template = basename($templates['main']); |
||
258 | } else { |
||
259 | $keys = array_keys($templates); |
||
260 | $key = reset($keys); |
||
261 | if (isset($templates[$key])) { |
||
262 | $template = $key . ':' . basename($templates[$key]); |
||
263 | } |
||
264 | } |
||
265 | if (!empty($template)) { |
||
266 | $sources[] = $template; |
||
267 | } |
||
268 | } |
||
269 | continue; |
||
270 | } |
||
271 | |||
272 | $name = $class; |
||
273 | if ($class && !DebugBar::config()->get('show_namespaces')) { |
||
274 | $nameArray = explode("\\", $class); |
||
275 | $name = array_pop($nameArray); |
||
276 | |||
277 | // Maybe we are inside a trait? |
||
278 | if ($file && $file != $name) { |
||
279 | $name .= '(' . $file . ')'; |
||
280 | } |
||
281 | } |
||
282 | if ($function) { |
||
283 | $name .= $type . $function; |
||
284 | } |
||
285 | if ($line) { |
||
286 | // Line number could apply to a trait |
||
287 | $name .= ':' . $line; |
||
288 | } |
||
289 | |||
290 | $sources[] = $name; |
||
291 | |||
292 | if (count($sources) > self::MAX_FIND_SOURCE_LEVEL) { |
||
293 | break; |
||
294 | } |
||
295 | |||
296 | // We reached a Controller, exit loop |
||
297 | if ($object && $object instanceof Controller) { |
||
298 | break; |
||
299 | } |
||
300 | } |
||
301 | |||
302 | if (empty($sources)) { |
||
303 | return 'Undefined source'; |
||
304 | } |
||
305 | return implode(' > ', $sources); |
||
306 | } |
||
308 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths