| Conditions | 12 |
| Paths | 36 |
| Total Lines | 74 |
| Code Lines | 45 |
| 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 |
||
| 57 | private function dumpXliff1($defaultLocale, MessageCatalogue $messages, $domain, array $options = array()) |
||
| 58 | { |
||
| 59 | $toolInfo = array('tool-id' => 'symfony', 'tool-name' => 'Symfony'); |
||
| 60 | if (array_key_exists('tool_info', $options)) { |
||
| 61 | $toolInfo = array_merge($toolInfo, $options['tool_info']); |
||
| 62 | } |
||
| 63 | |||
| 64 | $dom = new \DOMDocument('1.0', 'utf-8'); |
||
| 65 | $dom->formatOutput = true; |
||
| 66 | |||
| 67 | $xliff = $dom->appendChild($dom->createElement('xliff')); |
||
| 68 | $xliff->setAttribute('version', '1.2'); |
||
| 69 | $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2'); |
||
| 70 | |||
| 71 | $xliffFile = $xliff->appendChild($dom->createElement('file')); |
||
| 72 | $xliffFile->setAttribute('source-language', str_replace('_', '-', $defaultLocale)); |
||
| 73 | $xliffFile->setAttribute('target-language', str_replace('_', '-', $messages->getLocale())); |
||
| 74 | $xliffFile->setAttribute('datatype', 'plaintext'); |
||
| 75 | $xliffFile->setAttribute('original', 'file.ext'); |
||
| 76 | |||
| 77 | $xliffHead = $xliffFile->appendChild($dom->createElement('header')); |
||
| 78 | $xliffTool = $xliffHead->appendChild($dom->createElement('tool')); |
||
| 79 | foreach ($toolInfo as $id => $value) { |
||
| 80 | $xliffTool->setAttribute($id, $value); |
||
| 81 | } |
||
| 82 | |||
| 83 | $xliffBody = $xliffFile->appendChild($dom->createElement('body')); |
||
| 84 | foreach ($messages->all($domain) as $source => $target) { |
||
| 85 | $translation = $dom->createElement('trans-unit'); |
||
| 86 | |||
| 87 | // changed for phrase app |
||
| 88 | $translation->setAttribute('id', "$domain::$source"); |
||
| 89 | $translation->setAttribute('resname', $source); |
||
| 90 | |||
| 91 | $s = $translation->appendChild($dom->createElement('source')); |
||
| 92 | $s->appendChild($dom->createTextNode($source)); |
||
| 93 | |||
| 94 | // Does the target contain characters requiring a CDATA section? |
||
| 95 | $text = 1 === preg_match('/[&<>]/', $target) ? $dom->createCDATASection($target) : $dom->createTextNode($target); |
||
| 96 | |||
| 97 | $targetElement = $dom->createElement('target'); |
||
| 98 | $metadata = $messages->getMetadata($source, $domain); |
||
| 99 | if ($this->hasMetadataArrayInfo('target-attributes', $metadata)) { |
||
| 100 | foreach ($metadata['target-attributes'] as $name => $value) { |
||
| 101 | $targetElement->setAttribute($name, $value); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | $t = $translation->appendChild($targetElement); |
||
| 105 | $t->appendChild($text); |
||
| 106 | |||
| 107 | if ($this->hasMetadataArrayInfo('notes', $metadata)) { |
||
| 108 | foreach ($metadata['notes'] as $note) { |
||
| 109 | if (!isset($note['content'])) { |
||
| 110 | continue; |
||
| 111 | } |
||
| 112 | |||
| 113 | $n = $translation->appendChild($dom->createElement('note')); |
||
| 114 | $n->appendChild($dom->createTextNode($note['content'])); |
||
| 115 | |||
| 116 | if (isset($note['priority'])) { |
||
| 117 | $n->setAttribute('priority', $note['priority']); |
||
| 118 | } |
||
| 119 | |||
| 120 | if (isset($note['from'])) { |
||
| 121 | $n->setAttribute('from', $note['from']); |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | $xliffBody->appendChild($translation); |
||
| 127 | } |
||
| 128 | |||
| 129 | return $dom->saveXML(); |
||
| 130 | } |
||
| 131 | |||
| 187 |
If you suppress an error, we recommend checking for the error condition explicitly: