Conditions | 10 |
Paths | 28 |
Total Lines | 37 |
Code Lines | 29 |
Lines | 10 |
Ratio | 27.03 % |
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 |
||
16 | function inflectName($fullname, $case = null, $gender = null) |
||
17 | { |
||
18 | if (in_array($case, array('m', 'f'))) { |
||
19 | $gender = $case; |
||
20 | $case = null; |
||
21 | } |
||
22 | if ($gender === null) $gender = detectGender($fullname); |
||
23 | $fullname = normalizeFullName($fullname); |
||
24 | |||
25 | $name = explode(' ', $fullname); |
||
26 | if (count($name) < 2 || count($name) > 3) { |
||
27 | return false; |
||
28 | } |
||
29 | if ($case === null) { |
||
30 | $result = array(); |
||
|
|||
31 | if (count($name) == 2) { |
||
32 | $name[0] = LastNamesInflection::getCases($name[0], $gender); |
||
33 | $name[1] = FirstNamesInflection::getCases($name[1], $gender); |
||
34 | View Code Duplication | } elseif (count($name) == 3) { |
|
35 | $name[0] = LastNamesInflection::getCases($name[0], $gender); |
||
36 | $name[1] = FirstNamesInflection::getCases($name[1], $gender); |
||
37 | $name[2] = MiddleNamesInflection::getCases($name[2], $gender); |
||
38 | } |
||
39 | return CasesHelper::composeCasesFromWords($name); |
||
40 | } else { |
||
41 | $case = CasesHelper::canonizeCase($case); |
||
42 | if (count($name) == 2) { |
||
43 | $name[0] = LastNamesInflection::getCase($name[0], $case, $gender); |
||
44 | $name[1] = FirstNamesInflection::getCase($name[1], $case, $gender); |
||
45 | View Code Duplication | } elseif (count($name) == 3) { |
|
46 | $name[0] = LastNamesInflection::getCase($name[0], $case, $gender); |
||
47 | $name[1] = FirstNamesInflection::getCase($name[1], $case, $gender); |
||
48 | $name[2] = MiddleNamesInflection::getCase($name[2], $case, $gender); |
||
49 | } |
||
50 | return implode(' ', $name); |
||
51 | } |
||
52 | } |
||
53 | |||
93 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.