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