| Conditions | 15 |
| Paths | 25 |
| Total Lines | 49 |
| 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 |
||
| 15 | public function getAllLinksInner(bool $inCMS) |
||
| 16 | { |
||
| 17 | //first() will return null or the object |
||
| 18 | $return = []; |
||
| 19 | $list = ClassInfo::subclassesFor(DataObject::class); |
||
| 20 | $exceptForArray = array_merge($this->getListOfAllClasses(), [DataObject::class]); |
||
| 21 | foreach ($list as $class) { |
||
| 22 | if (! in_array($class, $exceptForArray, true)) { |
||
| 23 | if ($this->isValidClass($class)) { |
||
| 24 | for ($i = 0; $i < $this->getNumberOfExamples(); ++$i) { |
||
| 25 | $obj = DataObject::get_one( |
||
| 26 | $class, |
||
| 27 | ['ClassName' => $class], |
||
| 28 | null, |
||
| 29 | DB::get_conn()->random() . ' ASC' |
||
| 30 | ); |
||
| 31 | if (null !== $obj) { |
||
| 32 | if ($inCMS) { |
||
| 33 | if ($obj->hasMethod('CMSEditLink')) { |
||
| 34 | $return[] = $obj->CMSEditLink(); |
||
| 35 | } |
||
| 36 | |||
| 37 | if ($obj->hasMethod('CMSAddLink')) { |
||
| 38 | $return[] = $obj->CMSAddLink(); |
||
| 39 | } |
||
| 40 | |||
| 41 | if ($obj->hasMethod('CMSListLink')) { |
||
| 42 | $return[] = $obj->CMSListLink(); |
||
| 43 | } |
||
| 44 | |||
| 45 | if ($obj->hasMethod('PreviewLink')) { |
||
| 46 | $return[] = $obj->PreviewLink(); |
||
| 47 | } |
||
| 48 | } else { |
||
| 49 | if ($obj->hasMethod('Link') && ! (property_exists($obj, 'LinkID') && null !== $obj->LinkID)) { |
||
| 50 | $return[] = $obj->Link(); |
||
| 51 | } |
||
| 52 | |||
| 53 | if ($obj->hasMethod('getLink')) { |
||
| 54 | $return[] = $obj->getLink(); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | } |
||
| 58 | } |
||
| 59 | } |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | return $return; |
||
| 64 | } |
||
| 66 |