| Conditions | 28 |
| Paths | 8232 |
| Total Lines | 113 |
| Code Lines | 74 |
| 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); |
||
| 56 | public function toArray($extra = true): array |
||
| 57 | { |
||
| 58 | $ret = parent::toArray(); |
||
| 59 | |||
| 60 | $GLOBALS['myts'] = MyTextSanitizer::getInstance(); |
||
| 61 | |||
| 62 | $ret['lyrics'] = $GLOBALS['myts']->displayTarea($this->getVar('lyrics'), true, true, true, true, true); |
||
| 63 | |||
| 64 | $form = $this->getForm(true); |
||
| 65 | foreach ($form as $key => $element) { |
||
| 66 | $ret['form'][$key] = $element->render(); |
||
| 67 | } |
||
| 68 | foreach (['created', 'updated'] as $key) { |
||
| 69 | if ($this->getVar($key) > 0) { |
||
| 70 | $ret['form'][$key] = \date(_DATESTRING, $this->getVar($key)); |
||
| 71 | $ret[$key] = \date(_DATESTRING, $this->getVar($key)); |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | $ret['url'] = $this->getURL(); |
||
| 76 | |||
| 77 | $ret['rank'] = \number_format(($this->getVar('rank') > 0 && $this->getVar('votes') > 0 ? $this->getVar('rank') / $this->getVar('votes') : 0), 2) . \_MI_SONGLIST_OFTEN; |
||
| 78 | |||
| 79 | if (!empty($ret['mp3'])) { |
||
| 80 | $ret['mp3'] = '<embed flashvars="playerID=1&bg=0xf8f8f8&leftbg=0x3786b3&lefticon=0x78bee3&rightbg=0x3786b3&rightbghover=0x78bee3&righticon=0x78bee3&righticonhover=0x3786b3&text=0x666666&slider=0x3786b3&track=0xcccccc&border=0x666666&loader=0x78bee3&loop=no&soundFile=' |
||
| 81 | . $ret['mp3'] |
||
| 82 | . "\" quality='high' menu='false' wmode='transparent' pluginspage='https://www.macromedia.com/go/getflashplayer' src='" |
||
| 83 | . XOOPS_URL |
||
| 84 | . "/images/form/player.swf' width=290 height=24 type='application/x-shockwave-flash'></embed>"; |
||
| 85 | } |
||
| 86 | |||
| 87 | $helper = Helper::getInstance(); |
||
| 88 | if (1 == $helper->getConfig('tags') |
||
| 89 | && \class_exists(\XoopsModules\Tag\Tagbar::class) |
||
| 90 | && \xoops_isActiveModule('tag')) { |
||
| 91 | $tagbarObj = new \XoopsModules\Tag\Tagbar(); |
||
| 92 | $ret['tagbar'] = $tagbarObj->getTagbar($this->getVar('sid'), $this->getVar('cid')); |
||
| 93 | } |
||
| 94 | |||
| 95 | $extrasHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Extras'); |
||
| 96 | $fieldHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Field'); |
||
| 97 | $visibilityHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Visibility'); |
||
| 98 | |||
| 99 | $extras = $extrasHandler->get($this->getVar('sid')); |
||
| 100 | if ($extras) { |
||
| 101 | if (\is_object($GLOBALS['xoopsUser'])) { |
||
| 102 | $fields_id = $visibilityHandler->getVisibleFields([], $GLOBALS['xoopsUser']->getGroups()); |
||
| 103 | } elseif (!\is_object($GLOBALS['xoopsUser'])) { |
||
| 104 | $fields_id = $visibilityHandler->getVisibleFields([], []); |
||
| 105 | } |
||
| 106 | |||
| 107 | if (\count($fields_id) > 0) { |
||
| 108 | $criteria = new Criteria('field_id', '(' . \implode(',', $fields_id) . ')', 'IN'); |
||
| 109 | $criteria->setSort('field_weight'); |
||
| 110 | $fields = $fieldHandler->getObjects($criteria, true); |
||
| 111 | foreach ($fields as $id => $field) { |
||
| 112 | if (\in_array($this->getVar('cid'), $field->getVar('cids'), true)) { |
||
| 113 | $ret['fields'][$id]['title'] = $field->getVar('field_title'); |
||
| 114 | if (\is_object($GLOBALS['xoopsUser'])) { |
||
| 115 | $ret['fields'][$id]['value'] = htmlspecialchars_decode($field->getOutputValue($GLOBALS['xoopsUser'], $extras)); |
||
| 116 | } elseif (!\is_object($GLOBALS['xoopsUser'])) { |
||
| 117 | $ret['fields'][$id]['value'] = htmlspecialchars_decode($extras->getVar($field->getVar('field_name'))); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | } |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | if (!$extra) { |
||
| 125 | return $ret; |
||
| 126 | } |
||
| 127 | |||
| 128 | if (0 != $this->getVar('cid')) { |
||
| 129 | $categoryHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Category'); |
||
| 130 | $category = $categoryHandler->get($this->getVar('cid')); |
||
| 131 | $ret['category'] = $category->toArray(false); |
||
| 132 | } |
||
| 133 | |||
| 134 | if (0 != \count($this->getVar('gids'))) { |
||
| 135 | $i = 0; |
||
| 136 | $genreHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Genre'); |
||
| 137 | $ret['genre'] = ''; |
||
| 138 | $genres = $genreHandler->getObjects(new Criteria('gid', '(' . \implode(',', $this->getVar('gids')) . ')', 'IN'), true); |
||
| 139 | foreach ($genres as $gid => $genre) { |
||
| 140 | $ret['genre_array'][$gid] = $genre->toArray(false); |
||
| 141 | ++$i; |
||
| 142 | $ret['genre'] .= $genre->getVar('name') . ($i < \count($genres) ? ', ' : ''); |
||
| 143 | } |
||
| 144 | } |
||
| 145 | if (0 != $this->getVar('vcid')) { |
||
| 146 | $voiceHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Voice'); |
||
| 147 | $voice = $voiceHandler->get($this->getVar('vcid')); |
||
| 148 | $ret['voice'] = $voice->toArray(false); |
||
| 149 | } |
||
| 150 | |||
| 151 | if (0 != \count($this->getVar('aids'))) { |
||
| 152 | $artistsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Artists'); |
||
| 153 | foreach ($this->getVar('aids') as $aid) { |
||
| 154 | $artist = $artistsHandler->get($aid); |
||
| 155 | $ret['artists_array'][$aid] = $artist->toArray(false); |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 159 | if (0 != $this->getVar('abid')) { |
||
| 160 | $albumsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Albums'); |
||
| 161 | $albums = $albumsHandler->get($this->getVar('abid')); |
||
| 162 | if (null !== $albums) { |
||
| 163 | $ret['albums'] = $albums->toArray(false); |
||
| 164 | } |
||
| 165 | |||
| 166 | } |
||
| 167 | |||
| 168 | return $ret; |
||
| 169 | } |
||
| 184 |