| Conditions | 67 |
| Paths | > 20000 |
| Total Lines | 188 |
| Code Lines | 127 |
| 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); |
||
| 89 | public function insert(\XoopsObject $obj, $force = true, $object = null) |
||
| 90 | { |
||
| 91 | if ($obj->isNew()) { |
||
| 92 | $new = true; |
||
| 93 | $old = $this->create(); |
||
| 94 | $obj->setVar('created', \time()); |
||
| 95 | } else { |
||
| 96 | $new = false; |
||
| 97 | $old = $this->get($obj->getVar('sid')); |
||
| 98 | $obj->setVar('updated', \time()); |
||
| 99 | } |
||
| 100 | |||
| 101 | $albumsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Albums'); |
||
| 102 | $artistsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Artists'); |
||
| 103 | $genreHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Genre'); |
||
| 104 | $voiceHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Voice'); |
||
| 105 | $categoryHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Category'); |
||
| 106 | |||
| 107 | if (true === ($obj->vars['gid']['changed']??false)) { |
||
| 108 | if ($new || (0 != $obj->vars['gid']['value'])) { |
||
| 109 | $genre = $genreHandler->get($obj->vars['gid']['value']); |
||
| 110 | if (\is_object($genre)) { |
||
| 111 | $genre->setVar('songs', $genre->getVar('songs') + 1); |
||
| 112 | $genreHandler->insert($genre, true, $obj); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | if (!$old->isNew() && $old->getVar('gid') > 0) { |
||
| 116 | $genre = $genreHandler->get($old->vars['gid']['value']); |
||
| 117 | if (\is_object($genre)) { |
||
| 118 | $genre->setVar('songs', $genre->getVar('songs') - 1); |
||
| 119 | $genreHandler->insert($genre, true, null); |
||
| 120 | } |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | if (true === $obj->vars['vcid']['changed']) { |
||
| 125 | if ($new || (0 != $obj->vars['vcid']['value'])) { |
||
| 126 | $voice = $voiceHandler->get($obj->vars['vcid']['value']); |
||
| 127 | if (\is_object($voice)) { |
||
| 128 | $voice->setVar('songs', $voice->getVar('songs') + 1); |
||
| 129 | $voiceHandler->insert($voice, true, $obj); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | if (!$old->isNew() && $old->getVar('vcid') > 0) { |
||
| 133 | $voice = $voiceHandler->get($old->vars['vcid']['value']); |
||
| 134 | if (\is_object($voice)) { |
||
| 135 | $voice->setVar('songs', $voice->getVar('songs') - 1); |
||
| 136 | $voiceHandler->insert($voice, true, null); |
||
| 137 | } |
||
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 141 | if (true === $obj->vars['cid']['changed']) { |
||
| 142 | if (true === $new || (0 != $obj->vars['cid']['value'])) { |
||
| 143 | $category = $categoryHandler->get($obj->vars['cid']['value']); |
||
| 144 | if (\is_object($category)) { |
||
| 145 | $category->setVar('songs', $category->getVar('songs') + 1); |
||
| 146 | $categoryHandler->insert($category, true, $obj); |
||
| 147 | foreach ($obj->getVar('aids') as $aid) { |
||
| 148 | $artists = $artistsHandler->get($aid); |
||
| 149 | $cids = $artists->getVar('cids'); |
||
| 150 | $cids[$obj->getVar('cid')] = $obj->getVar('cid'); |
||
| 151 | if (\is_object($artists)) { |
||
| 152 | $artists->setVar('cids', $cids); |
||
| 153 | $artistsHandler->insert($artists, true, null); |
||
| 154 | } |
||
| 155 | } |
||
| 156 | } |
||
| 157 | } |
||
| 158 | if (!$old->isNew() && $old->getVar('cid') > 0) { |
||
| 159 | $category = $categoryHandler->get($old->vars['cid']['value']); |
||
| 160 | if (\is_object($category)) { |
||
| 161 | $category->setVar('songs', $category->getVar('songs') - 1); |
||
| 162 | $categoryHandler->insert($category, true, null); |
||
| 163 | foreach ($obj->getVar('aids') as $aid) { |
||
| 164 | $artists = $artistsHandler->get($aid); |
||
| 165 | $cids = []; |
||
| 166 | foreach ($artists->getVar('cids') as $cid) { |
||
| 167 | if ($cid != $old->getVar('cid') || $cid == $obj->getVar('cid')) { |
||
| 168 | $cids[$cid] = $cid; |
||
| 169 | } |
||
| 170 | } |
||
| 171 | if (\is_object($artists)) { |
||
| 172 | $artists->setVar('cids', $cids); |
||
| 173 | $artistsHandler->insert($artists, true, null); |
||
| 174 | } |
||
| 175 | } |
||
| 176 | } |
||
| 177 | } |
||
| 178 | } |
||
| 179 | |||
| 180 | if (true === $obj->vars['aids']['changed'] && 0 != \count($obj->vars['aids']['value'])) { |
||
| 181 | if (true === $new || 0 != \count($obj->vars['aids']['value'])) { |
||
| 182 | foreach ($obj->vars['aids']['value'] as $aid) { |
||
| 183 | if (!\in_array($aid, $old->vars['aids']['value'], true)) { |
||
| 184 | $artists = $artistsHandler->get($aid); |
||
| 185 | if (\is_object($artists)) { |
||
| 186 | $artists->setVar('songs', $artists->getVar('songs') + 1); |
||
| 187 | $artistsHandler->insert($artists, true, $obj); |
||
| 188 | if (true === $new || (0 != $obj->vars['vcid']['value'])) { |
||
| 189 | $voice = $voiceHandler->get($obj->vars['vcid']['value']); |
||
| 190 | if (\is_object($voice)) { |
||
| 191 | $voice->setVar('artists', $voice->getVar('artists') + 1); |
||
| 192 | $voiceHandler->insert($voice, true, $obj); |
||
| 193 | } |
||
| 194 | } |
||
| 195 | } |
||
| 196 | } |
||
| 197 | } |
||
| 198 | } |
||
| 199 | if (!$old->isNew() && 0 == \count($old->getVar('aids'))) { |
||
| 200 | foreach ($old->getVar('aids') as $aid) { |
||
| 201 | if (!\in_array($aid, $obj->vars['aids']['value'], true)) { |
||
| 202 | $artists = $artistsHandler->get($aid); |
||
| 203 | if (\is_object($artists)) { |
||
| 204 | $artists->setVar('songs', $artists->getVar('songs') - 1); |
||
| 205 | $artistsHandler->insert($artists, true, null); |
||
| 206 | if (!$old->isNew() && $old->getVar('vcid') > 0) { |
||
| 207 | $voice = $voiceHandler->get($old->vars['vcid']['value']); |
||
| 208 | if (\is_object($voice)) { |
||
| 209 | $voice->setVar('artists', $voice->getVar('artists') - 1); |
||
| 210 | $voiceHandler->insert($voice, true, null); |
||
| 211 | } |
||
| 212 | } |
||
| 213 | } |
||
| 214 | } |
||
| 215 | } |
||
| 216 | } |
||
| 217 | } |
||
| 218 | |||
| 219 | if (true === $obj->vars['abid']['changed']) { |
||
| 220 | if (true === $new || (0 != $obj->vars['abid']['value'])) { |
||
| 221 | $album = $albumsHandler->get($obj->vars['abid']['value']); |
||
| 222 | if (\is_object($album)) { |
||
| 223 | $album->setVar('songs', $album->getVar('songs') + 1); |
||
| 224 | $albumsHandler->insert($album, true, $obj); |
||
| 225 | if (true === $new || (0 != $obj->vars['vcid']['value'])) { |
||
| 226 | $voice = $voiceHandler->get($obj->vars['vcid']['value']); |
||
| 227 | if (\is_object($voice)) { |
||
| 228 | $voice->setVar('albums', $voice->getVar('albums') + 1); |
||
| 229 | $voiceHandler->insert($voice, true, $obj); |
||
| 230 | } |
||
| 231 | } |
||
| 232 | } |
||
| 233 | } |
||
| 234 | if (!$old->isNew() && $old->getVar('abid') > 0) { |
||
| 235 | $album = $albumsHandler->get($obj->vars['abid']['value']); |
||
| 236 | if (\is_object($album)) { |
||
| 237 | $album->setVar('songs', $album->getVar('songs') - 1); |
||
| 238 | $albumsHandler->insert($album, true, null); |
||
| 239 | if (!$old->isNew() && $old->getVar('vcid') > 0) { |
||
| 240 | $voice = $voiceHandler->get($old->vars['vcid']['value']); |
||
| 241 | if (\is_object($voice)) { |
||
| 242 | $voice->setVar('albums', $voice->getVar('albums') - 1); |
||
| 243 | $voiceHandler->insert($voice, true, null); |
||
| 244 | } |
||
| 245 | } |
||
| 246 | } |
||
| 247 | } |
||
| 248 | } |
||
| 249 | |||
| 250 | if ('' == $obj->getVar('title')) { |
||
| 251 | return false; |
||
| 252 | } |
||
| 253 | |||
| 254 | $sid = parent::insert($obj, $force); |
||
| 255 | if ($obj->vars['abid']['value'] > 0) { |
||
| 256 | $album = $albumsHandler->get($obj->vars['abid']['value']); |
||
| 257 | $arry = $album->getVar('sids'); |
||
| 258 | $arry[$sid] = $sid; |
||
| 259 | if (\is_object($album)) { |
||
| 260 | $album->setVar('sids', $arry); |
||
| 261 | $albumsHandler->insert($album); |
||
| 262 | } |
||
| 263 | } |
||
| 264 | if (\count($obj->getVar('aids')) > 0) { |
||
| 265 | foreach ($obj->getVar('aids') as $aid) { |
||
| 266 | $artist = $artistsHandler->get($aid); |
||
| 267 | $arry = $artist->getVar('sids'); |
||
| 268 | $arry[$sid] = $sid; |
||
| 269 | if (\is_object($artists)) { |
||
| 270 | $artist->setVar('sids', $arry); |
||
| 271 | $artistsHandler->insert($artist); |
||
| 272 | } |
||
| 273 | } |
||
| 274 | } |
||
| 275 | |||
| 276 | return $sid; |
||
| 277 | } |
||
| 410 |