| Conditions | 13 |
| Paths | 10 |
| Total Lines | 60 |
| Code Lines | 33 |
| 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 |
||
| 38 | public static function get_indexes($class = null, $rebuild = false) |
||
| 39 | { |
||
| 40 | if ($rebuild) { |
||
| 41 | self::$all_indexes = null; |
||
| 42 | self::$indexes_by_subclass = array(); |
||
| 43 | } |
||
| 44 | |||
| 45 | if (!$class) { |
||
| 46 | if (self::$all_indexes === null) { |
||
| 47 | // Get declared indexes, or otherwise default to all subclasses of SearchIndex |
||
| 48 | $classes = Config::inst()->get(__CLASS__, 'indexes') |
||
| 49 | ?: ClassInfo::subclassesFor(SearchIndex::class); |
||
| 50 | |||
| 51 | $hidden = array(); |
||
| 52 | $candidates = array(); |
||
| 53 | foreach ($classes as $class) { |
||
| 54 | // Check if this index is disabled |
||
| 55 | $hides = $class::config()->hide_ancestor; |
||
| 56 | if ($hides) { |
||
| 57 | $hidden[] = $hides; |
||
| 58 | } |
||
| 59 | |||
| 60 | // Check if this index is abstract |
||
| 61 | $ref = new ReflectionClass($class); |
||
| 62 | if (!$ref->isInstantiable()) { |
||
| 63 | continue; |
||
| 64 | } |
||
| 65 | |||
| 66 | $candidates[] = $class; |
||
| 67 | } |
||
| 68 | |||
| 69 | if ($hidden) { |
||
| 70 | $candidates = array_diff($candidates, $hidden); |
||
| 71 | } |
||
| 72 | |||
| 73 | // Create all indexes |
||
| 74 | $concrete = array(); |
||
| 75 | foreach ($candidates as $class) { |
||
| 76 | $concrete[$class] = singleton($class); |
||
| 77 | } |
||
| 78 | |||
| 79 | self::$all_indexes = $concrete; |
||
| 80 | } |
||
| 81 | |||
| 82 | return self::$all_indexes; |
||
| 83 | } else { |
||
| 84 | if (!isset(self::$indexes_by_subclass[$class])) { |
||
| 85 | $all = self::get_indexes(); |
||
| 86 | |||
| 87 | $valid = array(); |
||
| 88 | foreach ($all as $indexclass => $instance) { |
||
| 89 | if (is_subclass_of($indexclass, $class)) { |
||
| 90 | $valid[$indexclass] = $instance; |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | self::$indexes_by_subclass[$class] = $valid; |
||
| 95 | } |
||
| 96 | |||
| 97 | return self::$indexes_by_subclass[$class]; |
||
| 98 | } |
||
| 147 |