| Conditions | 7 |
| Paths | 14 |
| Total Lines | 89 |
| Code Lines | 80 |
| 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 |
||
| 79 | public function insert(\XoopsObject $msg, $force = true) |
||
| 80 | { |
||
| 81 | if (Message::class !== \get_class($msg)) { |
||
| 82 | return false; |
||
| 83 | } |
||
| 84 | if (!$msg->cleanVars()) { |
||
| 85 | return false; |
||
| 86 | } |
||
| 87 | foreach ($msg->cleanVars as $k => $v) { |
||
| 88 | ${$k} = $v; |
||
| 89 | } |
||
| 90 | if (empty($msg_id)) { |
||
| 91 | $msg_id = $this->db->genId('xfguestbook_msg_msg_id_seq'); |
||
| 92 | $sql = 'INSERT INTO ' |
||
| 93 | . $this->db->prefix('xfguestbook_msg') |
||
| 94 | . ' (msg_id, user_id, uname, title, message, note, post_time, email, url, poster_ip, moderate, gender, country, photo, flagdir, other) VALUES (' |
||
| 95 | . $msg_id |
||
| 96 | . ',' |
||
| 97 | . $user_id |
||
| 98 | . ', ' |
||
| 99 | . $this->db->quoteString($uname) |
||
| 100 | . ', ' |
||
| 101 | . $this->db->quoteString($title) |
||
| 102 | . ', ' |
||
| 103 | . $this->db->quoteString($message) |
||
| 104 | . ', ' |
||
| 105 | . $this->db->quoteString($note) |
||
| 106 | . ', ' |
||
| 107 | . $post_time |
||
| 108 | . ', ' |
||
| 109 | . $this->db->quoteString($email) |
||
| 110 | . ', ' |
||
| 111 | . $this->db->quoteString($url) |
||
| 112 | . ', ' |
||
| 113 | . $this->db->quoteString($poster_ip) |
||
| 114 | . ', ' |
||
| 115 | . $moderate |
||
| 116 | . ', ' |
||
| 117 | . $this->db->quoteString($gender) |
||
| 118 | . ', ' |
||
| 119 | . $this->db->quoteString($country) |
||
| 120 | . ', ' |
||
| 121 | . $this->db->quoteString($photo) |
||
| 122 | . ', ' |
||
| 123 | . $this->db->quoteString($flagdir) |
||
| 124 | . ', ' |
||
| 125 | . $this->db->quoteString($other) |
||
| 126 | . ')'; |
||
| 127 | } else { |
||
| 128 | $sql = 'UPDATE ' |
||
| 129 | . $this->db->prefix('xfguestbook_msg') |
||
| 130 | . ' SET user_id=' |
||
| 131 | . $user_id |
||
| 132 | . ', uname=' |
||
| 133 | . $this->db->quoteString($uname) |
||
| 134 | . ', title=' |
||
| 135 | . $this->db->quoteString($title) |
||
| 136 | . ', message=' |
||
| 137 | . $this->db->quoteString($message) |
||
| 138 | . ', note=' |
||
| 139 | . $this->db->quoteString($note) |
||
| 140 | . ', email=' |
||
| 141 | . $this->db->quoteString($email) |
||
| 142 | . ', url=' |
||
| 143 | . $this->db->quoteString($url) |
||
| 144 | . ', moderate=' |
||
| 145 | . $moderate |
||
| 146 | . ', gender=' |
||
| 147 | . $this->db->quoteString($gender) |
||
| 148 | . ', country=' |
||
| 149 | . $this->db->quoteString($country) |
||
| 150 | . ', photo=' |
||
| 151 | . $this->db->quoteString($photo) |
||
| 152 | . ', flagdir=' |
||
| 153 | . $this->db->quoteString($flagdir) |
||
| 154 | . ', other=' |
||
| 155 | . $this->db->quoteString($other) |
||
| 156 | . ' WHERE msg_id=' |
||
| 157 | . $msg_id; |
||
| 158 | } |
||
| 159 | if (!$result = $this->db->queryF($sql)) { |
||
| 160 | return false; |
||
| 161 | } |
||
| 162 | if (empty($msg_id)) { |
||
| 163 | $msg_id = $this->db->getInsertId(); |
||
| 164 | } |
||
| 165 | $msg->assignVar('msg_id', $msg_id); |
||
| 166 | |||
| 167 | return $msg_id; |
||
| 168 | } |
||
| 309 |