Conditions | 28 |
Paths | 131 |
Total Lines | 114 |
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 |
||
26 | public function saveGettextFunctions(Translations $translations, array $options) |
||
27 | { |
||
28 | $functions = $options['functions']; |
||
29 | $file = $options['file']; |
||
30 | |||
31 | foreach ($this->getFunctions($options['constants']) as $function) { |
||
32 | list($name, $line, $args) = $function; |
||
33 | |||
34 | if (isset($options['lineOffset'])) { |
||
35 | $line += $options['lineOffset']; |
||
36 | } |
||
37 | |||
38 | if (!isset($functions[$name])) { |
||
39 | continue; |
||
40 | } |
||
41 | |||
42 | $domain = $context = $original = $plural = null; |
||
43 | |||
44 | switch ($functions[$name]) { |
||
45 | case 'noop': |
||
46 | case 'gettext': |
||
47 | if (!isset($args[0])) { |
||
48 | continue 2; |
||
49 | } |
||
50 | |||
51 | $original = $args[0]; |
||
52 | break; |
||
53 | |||
54 | case 'ngettext': |
||
55 | if (!isset($args[1])) { |
||
56 | continue 2; |
||
57 | } |
||
58 | |||
59 | list($original, $plural) = $args; |
||
60 | break; |
||
61 | |||
62 | case 'pgettext': |
||
63 | if (!isset($args[1])) { |
||
64 | continue 2; |
||
65 | } |
||
66 | |||
67 | list($context, $original) = $args; |
||
68 | break; |
||
69 | |||
70 | case 'dgettext': |
||
71 | if (!isset($args[1])) { |
||
72 | continue 2; |
||
73 | } |
||
74 | |||
75 | list($domain, $original) = $args; |
||
76 | break; |
||
77 | |||
78 | case 'dpgettext': |
||
79 | if (!isset($args[2])) { |
||
80 | continue 2; |
||
81 | } |
||
82 | |||
83 | list($domain, $context, $original) = $args; |
||
84 | break; |
||
85 | |||
86 | case 'npgettext': |
||
87 | if (!isset($args[2])) { |
||
88 | continue 2; |
||
89 | } |
||
90 | |||
91 | list($context, $original, $plural) = $args; |
||
92 | break; |
||
93 | |||
94 | case 'dnpgettext': |
||
95 | if (!isset($args[3])) { |
||
96 | continue 2; |
||
97 | } |
||
98 | |||
99 | list($domain, $context, $original, $plural) = $args; |
||
100 | break; |
||
101 | |||
102 | case 'dngettext': |
||
103 | if (!isset($args[2])) { |
||
104 | continue 2; |
||
105 | } |
||
106 | |||
107 | list($domain, $original, $plural) = $args; |
||
108 | break; |
||
109 | |||
110 | default: |
||
111 | throw new Exception(sprintf('Not valid function %s', $functions[$name])); |
||
112 | } |
||
113 | |||
114 | if ((string)$original === '') { |
||
115 | continue; |
||
116 | } |
||
117 | |||
118 | $isDefaultDomain = $domain === null; |
||
119 | $isMatchingDomain = $domain === $translations->getDomain(); |
||
120 | |||
121 | if (!empty($options['domainOnly']) && $isDefaultDomain) { |
||
122 | // If we want to find translations for a specific domain, skip default domain messages |
||
123 | continue; |
||
124 | } |
||
125 | |||
126 | if (!$isDefaultDomain && !$isMatchingDomain) { |
||
127 | continue; |
||
128 | } |
||
129 | |||
130 | $translation = $translations->insert($context, $original, $plural); |
||
131 | $translation->addReference($file, $line); |
||
132 | |||
133 | if (isset($function[3])) { |
||
134 | foreach ($function[3] as $extractedComment) { |
||
135 | $translation->addExtractedComment($extractedComment); |
||
136 | } |
||
137 | } |
||
138 | } |
||
139 | } |
||
140 | } |
||
141 |