| Conditions | 28 |
| Paths | 652 |
| Total Lines | 78 |
| Code Lines | 51 |
| 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); |
||
| 90 | public function insert(XoopsObject $obj, $force = true, $object = null) |
||
| 91 | { |
||
| 92 | if ($obj->isNew()) { |
||
| 93 | $new = true; |
||
| 94 | $old = $this->create(); |
||
| 95 | $obj->setVar('created', \time()); |
||
| 96 | } else { |
||
| 97 | $new = false; |
||
| 98 | $old = $this->get($obj->getVar('abid')); |
||
| 99 | $obj->setVar('updated', \time()); |
||
| 100 | } |
||
| 101 | |||
| 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 ($object instanceof Songs) { |
||
| 108 | if (true === $obj->vars['cid']['changed']) { |
||
| 109 | if ($obj->vars['cid']['value'] != $old->vars['cid']['value']) { |
||
| 110 | $category = $categoryHandler->get($obj->vars['cid']['value']); |
||
| 111 | if (\is_object($category)) { |
||
| 112 | $category->setVar('albums', $category->getVar('albums') + 1); |
||
| 113 | $categoryHandler->insert($category, true, $obj); |
||
| 114 | if (!$old->isNew() && $old->vars['cid']['value'] > 0) { |
||
| 115 | $category = $categoryHandler->get($old->vars['cid']['value']); |
||
| 116 | if (\is_object($category)) { |
||
| 117 | $category->setVar('albums', $category->getVar('albums') - 1); |
||
| 118 | $categoryHandler->insert($category, true, $obj); |
||
| 119 | } |
||
| 120 | } |
||
| 121 | } |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | if (is_array($obj->vars['aids']['value']) && 0 != \count($obj->vars['aids']['value']) && true === $obj->vars['aids']['changed']) { |
||
| 126 | foreach ($obj->vars['aids']['value'] as $aid) { |
||
| 127 | if (!\is_array($aid, $old->getVar('aids')) && 0 != $aid) { |
||
| 128 | $artists = $artistsHandler->get($aid); |
||
| 129 | if (\is_object($artists)) { |
||
| 130 | $artists->setVar('albums', $artists->getVar('albums') + 1); |
||
| 131 | $artistsHandler->insert($artists, true, $obj); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | } |
||
| 135 | if (!$old->isNew()) { |
||
| 136 | foreach ($old->getVar('aids') as $aid) { |
||
| 137 | if (!\is_array($aid, $obj->vars['aids']['value']) && 0 != $aid) { |
||
| 138 | $artists = $artistsHandler->get($aid); |
||
| 139 | if (\is_object($artists)) { |
||
| 140 | $artists->setVar('albums', $artists->getVar('albums') - 1); |
||
| 141 | $artistsHandler->insert($artists, true, $obj); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | } |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | if (0 != $object->vars['gid']['value']??'' && true === $object->vars['gid']['changed']??'') { |
||
| 149 | $genre = $genreHandler->get($object->vars['gid']['value']); |
||
| 150 | if (\is_object($genre)) { |
||
| 151 | $genre->setVar('albums', $genre->getVar('albums') + 1); |
||
| 152 | $genreHandler->insert($genre, true, $obj); |
||
| 153 | } |
||
| 154 | } |
||
| 155 | if (0 != $object->vars['vid']['value']??'' && true === $object->vars['vid']['changed']??'') { |
||
| 156 | $voice = $voiceHandler->get($object->vars['vid']['value']); |
||
| 157 | if (\is_object($voice)) { |
||
| 158 | $voice->setVar('albums', $voice->getVar('albums') + 1); |
||
| 159 | $voiceHandler->insert($voice, true, $obj); |
||
| 160 | } |
||
| 161 | } |
||
| 162 | } |
||
| 163 | if ('' == $obj->getVar('title')) { |
||
| 164 | return false; |
||
| 165 | } |
||
| 166 | |||
| 167 | return parent::insert($obj, $force); |
||
| 168 | } |
||
| 288 |