| Conditions | 14 |
| Paths | 9 |
| Total Lines | 59 |
| 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 |
||
| 140 | public function Children() |
||
| 141 | { |
||
| 142 | if (self::$_children_cache_for_sorting === null) { |
||
| 143 | $class = $this->request->param("ID"); |
||
| 144 | if ($class) { |
||
| 145 | if (class_exists($class)) { |
||
| 146 | $where = ''; |
||
| 147 | $filterField = Convert::raw2sql($this->request->param("OtherID")); |
||
| 148 | $filterValue = Convert::raw2sql($this->request->param("ThirdID")); |
||
| 149 | $titleField = Convert::raw2sql($this->request->param("FourthID")); |
||
| 150 | $objects = $class::get(); |
||
| 151 | if ($filterField && $filterValue) { |
||
| 152 | $filterValue = explode(",", $filterValue); |
||
| 153 | $objects = $objects->filter(array($filterField => $filterValue)); |
||
| 154 | } elseif (is_numeric($filterField)) { |
||
| 155 | $objects = $objects->filter(array("ParentID" => $filterField)); |
||
| 156 | } |
||
| 157 | $singletonObj = singleton($class); |
||
| 158 | $sortField = $singletonObj->SortFieldForDataObjectSorter(); |
||
| 159 | $objects = $objects->sort($sortField, "ASC"); |
||
| 160 | $tobeExcludedArray = array(); |
||
| 161 | if ($objects->count()) { |
||
| 162 | foreach ($objects as $obj) { |
||
| 163 | if ($obj->canEdit()) { |
||
| 164 | if ($titleField) { |
||
| 165 | $method = "getSortTitle"; |
||
| 166 | if ($obj->hasMethod($method)) { |
||
| 167 | $obj->SortTitle = $obj->$method(); |
||
| 168 | } else { |
||
| 169 | $method = 'SortTitle'; |
||
| 170 | if ($obj->hasMethod($method)) { |
||
| 171 | $obj->SortTitle = $obj->$method(); |
||
| 172 | } elseif ($obj->hasDatabaseField($titleField)) { |
||
| 173 | $obj->SortTitle = $obj->$titleField; |
||
| 174 | } |
||
| 175 | } |
||
| 176 | } else { |
||
| 177 | $obj->SortTitle = $obj->getTitle(); |
||
| 178 | } |
||
| 179 | } else { |
||
| 180 | $tobeExcludedArray[$obj->ID] = $obj->ID; |
||
| 181 | } |
||
| 182 | } |
||
| 183 | $objects = $objects->exclude(array('ID' => $tobeExcludedArray)); |
||
| 184 | $this->addRequirements($class); |
||
| 185 | self::$_children_cache_for_sorting = $objects; |
||
| 186 | } else { |
||
| 187 | return null; |
||
| 188 | } |
||
| 189 | } else { |
||
| 190 | user_error("$class does not exist", E_USER_WARNING); |
||
| 191 | } |
||
| 192 | } else { |
||
| 193 | user_error("Please make sure to provide a class to sort e.g. http://www.sunnysideup.co.nz/dataobjectsorter/MyLongList - where MyLongList is the DataObject you want to sort.", E_USER_WARNING); |
||
| 194 | } |
||
| 195 | } else { |
||
| 196 | } |
||
| 197 | return self::$_children_cache_for_sorting; |
||
| 198 | } |
||
| 199 | |||
| 216 |