| Conditions | 1 |
| Paths | 1 |
| Total Lines | 98 |
| Lines | 98 |
| Ratio | 100 % |
| 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 namespace XoopsModules\Smartobject; |
||
| 145 | View Code Duplication | public function generateTag() |
|
|
|
|||
| 146 | { |
||
| 147 | $title = rawurlencode(strtolower($this->getVar('description', 'e'))); |
||
| 148 | $title = xoops_substr($title, 0, 10, ''); |
||
| 149 | // Transformation des ponctuations |
||
| 150 | $pattern = [ |
||
| 151 | '/%09/', // Tab |
||
| 152 | '/%20/', // Space |
||
| 153 | '/%21/', // ! |
||
| 154 | '/%22/', // " |
||
| 155 | '/%23/', // # |
||
| 156 | '/%25/', // % |
||
| 157 | '/%26/', // & |
||
| 158 | '/%27/', // ' |
||
| 159 | '/%28/', // ( |
||
| 160 | '/%29/', // ) |
||
| 161 | '/%2C/', // , |
||
| 162 | '/%2F/', // / |
||
| 163 | '/%3A/', // : |
||
| 164 | '/%3B/', // ; |
||
| 165 | '/%3C/', // < |
||
| 166 | '/%3D/', // = |
||
| 167 | '/%3E/', // > |
||
| 168 | '/%3F/', // ? |
||
| 169 | '/%40/', // @ |
||
| 170 | '/%5B/', // [ |
||
| 171 | '/%5C/', // \ |
||
| 172 | '/%5D/', // ] |
||
| 173 | '/%5E/', // ^ |
||
| 174 | '/%7B/', // { |
||
| 175 | '/%7C/', // | |
||
| 176 | '/%7D/', // } |
||
| 177 | '/%7E/', // ~ |
||
| 178 | "/\./" // . |
||
| 179 | ]; |
||
| 180 | $rep_pat = [ |
||
| 181 | '-', |
||
| 182 | '-', |
||
| 183 | '-', |
||
| 184 | '-', |
||
| 185 | '-', |
||
| 186 | '-100', |
||
| 187 | '-', |
||
| 188 | '-', |
||
| 189 | '-', |
||
| 190 | '-', |
||
| 191 | '-', |
||
| 192 | '-', |
||
| 193 | '-', |
||
| 194 | '-', |
||
| 195 | '-', |
||
| 196 | '-', |
||
| 197 | '-', |
||
| 198 | '-', |
||
| 199 | '-at-', |
||
| 200 | '-', |
||
| 201 | '-', |
||
| 202 | '-', |
||
| 203 | '-', |
||
| 204 | '-', |
||
| 205 | '-', |
||
| 206 | '-', |
||
| 207 | '-', |
||
| 208 | '-' |
||
| 209 | ]; |
||
| 210 | $title = preg_replace($pattern, $rep_pat, $title); |
||
| 211 | |||
| 212 | // Transformation des caractères accentués |
||
| 213 | $pattern = [ |
||
| 214 | '/%B0/', // ° |
||
| 215 | '/%E8/', // è |
||
| 216 | '/%E9/', // é |
||
| 217 | '/%EA/', // ê |
||
| 218 | '/%EB/', // ë |
||
| 219 | '/%E7/', // ç |
||
| 220 | '/%E0/', // à |
||
| 221 | '/%E2/', // â |
||
| 222 | '/%E4/', // ä |
||
| 223 | '/%EE/', // î |
||
| 224 | '/%EF/', // ï |
||
| 225 | '/%F9/', // ù |
||
| 226 | '/%FC/', // ü |
||
| 227 | '/%FB/', // û |
||
| 228 | '/%F4/', // ô |
||
| 229 | '/%F6/', // ö |
||
| 230 | ]; |
||
| 231 | $rep_pat = ['-', 'e', 'e', 'e', 'e', 'c', 'a', 'a', 'a', 'i', 'i', 'u', 'u', 'u', 'o', 'o']; |
||
| 232 | $title = preg_replace($pattern, $rep_pat, $title); |
||
| 233 | |||
| 234 | $tableau = explode('-', $title); // Transforme la chaine de caract�res en tableau |
||
| 235 | $tableau = array_filter($tableau, [$this, 'emptyString']); // Supprime les chaines vides du tableau |
||
| 236 | $title = implode('-', $tableau); // Transforme un tableau en chaine de caract�res s�par� par un tiret |
||
| 237 | |||
| 238 | $title .= time(); |
||
| 239 | $title = md5($title); |
||
| 240 | |||
| 241 | return $title; |
||
| 242 | } |
||
| 243 | |||
| 254 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.