Conditions | 10 |
Paths | 5 |
Total Lines | 26 |
Lines | 21 |
Ratio | 80.77 % |
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 |
||
26 | function RegexMatch($preg, $str = '', $csrts = true) { |
||
27 | if (empty($preg) || empty($str)) return ''; |
||
28 | $i = preg_match_all($preg, $str, $ar, PREG_SET_ORDER); |
||
29 | View Code Duplication | if (0 == $i || false === $i) |
|
|
|||
30 | // Got none match or Got error |
||
31 | $ar = ''; |
||
32 | elseif (1 == $i) |
||
33 | { |
||
34 | // Got 1 match, return as string or array(2 value in 1 match) |
||
35 | $ar = $ar[0]; |
||
36 | array_shift($ar); |
||
37 | if (1 == count($ar) && true == $csrts) |
||
38 | $ar = $ar[0]; |
||
39 | } |
||
40 | else |
||
41 | { |
||
42 | // Got more than 1 match return array contains string or sub-array |
||
43 | foreach ($ar as &$row) |
||
44 | { |
||
45 | array_shift($row); |
||
46 | if (1 == count($row)) |
||
47 | $row = $row[0]; |
||
48 | } |
||
49 | } |
||
50 | return $ar; |
||
51 | } // end of func RegexMatch |
||
52 | ?> |
||
53 |
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.