| Conditions | 13 |
| Paths | 25 |
| Total Lines | 45 |
| Code Lines | 28 |
| 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 |
||
| 33 | public function getAllLinksInner(bool $inCMS) |
||
| 34 | { |
||
| 35 | //first() will return null or the object |
||
| 36 | $return = []; |
||
| 37 | $list = ClassInfo::subclassesFor(DataObject::class); |
||
| 38 | $exceptForArray = array_merge($this->getListOfAllSiteTreeClasses(), [DataObject::class]); |
||
| 39 | foreach ($list as $class) { |
||
| 40 | if (! in_array($class, $exceptForArray, true)) { |
||
| 41 | if ($this->isValidClass($class)) { |
||
| 42 | for ($i = 0; $i < $this->getNumberOfExamples(); $i++) { |
||
| 43 | $obj = DataObject::get_one( |
||
| 44 | $class, |
||
| 45 | ['ClassName' => $class], |
||
| 46 | null, |
||
| 47 | DB::get_conn()->random() . ' ASC' |
||
| 48 | ); |
||
| 49 | if ($obj) { |
||
| 50 | if ($inCMS) { |
||
| 51 | if ($obj->hasMethod('CMSEditLink')) { |
||
| 52 | $return[] = $obj->CMSEditLink(); |
||
| 53 | } |
||
| 54 | if ($obj->hasMethod('CMSAddLink')) { |
||
| 55 | $return[] = $obj->CMSAddLink(); |
||
| 56 | } |
||
| 57 | if ($obj->hasMethod('CMSListLink')) { |
||
| 58 | $return[] = $obj->CMSListLink(); |
||
| 59 | } |
||
| 60 | if ($obj->hasMethod('PreviewLink')) { |
||
| 61 | $return[] = $obj->PreviewLink(); |
||
| 62 | } |
||
| 63 | } else { |
||
| 64 | if ($obj->hasMethod('Link')) { |
||
| 65 | $return[] = $obj->Link(); |
||
| 66 | } |
||
| 67 | if ($obj->hasMethod('getLink')) { |
||
| 68 | $return[] = $obj->getLink(); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | return $return; |
||
| 78 | } |
||
| 80 |