| Conditions | 21 | 
| Paths | 2050 | 
| Total Lines | 103 | 
| Code Lines | 66 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| 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 | ||
| 157 | protected static function findSource() | ||
| 158 |     { | ||
| 159 | $traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); | ||
| 160 | |||
| 161 | // Not relevant to determine source | ||
| 162 | $internalClasses = array( | ||
| 163 | '', | ||
| 164 | get_called_class(), | ||
| 165 | // DebugBar | ||
| 166 | DebugBar::class, | ||
| 167 | \LeKoala\DebugBar\Middleware\DebugBarMiddleware::class, | ||
| 168 | // Proxy | ||
| 169 | ProxyDBExtension::class, | ||
| 170 | \TractorCow\ClassProxy\Proxied\ProxiedBehaviour::class, | ||
| 171 | // Orm | ||
| 172 | \SilverStripe\ORM\Connect\Database::class, | ||
| 173 | \SilverStripe\ORM\Connect\DBSchemaManager::class, | ||
| 174 | \SilverStripe\ORM\Connect\MySQLDatabase::class, | ||
| 175 | \SilverStripe\ORM\Connect\MySQLSchemaManager::class, | ||
| 176 | \SilverStripe\ORM\DataObjectSchema::class, | ||
| 177 | \SilverStripe\ORM\DB::class, | ||
| 178 | \SilverStripe\ORM\Queries\SQLExpression::class, | ||
| 179 | \SilverStripe\ORM\DataList::class, | ||
| 180 | \SilverStripe\ORM\DataObject::class, | ||
| 181 | \SilverStripe\ORM\DataQuery::class, | ||
| 182 | \SilverStripe\ORM\Queries\SQLSelect::class, | ||
| 183 | \SilverStripe\ORM\Map::class, | ||
| 184 | \SilverStripe\ORM\ListDecorator::class, | ||
| 185 | // Core | ||
| 186 | \SilverStripe\Control\Director::class, | ||
| 187 | ); | ||
| 188 | |||
| 189 | $viewerClasses = array( | ||
| 190 | \SilverStripe\View\SSViewer_DataPresenter::class, | ||
| 191 | \SilverStripe\View\SSViewer_Scope::class, | ||
| 192 | \SilverStripe\View\SSViewer::class, | ||
| 193 | \SilverStripe\View\ViewableData::class | ||
| 194 | ); | ||
| 195 | |||
| 196 | $sources = array(); | ||
| 197 |         foreach ($traces as $trace) { | ||
| 198 | $class = isset($trace['class']) ? $trace['class'] : null; | ||
| 199 | $line = isset($trace['line']) ? $trace['line'] : null; | ||
| 200 | $function = isset($trace['function']) ? $trace['function'] : null; | ||
| 201 | $type = isset($trace['type']) ? $trace['type'] : '::'; | ||
| 202 | |||
| 203 | /* @var $object SSViewer */ | ||
| 204 | $object = isset($trace['object']) ? $trace['object'] : null; | ||
| 205 | |||
| 206 |             if (in_array($class, $internalClasses)) { | ||
| 207 | continue; | ||
| 208 | } | ||
| 209 | |||
| 210 | // Viewer classes need special handling | ||
| 211 |             if (in_array($class, $viewerClasses)) { | ||
| 212 |                 if ($function == 'includeGeneratedTemplate') { | ||
| 213 | $templates = $object->templates(); | ||
| 214 | |||
| 215 | $template = null; | ||
| 216 |                     if (isset($templates['main'])) { | ||
| 217 | $template = basename($templates['main']); | ||
| 218 |                     } else { | ||
| 219 | $keys = array_keys($templates); | ||
| 220 | $key = reset($keys); | ||
| 221 |                         if (isset($templates[$key])) { | ||
| 222 | $template = $key . ':' . basename($templates[$key]); | ||
| 223 | } | ||
| 224 | } | ||
| 225 |                     if (!empty($template)) { | ||
| 226 | $sources[] = $template; | ||
| 227 | } | ||
| 228 | } | ||
| 229 | continue; | ||
| 230 | } | ||
| 231 | |||
| 232 | $name = $class; | ||
| 233 |             if ($class && !DebugBar::config()->get('show_namespaces')) { | ||
| 234 |                 $nameArray = explode("\\", $class); | ||
| 235 | $name = array_pop($nameArray); | ||
| 236 | } | ||
| 237 |             if ($function) { | ||
| 238 | $name .= $type . $function; | ||
| 239 | } | ||
| 240 |             if ($line) { | ||
| 241 | $name .= ':' . $line; | ||
| 242 | } | ||
| 243 | |||
| 244 | $sources[] = $name; | ||
| 245 | |||
| 246 |             if (count($sources) > self::MAX_FIND_SOURCE_LEVEL) { | ||
| 247 | break; | ||
| 248 | } | ||
| 249 | |||
| 250 | // We reached a Controller, exit loop | ||
| 251 |             if ($object && $object instanceof Controller) { | ||
| 252 | break; | ||
| 253 | } | ||
| 254 | } | ||
| 255 | |||
| 256 |         if (empty($sources)) { | ||
| 257 | return 'Undefined source'; | ||
| 258 | } | ||
| 259 |         return implode(' > ', $sources); | ||
| 260 | } | ||
| 262 |