| Conditions | 21 |
| Paths | 17 |
| Total Lines | 82 |
| Code Lines | 56 |
| 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 |
||
| 25 | public function ListOfAllClasses($checkCurrentClass = true) |
||
| 26 | { |
||
| 27 | if (!self::$list_of_all_classes) { |
||
| 28 | $ArrayOfAllClasses = array(); |
||
| 29 | //$classes = ClassInfo::subclassesFor("SiteTree"); |
||
| 30 | $classes = SiteTree::page_type_classes(); |
||
| 31 | $classesToRemove = array(); |
||
| 32 | |||
| 33 | foreach ($classes as $className) { |
||
| 34 | if (!in_array($className, $this->config()->get("classes_to_exclude"))) { |
||
| 35 | if ($this->showAll) { |
||
| 36 | $objects = $className::get() |
||
| 37 | ->filter(array("ClassName" => $className)) |
||
| 38 | ->sort("RAND() ASC") |
||
| 39 | ->limit(25); |
||
| 40 | $count = 0; |
||
| 41 | if ($objects->count()) { |
||
| 42 | foreach ($objects as $obj) { |
||
| 43 | if (!$count) { |
||
| 44 | if ($ancestorToHide = $obj->stat('hide_ancestor')) { |
||
| 45 | $classesToRemove[] = $ancestorToHide; |
||
| 46 | } |
||
| 47 | } |
||
| 48 | $object = $this->createPageObject($obj, $count++); |
||
| 49 | $ArrayOfAllClasses[$object->indexNumber] = clone $object; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | } else { |
||
| 53 | $obj = null; |
||
| 54 | $obj = $className::get() |
||
| 55 | ->filter(array("ClassName" => $className)) |
||
| 56 | ->sort("RAND() ASC") |
||
| 57 | ->limit(1) |
||
| 58 | ->first(); |
||
| 59 | if ($obj) { |
||
| 60 | $count = SiteTree::get()->filter(array("ClassName" => $obj->ClassName))->count(); |
||
| 61 | } else { |
||
| 62 | $obj = $className::create(); |
||
| 63 | $count = 0; |
||
| 64 | } |
||
| 65 | if ($ancestorToHide = $obj->stat('hide_ancestor')) { |
||
| 66 | $classesToRemove[] = $ancestorToHide; |
||
| 67 | } |
||
| 68 | $object = $this->createPageObject($obj, $count); |
||
| 69 | $ArrayOfAllClasses[$object->indexNumber] = clone $object; |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | //remove the hidden ancestors... |
||
| 75 | if ($classesToRemove && count($classesToRemove)) { |
||
| 76 | $classesToRemove = array_unique($classesToRemove); |
||
| 77 | // unset from $classes |
||
| 78 | foreach ($ArrayOfAllClasses as $tempKey => $tempClass) { |
||
| 79 | if (in_array($tempClass->ClassName, $classesToRemove)) { |
||
| 80 | unset($ArrayOfAllClasses[$tempKey]); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | ksort($ArrayOfAllClasses); |
||
| 85 | self::$list_of_all_classes = new ArrayList(); |
||
| 86 | $currentClassname = ''; |
||
| 87 | if ($checkCurrentClass) { |
||
| 88 | if ($c = Controller::curr()) { |
||
| 89 | if ($d = $c->dataRecord) { |
||
| 90 | $currentClassname = $d->ClassName; |
||
| 91 | } |
||
| 92 | } |
||
| 93 | } |
||
| 94 | if (count($ArrayOfAllClasses)) { |
||
| 95 | foreach ($ArrayOfAllClasses as $item) { |
||
| 96 | if ($item->ClassName == $currentClassname) { |
||
| 97 | $item->LinkingMode = "current"; |
||
| 98 | } else { |
||
| 99 | $item->LinkingMode = "link"; |
||
| 100 | } |
||
| 101 | self::$list_of_all_classes->push($item); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | } |
||
| 105 | return self::$list_of_all_classes; |
||
| 106 | } |
||
| 107 | |||
| 175 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.