| Conditions | 14 |
| Paths | 130 |
| Total Lines | 58 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 2 | Features | 1 |
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 |
||
| 13 | public static function toString(Translations $translations) |
||
| 14 | { |
||
| 15 | $lines = array('msgid ""', 'msgstr ""'); |
||
| 16 | |||
| 17 | $headers = $translations->getHeaders(); |
||
| 18 | $headers['PO-Revision-Date'] = date('c'); |
||
| 19 | |||
| 20 | foreach ($headers as $name => $value) { |
||
| 21 | $lines[] = '"'.$name.': '.$value.'\\n"'; |
||
| 22 | } |
||
| 23 | |||
| 24 | $lines[] = ''; |
||
| 25 | |||
| 26 | //Translations |
||
| 27 | foreach ($translations as $translation) { |
||
| 28 | if ($translation->hasComments()) { |
||
| 29 | foreach ($translation->getComments() as $comment) { |
||
| 30 | $lines[] = '# '.$comment; |
||
| 31 | } |
||
| 32 | } |
||
| 33 | |||
| 34 | if ($translation->hasExtractedComments()) { |
||
| 35 | foreach ($translation->getExtractedComments() as $comment) { |
||
| 36 | $lines[] = '#. '.$comment; |
||
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | if ($translation->hasReferences()) { |
||
| 41 | foreach ($translation->getReferences() as $reference) { |
||
| 42 | $lines[] = '#: '.$reference[0].(!is_null($reference[1]) ? ':'.$reference[1] : null); |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | if ($translation->hasFlags()) { |
||
| 47 | $lines[] = '#, '.implode(',', $translation->getFlags()); |
||
| 48 | } |
||
| 49 | |||
| 50 | if ($translation->hasContext()) { |
||
| 51 | $lines[] = 'msgctxt '.Strings::toPo($translation->getContext()); |
||
| 52 | } |
||
| 53 | |||
| 54 | self::addLines($lines, 'msgid', $translation->getOriginal()); |
||
| 55 | if ($translation->hasPlural()) { |
||
| 56 | self::addLines($lines, 'msgid_plural', $translation->getPlural()); |
||
| 57 | self::addLines($lines, 'msgstr[0]', $translation->getTranslation()); |
||
| 58 | |||
| 59 | foreach ($translation->getPluralTranslation() as $k => $v) { |
||
| 60 | self::addLines($lines, 'msgstr['.($k + 1).']', $v); |
||
| 61 | } |
||
| 62 | } else { |
||
| 63 | self::addLines($lines, 'msgstr', $translation->getTranslation()); |
||
| 64 | } |
||
| 65 | |||
| 66 | $lines[] = ''; |
||
| 67 | } |
||
| 68 | |||
| 69 | return implode("\n", $lines); |
||
| 70 | } |
||
| 71 | |||
| 117 |