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 |
||
168 | protected static function findSource() |
||
169 | { |
||
170 | $traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); |
||
171 | |||
172 | // Not relevant to determine source |
||
173 | $internalClasses = array( |
||
174 | '', |
||
175 | get_called_class(), |
||
176 | // DebugBar |
||
177 | DebugBar::class, |
||
178 | \LeKoala\DebugBar\Middleware\DebugBarMiddleware::class, |
||
179 | // Proxy |
||
180 | ProxyDBExtension::class, |
||
181 | \TractorCow\ClassProxy\Proxied\ProxiedBehaviour::class, |
||
182 | // Orm |
||
183 | \SilverStripe\ORM\Connect\Database::class, |
||
184 | \SilverStripe\ORM\Connect\DBSchemaManager::class, |
||
185 | \SilverStripe\ORM\Connect\MySQLDatabase::class, |
||
186 | \SilverStripe\ORM\Connect\MySQLSchemaManager::class, |
||
187 | \SilverStripe\ORM\DataObjectSchema::class, |
||
188 | \SilverStripe\ORM\DB::class, |
||
189 | \SilverStripe\ORM\Queries\SQLExpression::class, |
||
190 | \SilverStripe\ORM\DataList::class, |
||
191 | \SilverStripe\ORM\DataObject::class, |
||
192 | \SilverStripe\ORM\DataQuery::class, |
||
193 | \SilverStripe\ORM\Queries\SQLSelect::class, |
||
194 | \SilverStripe\ORM\Map::class, |
||
195 | \SilverStripe\ORM\ListDecorator::class, |
||
196 | // Core |
||
197 | \SilverStripe\Control\Director::class, |
||
198 | ); |
||
199 | |||
200 | $viewerClasses = array( |
||
201 | \SilverStripe\View\SSViewer_DataPresenter::class, |
||
202 | \SilverStripe\View\SSViewer_Scope::class, |
||
|
|||
203 | \SilverStripe\View\SSViewer::class, |
||
204 | \LeKoala\DebugBar\Proxy\SSViewerProxy::class, |
||
205 | \SilverStripe\View\ViewableData::class |
||
206 | ); |
||
207 | |||
208 | $sources = []; |
||
209 | foreach ($traces as $i => $trace) { |
||
210 | // We need to be able to look ahead one item in the trace, because the class/function values |
||
211 | // are talking about what is being *called* on this line, not the function this line lives in. |
||
212 | if (!isset($traces[$i + 1])) { |
||
213 | break; |
||
214 | } |
||
215 | |||
216 | $file = isset($trace['file']) ? pathinfo($trace['file'], PATHINFO_FILENAME) : null; |
||
217 | $class = isset($traces[$i + 1]['class']) ? $traces[$i + 1]['class'] : null; |
||
218 | $line = isset($trace['line']) ? $trace['line'] : null; |
||
219 | $function = isset($traces[$i + 1]['function']) ? $traces[$i + 1]['function'] : null; |
||
220 | $type = isset($traces[$i + 1]['type']) ? $traces[$i + 1]['type'] : '::'; |
||
221 | |||
222 | /* @var $object SSViewer */ |
||
223 | $object = isset($traces[$i + 1]['object']) ? $traces[$i + 1]['object'] : null; |
||
224 | |||
225 | if (in_array($class, $internalClasses)) { |
||
226 | continue; |
||
227 | } |
||
228 | |||
229 | // Viewer classes need special handling |
||
230 | if (in_array($class, $viewerClasses)) { |
||
231 | if ($function == 'includeGeneratedTemplate') { |
||
232 | $templates = $object->templates(); |
||
233 | |||
234 | $template = null; |
||
235 | if (isset($templates['main'])) { |
||
236 | $template = basename($templates['main']); |
||
237 | } else { |
||
238 | $keys = array_keys($templates); |
||
239 | $key = reset($keys); |
||
240 | if (isset($templates[$key])) { |
||
241 | $template = $key . ':' . basename($templates[$key]); |
||
242 | } |
||
243 | } |
||
244 | if (!empty($template)) { |
||
245 | $sources[] = $template; |
||
246 | } |
||
247 | } |
||
248 | continue; |
||
249 | } |
||
250 | |||
251 | $name = $class; |
||
252 | if ($class && !DebugBar::config()->get('show_namespaces')) { |
||
253 | $nameArray = explode("\\", $class); |
||
254 | $name = array_pop($nameArray); |
||
255 | |||
256 | // Maybe we are inside a trait? |
||
257 | if ($file && $file != $name) { |
||
258 | $name .= '(' . $file . ')'; |
||
259 | } |
||
260 | } |
||
261 | if ($function) { |
||
262 | $name .= $type . $function; |
||
263 | } |
||
264 | if ($line) { |
||
265 | // Line number could apply to a trait |
||
266 | $name .= ':' . $line; |
||
267 | } |
||
268 | |||
269 | $sources[] = $name; |
||
270 | |||
271 | if (count($sources) > self::MAX_FIND_SOURCE_LEVEL) { |
||
272 | break; |
||
273 | } |
||
274 | |||
275 | // We reached a Controller, exit loop |
||
276 | if ($object && $object instanceof Controller) { |
||
277 | break; |
||
278 | } |
||
279 | } |
||
280 | |||
281 | if (empty($sources)) { |
||
282 | return 'Undefined source'; |
||
283 | } |
||
284 | return implode(' > ', $sources); |
||
285 | } |
||
287 |
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