| Conditions | 18 |
| Paths | 108 |
| Total Lines | 59 |
| Code Lines | 36 |
| 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 declare(strict_types=1); |
||
| 46 | public function toArray($extra = false): array |
||
| 47 | { |
||
| 48 | $ret = parent::toArray(); |
||
| 49 | $form = $this->getForm(true); |
||
| 50 | foreach ($form as $key => $element) { |
||
| 51 | $ret['form'][$key] = $element->render(); |
||
| 52 | } |
||
| 53 | foreach (['created', 'updated'] as $key) { |
||
| 54 | if ($this->getVar($key) > 0) { |
||
| 55 | $ret['form'][$key] = \date(_DATESTRING, $this->getVar($key)); |
||
| 56 | $ret[$key] = \date(_DATESTRING, $this->getVar($key)); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | $ret['rank'] = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN; |
||
| 61 | $ret['url'] = $this->getURL(true); |
||
| 62 | |||
| 63 | \xoops_loadLanguage('enum', 'songlist'); |
||
| 64 | if (!empty($ret['singer'])) { |
||
| 65 | $ret['singer'] = \constant($ret['singer']); |
||
| 66 | } |
||
| 67 | |||
| 68 | if (!$extra) { |
||
| 69 | return $ret; |
||
| 70 | } |
||
| 71 | |||
| 72 | if (0 != \count($this->getVar('cids'))) { |
||
| 73 | $categoriesHandler = Helper::getInstance()->getHandler('Category'); |
||
| 74 | foreach ($this->getVar('cids') as $aid) { |
||
| 75 | $category = $categoriesHandler->get($aid); |
||
| 76 | if (\is_object($category)) { |
||
| 77 | $ret['categories_array'][$aid] = $category->toArray(false); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | if (\is_array($this->getVar('aids')) && 0 != \count($this->getVar('aids'))) { |
||
| 83 | $artistsHandler = Helper::getInstance()->getHandler('Artists'); |
||
| 84 | foreach ($this->getVar('aids') as $aid) { |
||
| 85 | $artist = $artistsHandler->get($aid); |
||
| 86 | if (\is_object($artist)) { |
||
| 87 | $ret['artists_array'][$aid] = $artist->toArray(false); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | if (0 != \count($this->getVar('sids'))) { |
||
| 93 | $songsHandler = Helper::getInstance()->getHandler('Songs'); |
||
| 94 | $criteria = new \Criteria('aids', '%"' . $this->getVar('aid') . '"%', 'LIKE'); |
||
| 95 | $criteria->setSort('songid'); |
||
| 96 | $criteria->setOrder('ASC'); |
||
| 97 | foreach ($songsHandler->getObjects($criteria, true) as $sid => $song) { |
||
| 98 | if (\is_object($song)) { |
||
| 99 | $ret['songs_array'][$sid] = $song->toArray(false); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | return $ret; |
||
| 105 | } |
||
| 149 |