Conditions | 22 |
Paths | 38 |
Total Lines | 84 |
Code Lines | 50 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 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 |
||
24 | public function saveGettextFunctions(array $functions, Translations $translations, $file = '') |
||
25 | { |
||
26 | foreach ($this->getFunctions() as $function) { |
||
27 | list($name, $line, $args) = $function; |
||
28 | |||
29 | if (!isset($functions[$name])) { |
||
30 | continue; |
||
31 | } |
||
32 | |||
33 | $domain = $context = $original = $plural = $translation = null; |
||
|
|||
34 | |||
35 | switch ($functions[$name]) { |
||
36 | case 'gettext': |
||
37 | if (!isset($args[0])) { |
||
38 | continue 2; |
||
39 | } |
||
40 | |||
41 | $original = $args[0]; |
||
42 | break; |
||
43 | |||
44 | case 'ngettext': |
||
45 | if (!isset($args[1])) { |
||
46 | continue 2; |
||
47 | } |
||
48 | |||
49 | list($original, $plural) = $args; |
||
50 | break; |
||
51 | |||
52 | case 'pgettext': |
||
53 | if (!isset($args[1])) { |
||
54 | continue 2; |
||
55 | } |
||
56 | |||
57 | list($context, $original) = $args; |
||
58 | break; |
||
59 | |||
60 | case 'dgettext': |
||
61 | if (!isset($args[1])) { |
||
62 | continue 2; |
||
63 | } |
||
64 | |||
65 | list($domain, $original) = $args; |
||
66 | break; |
||
67 | |||
68 | case 'dpgettext': |
||
69 | if (!isset($args[2])) { |
||
70 | continue 2; |
||
71 | } |
||
72 | |||
73 | list($domain, $context, $original) = $args; |
||
74 | break; |
||
75 | |||
76 | case 'npgettext': |
||
77 | if (!isset($args[2])) { |
||
78 | continue 2; |
||
79 | } |
||
80 | |||
81 | list($context, $original, $plural) = $args; |
||
82 | break; |
||
83 | |||
84 | case 'dnpgettext': |
||
85 | if (!isset($args[4])) { |
||
86 | continue 2; |
||
87 | } |
||
88 | |||
89 | list($domain, $context, $original, $plural) = $args; |
||
90 | break; |
||
91 | |||
92 | default: |
||
93 | throw new Exception(sprintf('Not valid function %s', $functions[$name])); |
||
94 | } |
||
95 | |||
96 | if ((string) $original !== '' && ($domain === null || $domain === $translations->getDomain())) { |
||
97 | $translation = $translations->insert($context, $original, $plural); |
||
98 | $translation->addReference($file, $line); |
||
99 | |||
100 | if (isset($function[3])) { |
||
101 | foreach ($function[3] as $extractedComment) { |
||
102 | $translation->addExtractedComment($extractedComment); |
||
103 | } |
||
104 | } |
||
105 | } |
||
106 | } |
||
107 | } |
||
108 | } |
||
109 |
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.