Conditions | 17 |
Paths | 516 |
Total Lines | 62 |
Code Lines | 33 |
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 |
||
16 | public static function toString(Translations $translations, array $options = []) |
||
17 | { |
||
18 | $options += static::$options; |
||
19 | |||
20 | $pluralForm = $translations->getPluralForms(); |
||
21 | $pluralSize = is_array($pluralForm) ? ($pluralForm[0] - 1) : null; |
||
22 | $lines = ['msgid ""', 'msgstr ""']; |
||
23 | |||
24 | foreach ($translations->getHeaders() as $name => $value) { |
||
25 | $lines[] = sprintf('"%s: %s\\n"', $name, $value); |
||
26 | } |
||
27 | |||
28 | $lines[] = ''; |
||
29 | |||
30 | //Translations |
||
31 | foreach ($translations as $translation) { |
||
32 | if ($translation->hasComments()) { |
||
33 | foreach ($translation->getComments() as $comment) { |
||
34 | $lines[] = '# '.$comment; |
||
35 | } |
||
36 | } |
||
37 | |||
38 | if ($translation->hasExtractedComments()) { |
||
39 | foreach ($translation->getExtractedComments() as $comment) { |
||
40 | $lines[] = '#. '.$comment; |
||
41 | } |
||
42 | } |
||
43 | |||
44 | if (!$options['noLocation'] && $translation->hasReferences()) { |
||
45 | foreach ($translation->getReferences() as $reference) { |
||
46 | $lines[] = '#: '.$reference[0].(!is_null($reference[1]) ? ':'.$reference[1] : null); |
||
47 | } |
||
48 | } |
||
49 | |||
50 | if ($translation->hasFlags()) { |
||
51 | $lines[] = '#, '.implode(',', $translation->getFlags()); |
||
52 | } |
||
53 | |||
54 | $prefix = $translation->isDisabled() ? '#~ ' : ''; |
||
55 | |||
56 | if ($translation->hasContext()) { |
||
57 | $lines[] = $prefix.'msgctxt '.self::convertString($translation->getContext()); |
||
58 | } |
||
59 | |||
60 | self::addLines($lines, $prefix.'msgid', $translation->getOriginal()); |
||
61 | |||
62 | if ($translation->hasPlural()) { |
||
63 | self::addLines($lines, $prefix.'msgid_plural', $translation->getPlural()); |
||
64 | self::addLines($lines, $prefix.'msgstr[0]', $translation->getTranslation()); |
||
65 | |||
66 | foreach ($translation->getPluralTranslations($pluralSize) as $k => $v) { |
||
67 | self::addLines($lines, $prefix.'msgstr['.($k + 1).']', $v); |
||
68 | } |
||
69 | } else { |
||
70 | self::addLines($lines, $prefix.'msgstr', $translation->getTranslation()); |
||
71 | } |
||
72 | |||
73 | $lines[] = ''; |
||
74 | } |
||
75 | |||
76 | return implode("\n", $lines); |
||
77 | } |
||
78 | |||
145 |