Conditions | 15 |
Paths | 78 |
Total Lines | 52 |
Code Lines | 33 |
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); |
||
49 | public function toArray($extra = true): array |
||
50 | { |
||
51 | $ret = parent::toArray(); |
||
52 | $form = $this->getForm(true); |
||
53 | foreach ($form as $key => $element) { |
||
54 | $ret['form'][$key] = $element->render(); |
||
55 | } |
||
56 | foreach (['created', 'updated'] as $key) { |
||
57 | if ($this->getVar($key) > 0) { |
||
58 | $ret['form'][$key] = \date(_DATESTRING, $this->getVar($key)); |
||
59 | $ret[$key] = \date(_DATESTRING, $this->getVar($key)); |
||
60 | } |
||
61 | } |
||
62 | $ret['picture'] = $this->getImage('image', false); |
||
63 | $ret['rank'] = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN; |
||
64 | $ret['url'] = $this->getURL(true); |
||
65 | |||
66 | if (!$extra) { |
||
67 | return $ret; |
||
68 | } |
||
69 | |||
70 | if (0 != $this->getVar('cid')) { |
||
71 | $categoryHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Category'); |
||
72 | $category = $categoryHandler->get($this->getVar('cid')); |
||
73 | if (\is_object($category)) { |
||
74 | $ret['category'] = $category->toArray(false); |
||
75 | } |
||
76 | } |
||
77 | |||
78 | if (0 != \count($this->getVar('aids'))) { |
||
79 | $artistsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Artists'); |
||
80 | foreach ($this->getVar('aids') as $aid) { |
||
81 | $artist = $artistsHandler->get($aid); |
||
82 | if (\is_object($artist)) { |
||
83 | $ret['artists_array'][$aid] = $artist->toArray(false); |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | |||
88 | if (0 != \count($this->getVar('sids'))) { |
||
89 | $songsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Songs'); |
||
90 | $criteria = new \Criteria('sid', '(' . \implode(',', $this->getVar('sids')) . ')', 'IN'); |
||
91 | $criteria->setSort('traxid'); |
||
92 | $criteria->setOrder('ASC'); |
||
93 | foreach ($songsHandler->getObjects($criteria, true) as $sid => $song) { |
||
94 | if (\is_object($song)) { |
||
95 | $ret['songs_array'][$sid] = $song->toArray(false); |
||
96 | } |
||
97 | } |
||
98 | } |
||
99 | |||
100 | return $ret; |
||
101 | } |
||
165 |