| Conditions | 29 |
| Paths | 544 |
| Total Lines | 97 |
| Code Lines | 68 |
| 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 |
||
| 118 | public function store() |
||
| 119 | { |
||
| 120 | $myts = \MyTextSanitizer::getInstance(); |
||
| 121 | $title = ''; |
||
| 122 | $imgurl = ''; |
||
| 123 | if (isset($this->topic_title) && '' !== $this->topic_title) { |
||
| 124 | $title = $myts->addSlashes($this->topic_title); |
||
| 125 | } |
||
| 126 | if (isset($this->topic_imgurl) && '' !== $this->topic_imgurl) { |
||
| 127 | $imgurl = $myts->addSlashes($this->topic_imgurl); |
||
| 128 | } |
||
| 129 | if (!isset($this->topic_pid) || !\is_numeric($this->topic_pid)) { |
||
| 130 | $this->topic_pid = 0; |
||
| 131 | } |
||
| 132 | if (empty($this->topic_id)) { |
||
| 133 | $this->topic_id = $this->db->genId($this->table . '_topic_id_seq'); |
||
| 134 | $sql = \sprintf("INSERT INTO `%s` (topic_id, topic_pid, topic_imgurl, topic_title) VALUES (%u, %u, '%s', '%s')", $this->table, $this->topic_id, $this->topic_pid, $imgurl, $title); |
||
| 135 | } else { |
||
| 136 | $sql = \sprintf("UPDATE `%s` SET topic_pid = %u, topic_imgurl = '%s', topic_title = '%s' WHERE topic_id = %u", $this->table, $this->topic_pid, $imgurl, $title, $this->topic_id); |
||
| 137 | } |
||
| 138 | if (!$result = $this->db->query($sql)) { |
||
| 139 | // TODO: Replace with something else |
||
| 140 | // ErrorHandler::show('0022'); |
||
| 141 | |||
| 142 | $helper = \XoopsModules\News\Helper::getHelper($dirname); |
||
| 143 | $helper->redirect('admin/index.php', 5, $this->db->error()); |
||
| 144 | } |
||
| 145 | if (true === $this->use_permission) { |
||
| 146 | if (empty($this->topic_id)) { |
||
| 147 | $this->topic_id = $this->db->getInsertId(); |
||
| 148 | } |
||
| 149 | $xt = new \XoopsTree($this->table, 'topic_id', 'topic_pid'); |
||
| 150 | $parent_topics = $xt->getAllParentId($this->topic_id); |
||
| 151 | if (!empty($this->m_groups) && \is_array($this->m_groups)) { |
||
| 152 | foreach ($this->m_groups as $m_g) { |
||
| 153 | $moderate_topics = \XoopsPerms::getPermitted($this->mid, 'ModInTopic', $m_g); |
||
| 154 | $add = true; |
||
| 155 | // only grant this permission when the group has this permission in all parent topics of the created topic |
||
| 156 | foreach ($parent_topics as $p_topic) { |
||
| 157 | if (!\in_array($p_topic, $moderate_topics)) { |
||
| 158 | $add = false; |
||
| 159 | continue; |
||
| 160 | } |
||
| 161 | } |
||
| 162 | if (true === $add) { |
||
| 163 | $xp = new \XoopsPerms(); |
||
| 164 | $xp->setModuleId($this->mid); |
||
| 165 | $xp->setName('ModInTopic'); |
||
| 166 | $xp->setItemId($this->topic_id); |
||
| 167 | $xp->store(); |
||
| 168 | $xp->addGroup($m_g); |
||
| 169 | } |
||
| 170 | } |
||
| 171 | } |
||
| 172 | if (!empty($this->s_groups) && \is_array($this->s_groups)) { |
||
| 173 | foreach ($s_groups as $s_g) { |
||
| 174 | $submit_topics = \XoopsPerms::getPermitted($this->mid, 'SubmitInTopic', $s_g); |
||
| 175 | $add = true; |
||
| 176 | foreach ($parent_topics as $p_topic) { |
||
| 177 | if (!\in_array($p_topic, $submit_topics)) { |
||
| 178 | $add = false; |
||
| 179 | continue; |
||
| 180 | } |
||
| 181 | } |
||
| 182 | if (true === $add) { |
||
| 183 | $xp = new \XoopsPerms(); |
||
| 184 | $xp->setModuleId($this->mid); |
||
| 185 | $xp->setName('SubmitInTopic'); |
||
| 186 | $xp->setItemId($this->topic_id); |
||
| 187 | $xp->store(); |
||
| 188 | $xp->addGroup($s_g); |
||
| 189 | } |
||
| 190 | } |
||
| 191 | } |
||
| 192 | if (!empty($this->r_groups) && \is_array($this->r_groups)) { |
||
| 193 | foreach ($r_groups as $r_g) { |
||
| 194 | $read_topics = \XoopsPerms::getPermitted($this->mid, 'ReadInTopic', $r_g); |
||
| 195 | $add = true; |
||
| 196 | foreach ($parent_topics as $p_topic) { |
||
| 197 | if (!\in_array($p_topic, $read_topics)) { |
||
| 198 | $add = false; |
||
| 199 | continue; |
||
| 200 | } |
||
| 201 | } |
||
| 202 | if (true === $add) { |
||
| 203 | $xp = new \XoopsPerms(); |
||
| 204 | $xp->setModuleId($this->mid); |
||
| 205 | $xp->setName('ReadInTopic'); |
||
| 206 | $xp->setItemId($this->topic_id); |
||
| 207 | $xp->store(); |
||
| 208 | $xp->addGroup($r_g); |
||
| 209 | } |
||
| 210 | } |
||
| 211 | } |
||
| 212 | } |
||
| 213 | |||
| 214 | return true; |
||
| 215 | } |
||
| 423 |