Conditions | 14 |
Paths | 54 |
Total Lines | 59 |
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 |
||
28 | public function saveGettextFunctions($translations, array $options) |
||
29 | { |
||
30 | $translations = is_array($translations) ? $translations : [$translations]; |
||
31 | |||
32 | /** @var Translations[] $translationByDomain [domain => translations, ..] */ |
||
33 | $translationByDomain = array_reduce($translations, function (&$carry, Translations $translations) { |
||
34 | $carry[$translations->getDomain()] = $translations; |
||
35 | return $carry; |
||
36 | }, []); |
||
37 | |||
38 | $functions = $options['functions']; |
||
39 | $file = $options['file']; |
||
40 | |||
41 | foreach ($this->getFunctions($options['constants']) as $function) { |
||
42 | list($name, $line, $args) = $function; |
||
43 | |||
44 | if (isset($options['lineOffset'])) { |
||
45 | $line += $options['lineOffset']; |
||
46 | } |
||
47 | |||
48 | if (!isset($functions[$name])) { |
||
49 | continue; |
||
50 | } |
||
51 | |||
52 | $deconstructed = $this->deconstructArgs($functions[$name], $args); |
||
53 | |||
54 | if (!$deconstructed) { |
||
55 | continue; |
||
56 | } |
||
57 | |||
58 | list($domain, $context, $original, $plural) = $deconstructed; |
||
59 | |||
60 | if ((string)$original === '') { |
||
61 | continue; |
||
62 | } |
||
63 | |||
64 | $isDefaultDomain = $domain === null; |
||
65 | |||
66 | $domainTranslations = isset($translationByDomain[$domain]) ? $translationByDomain[$domain] : false; |
||
67 | |||
68 | if (!empty($options['domainOnly']) && $isDefaultDomain) { |
||
69 | // If we want to find translations for a specific domain, skip default domain messages |
||
70 | continue; |
||
71 | } |
||
72 | |||
73 | if (!$isDefaultDomain && !$domainTranslations) { |
||
74 | continue; |
||
75 | } |
||
76 | |||
77 | $translation = $domainTranslations->insert($context, $original, $plural); |
||
78 | $translation->addReference($file, $line); |
||
79 | |||
80 | if (isset($function[3])) { |
||
81 | foreach ($function[3] as $extractedComment) { |
||
82 | $translation->addExtractedComment($extractedComment); |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | |||
168 |