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