Conditions | 16 |
Paths | 80 |
Total Lines | 112 |
Code Lines | 86 |
Lines | 0 |
Ratio | 0 % |
Changes | 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); |
||
83 | public function insert(\XoopsObject $obj, $force = true) |
||
84 | { |
||
85 | if ($obj->isNew()) { |
||
86 | $obj->setVar('created', \time()); |
||
87 | $new = true; |
||
88 | $sendmail = true; |
||
89 | } else { |
||
90 | $obj->setVar('updated', \time()); |
||
91 | $new = false; |
||
92 | if (true === $obj->vars['songid']['changed']) { |
||
93 | $songsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Songs'); |
||
94 | $criteria = new \Criteria('songid', $obj->getVar('songid')); |
||
|
|||
95 | $songs = $songsHandler->getObjects($criteria, false); |
||
96 | if (\is_object($songs[0])) { |
||
97 | foreach ($songs[0]->getVar('aids') as $aid) { |
||
98 | $ad[] = $aid; |
||
99 | } |
||
100 | $obj->setVar('sid', $songs[0]->getVar('sid')); |
||
101 | $obj->setVar('aid', $ad[0]); |
||
102 | $sendmail = true; |
||
103 | } |
||
104 | } |
||
105 | } |
||
106 | $rid = parent::insert($obj, $force); |
||
107 | if ($rid) { |
||
108 | if ($sendmail) { |
||
109 | if ($new) { |
||
110 | \xoops_loadLanguage('email', 'songlist'); |
||
111 | $xoopsMailer = \xoops_getMailer(); |
||
112 | $xoopsMailer->setHTML(true); |
||
113 | $xoopsMailer->setTemplateDir($GLOBALS['xoops']->path('/modules/songlist/language/' . $GLOBALS['xoopsConfig']['language'] . '/mail_templates/')); |
||
114 | $xoopsMailer->setTemplate('songlist_request_created.tpl'); |
||
115 | $xoopsMailer->setSubject(\sprintf(\_MD_SONGLIST_SUBJECT_REQUESTMADE, $rid)); |
||
116 | |||
117 | foreach (\explode('|', $GLOBALS['songlistModuleConfig']['email']) as $email) { |
||
118 | $xoopsMailer->setToEmails($email); |
||
119 | } |
||
120 | |||
121 | $xoopsMailer->setToEmails($obj->getVar('email')); |
||
122 | |||
123 | $xoopsMailer->assign('SITEURL', XOOPS_URL); |
||
124 | $xoopsMailer->assign('SITENAME', $GLOBALS['xoopsConfig']['sitename']); |
||
125 | $xoopsMailer->assign('RID', $rid); |
||
126 | $xoopsMailer->assign('TITLE', $obj->getVar('title')); |
||
127 | $xoopsMailer->assign('ALBUM', $obj->getVar('album')); |
||
128 | $xoopsMailer->assign('ARTIST', $obj->getVar('artist')); |
||
129 | $xoopsMailer->assign('EMAIL', $obj->getVar('email')); |
||
130 | $xoopsMailer->assign('NAME', $obj->getVar('name')); |
||
131 | |||
132 | $debug = true; |
||
133 | |||
134 | if (!$xoopsMailer->send($debug)) { |
||
135 | \xoops_error($xoopsMailer->getErrors(true), 'Email Send Error'); |
||
136 | } |
||
137 | } else { |
||
138 | \xoops_loadLanguage('email', 'songlist'); |
||
139 | $songsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Songs'); |
||
140 | $artistsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Artists'); |
||
141 | $albumsHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Albums'); |
||
142 | $genreHandler = \XoopsModules\Songlist\Helper::getInstance()->getHandler('Genre'); |
||
143 | |||
144 | $song = $songsHandler->get($obj->getVar('sid')); |
||
145 | if (\is_object($song)) { |
||
146 | $sng = $genre->getVar('title'); |
||
147 | } |
||
148 | $album = $albumHandler->get($song->getVar('abid')); |
||
149 | if (\is_object($album)) { |
||
150 | $alb = $genre->getVar('title'); |
||
151 | $alb_img = $genre->getImage(); |
||
152 | } |
||
153 | $genre = $genreHandler->get($song->getVar('abid')); |
||
154 | if (\is_object($genre)) { |
||
155 | $gen = $genre->getVar('name'); |
||
156 | } |
||
157 | $artists = $artistsHandler->getObjects(new \Criteria('aid', '(' . \implode(',', $song->getVar('aid')) . ')', 'IN'), false); |
||
158 | $art = ''; |
||
159 | foreach ($artists as $id => $artist) { |
||
160 | $art .= $artist->getVar('name') . ($id < \count($artists) - 1 ? ', ' : ''); |
||
161 | } |
||
162 | $xoopsMailer = \getMailer(); |
||
163 | $xoopsMailer->setHTML(true); |
||
164 | $xoopsMailer->setTemplateDir($GLOBALS['xoops']->path('/modules/songlist/language/' . $GLOBALS['xoopsConfig']['language'] . '/mail_templates/')); |
||
165 | $xoopsMailer->setTemplate('songlist_request_updated.tpl'); |
||
166 | $xoopsMailer->setSubject(\sprintf(\_MD_SONGLIST_SUBJECT_REQUESTFOUND, $rid)); |
||
167 | |||
168 | $xoopsMailer->setToEmails($obj->getVar('email')); |
||
169 | |||
170 | $xoopsMailer->assign('SITEURL', XOOPS_URL); |
||
171 | $xoopsMailer->assign('SITENAME', $GLOBALS['xoopsConfig']['sitename']); |
||
172 | $xoopsMailer->assign('RID', $rid); |
||
173 | $xoopsMailer->assign('TITLE', $obj->getVar('title')); |
||
174 | $xoopsMailer->assign('ALBUM', $obj->getVar('album')); |
||
175 | $xoopsMailer->assign('ARTIST', $obj->getVar('artist')); |
||
176 | $xoopsMailer->assign('EMAIL', $obj->getVar('email')); |
||
177 | $xoopsMailer->assign('NAME', $obj->getVar('name')); |
||
178 | $xoopsMailer->assign('SONGID', $song->getVar('songid')); |
||
179 | $xoopsMailer->assign('SONGURL', $song->getURL()); |
||
180 | $xoopsMailer->assign('FOUNDTITLE', $sng); |
||
181 | $xoopsMailer->assign('FOUNDALBUM', $alb); |
||
182 | $xoopsMailer->assign('FOUNDARTIST', $art); |
||
183 | $xoopsMailer->assign('FOUNDGENRE', $gen); |
||
184 | $xoopsMailer->assign('EMAIL', $obj->getVar('email')); |
||
185 | $xoopsMailer->assign('NAME', $obj->getVar('name')); |
||
186 | |||
187 | if (!$xoopsMailer->send()) { |
||
188 | \xoops_error($xoopsMailer->getErrors(true), 'Email Send Error'); |
||
189 | } |
||
190 | } |
||
191 | } |
||
192 | } |
||
193 | |||
194 | return $rid; |
||
195 | } |
||
210 |