@@ -9,12 +9,12 @@ discard block |
||
9 | 9 | /** |
10 | 10 | * @var array |
11 | 11 | */ |
12 | - private static $versions_1 = [ '1.0', '1.1', '1.2' ]; |
|
12 | + private static $versions_1 = ['1.0', '1.1', '1.2']; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * @var array |
16 | 16 | */ |
17 | - private static $versions_2 = [ '2.0', '2.1' ]; |
|
17 | + private static $versions_2 = ['2.0', '2.1']; |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @param string $xliffContent |
@@ -23,16 +23,16 @@ discard block |
||
23 | 23 | * @throws NotSupportedVersionException |
24 | 24 | * @throws NotValidFileException |
25 | 25 | */ |
26 | - public static function detect( $xliffContent ) { |
|
27 | - preg_match( '|<xliff.*?\sversion\s?=\s?["\'](.*?)["\']|si', substr( $xliffContent, 0, 1000 ), $versionMatches ); |
|
26 | + public static function detect($xliffContent) { |
|
27 | + preg_match('|<xliff.*?\sversion\s?=\s?["\'](.*?)["\']|si', substr($xliffContent, 0, 1000), $versionMatches); |
|
28 | 28 | |
29 | - if ( empty( $versionMatches ) ) { |
|
30 | - throw new NotValidFileException( 'This is not a valid xliff file' ); |
|
29 | + if (empty($versionMatches)) { |
|
30 | + throw new NotValidFileException('This is not a valid xliff file'); |
|
31 | 31 | } |
32 | 32 | |
33 | - $version = $versionMatches[ 1 ]; |
|
33 | + $version = $versionMatches[1]; |
|
34 | 34 | |
35 | - return self::resolveVersion( $version ); |
|
35 | + return self::resolveVersion($version); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -41,15 +41,15 @@ discard block |
||
41 | 41 | * @return int |
42 | 42 | * @throws NotSupportedVersionException |
43 | 43 | */ |
44 | - private static function resolveVersion( $version ) { |
|
45 | - if ( in_array( $version, self::$versions_1 ) ) { |
|
44 | + private static function resolveVersion($version) { |
|
45 | + if (in_array($version, self::$versions_1)) { |
|
46 | 46 | return 1; |
47 | 47 | } |
48 | 48 | |
49 | - if ( in_array( $version, self::$versions_2 ) ) { |
|
49 | + if (in_array($version, self::$versions_2)) { |
|
50 | 50 | return 2; |
51 | 51 | } |
52 | 52 | |
53 | - throw new NotSupportedVersionException( 'Not supported version' ); |
|
53 | + throw new NotSupportedVersionException('Not supported version'); |
|
54 | 54 | } |
55 | 55 | } |
@@ -18,13 +18,13 @@ |
||
18 | 18 | * |
19 | 19 | * @return SdlXliffSAXTranslationReplacer|XliffSAXTranslationReplacer |
20 | 20 | */ |
21 | - public static function getInstance( $originalXliffPath, &$data, &$transUnits, $targetLang, $outputFilePath, $setSourceInTarget, LoggerInterface $logger = null, XliffReplacerCallbackInterface $callback = null ) { |
|
22 | - $info = XliffProprietaryDetect::getInfo( $originalXliffPath ); |
|
21 | + public static function getInstance($originalXliffPath, &$data, &$transUnits, $targetLang, $outputFilePath, $setSourceInTarget, LoggerInterface $logger = null, XliffReplacerCallbackInterface $callback = null) { |
|
22 | + $info = XliffProprietaryDetect::getInfo($originalXliffPath); |
|
23 | 23 | |
24 | - if ( $info[ 'proprietary_short_name' ] !== 'trados' ) { |
|
25 | - return new XliffSAXTranslationReplacer( $originalXliffPath, $info[ 'version' ], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback ); |
|
24 | + if ($info['proprietary_short_name'] !== 'trados') { |
|
25 | + return new XliffSAXTranslationReplacer($originalXliffPath, $info['version'], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback); |
|
26 | 26 | } |
27 | 27 | |
28 | - return new SdlXliffSAXTranslationReplacer( $originalXliffPath, $info[ 'version' ], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback ); |
|
28 | + return new SdlXliffSAXTranslationReplacer($originalXliffPath, $info['version'], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback); |
|
29 | 29 | } |
30 | 30 | } |
@@ -8,14 +8,14 @@ |
||
8 | 8 | * https://stackoverflow.com/questions/11427398/how-to-implode-array-with-key-and-value-without-foreach-in-php |
9 | 9 | */ |
10 | 10 | class FlatData { |
11 | - public static function flatArray( array $input = [], $separator_elements = ', ', $separator = ': ' ) { |
|
12 | - return implode( $separator_elements, array_map( |
|
13 | - function ( $v, $k, $s ) { |
|
14 | - return sprintf( "%s{$s}\"%s\"", $k, $v ); |
|
11 | + public static function flatArray(array $input = [], $separator_elements = ', ', $separator = ': ') { |
|
12 | + return implode($separator_elements, array_map( |
|
13 | + function($v, $k, $s) { |
|
14 | + return sprintf("%s{$s}\"%s\"", $k, $v); |
|
15 | 15 | }, |
16 | 16 | $input, |
17 | - array_keys( $input ), |
|
18 | - array_fill( 0, count( $input ), $separator ) |
|
19 | - ) ); |
|
17 | + array_keys($input), |
|
18 | + array_fill(0, count($input), $separator) |
|
19 | + )); |
|
20 | 20 | } |
21 | 21 | } |
@@ -12,10 +12,10 @@ |
||
12 | 12 | * |
13 | 13 | * @return AbstractXliffParser |
14 | 14 | */ |
15 | - public static function getInstance( $xliffVersion, $xliffProprietary = null, LoggerInterface $logger = null ) { |
|
15 | + public static function getInstance($xliffVersion, $xliffProprietary = null, LoggerInterface $logger = null) { |
|
16 | 16 | $parserClass = 'Matecat\\XliffParser\\XliffParser\\XliffParserV' . $xliffVersion; |
17 | 17 | |
18 | 18 | /** @var AbstractXliffParser $parser */ |
19 | - return new $parserClass( $xliffVersion, $xliffProprietary, $logger ); |
|
19 | + return new $parserClass($xliffVersion, $xliffProprietary, $logger); |
|
20 | 20 | } |
21 | 21 | } |
@@ -11,5 +11,5 @@ |
||
11 | 11 | * @param null $error |
12 | 12 | * @return bool |
13 | 13 | */ |
14 | - public function thereAreErrors( $segmentId, $segment, $translation, array $dataRefMap = [], $error = null ); |
|
14 | + public function thereAreErrors($segmentId, $segment, $translation, array $dataRefMap = [], $error = null); |
|
15 | 15 | } |
@@ -10,22 +10,22 @@ discard block |
||
10 | 10 | /** |
11 | 11 | * @inheritDoc |
12 | 12 | */ |
13 | - protected function tagOpen( $parser, $name, $attr ) { |
|
13 | + protected function tagOpen($parser, $name, $attr) { |
|
14 | 14 | // check if we are entering into a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*) |
15 | - if ( $this->tuTagName === $name ) { |
|
15 | + if ($this->tuTagName === $name) { |
|
16 | 16 | $this->inTU = true; |
17 | 17 | |
18 | 18 | // get id |
19 | 19 | // trim to first 100 characters because this is the limit on Matecat's DB |
20 | - $this->currentTransUnitId = substr( $attr[ 'id' ], 0, 100 ); |
|
20 | + $this->currentTransUnitId = substr($attr['id'], 0, 100); |
|
21 | 21 | |
22 | 22 | // current 'translate' attribute of the current trans-unit |
23 | - $this->currentTransUnitTranslate = isset( $attr[ 'translate' ] ) ? $attr[ 'translate' ] : 'yes'; |
|
23 | + $this->currentTransUnitTranslate = isset($attr['translate']) ? $attr['translate'] : 'yes'; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | // check if we are entering into a <target> |
27 | - if ( 'target' == $name ) { |
|
28 | - if ( $this->currentTransUnitTranslate === 'no' ) { |
|
27 | + if ('target' == $name) { |
|
28 | + if ($this->currentTransUnitTranslate === 'no') { |
|
29 | 29 | $this->inTarget = false; |
30 | 30 | } else { |
31 | 31 | $this->inTarget = true; |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | } |
34 | 34 | |
35 | 35 | // reset Marker positions |
36 | - if ( 'sdl:seg-defs' == $name ) { |
|
36 | + if ('sdl:seg-defs' == $name) { |
|
37 | 37 | $this->markerPos = 0; |
38 | 38 | } |
39 | 39 | |
40 | 40 | // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit |
41 | 41 | // <target> must be stripped to be replaced, so this check avoids <target> reconstruction |
42 | - if ( !$this->inTarget ) { |
|
42 | + if (!$this->inTarget) { |
|
43 | 43 | |
44 | 44 | // costruct tag |
45 | 45 | $tag = "<$name "; |
@@ -49,23 +49,23 @@ discard block |
||
49 | 49 | // so the check on it's name is not enough |
50 | 50 | $_sdlStatus_confWritten = false; |
51 | 51 | |
52 | - foreach ( $attr as $k => $v ) { |
|
52 | + foreach ($attr as $k => $v) { |
|
53 | 53 | |
54 | 54 | // if tag name is file, we must replace the target-language attribute |
55 | - if ( $name == 'file' && $k == 'target-language' && !empty( $this->targetLang ) ) { |
|
55 | + if ($name == 'file' && $k == 'target-language' && !empty($this->targetLang)) { |
|
56 | 56 | //replace Target language with job language provided from constructor |
57 | 57 | $tag .= "$k=\"$this->targetLang\" "; |
58 | 58 | |
59 | - if ( null !== $this->logger ) { |
|
60 | - $this->logger->debug( $k . " => " . $this->targetLang ); |
|
59 | + if (null !== $this->logger) { |
|
60 | + $this->logger->debug($k . " => " . $this->targetLang); |
|
61 | 61 | } |
62 | - } elseif ( 'sdl:seg' == $name ) { |
|
62 | + } elseif ('sdl:seg' == $name) { |
|
63 | 63 | |
64 | 64 | // write the confidence level for this segment ( Translated, Draft, etc. ) |
65 | - if ( isset( $this->segments[ 'matecat|' . $this->currentTransUnitId ] ) && $_sdlStatus_confWritten === false ) { |
|
65 | + if (isset($this->segments['matecat|' . $this->currentTransUnitId]) && $_sdlStatus_confWritten === false) { |
|
66 | 66 | |
67 | 67 | // append definition attribute |
68 | - $tag .= $this->prepareTargetStatuses( $this->lastTransUnit[ $this->markerPos ] ); |
|
68 | + $tag .= $this->prepareTargetStatuses($this->lastTransUnit[$this->markerPos]); |
|
69 | 69 | |
70 | 70 | //prepare for an eventual next cycle |
71 | 71 | $this->markerPos++; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | } |
74 | 74 | |
75 | 75 | // Warning, this is NOT an elseif |
76 | - if ( $k != 'conf' ) { |
|
76 | + if ($k != 'conf') { |
|
77 | 77 | //put also the current attribute in it if it is not a "conf" attribute |
78 | 78 | $tag .= "$k=\"$v\" "; |
79 | 79 | } |
@@ -86,29 +86,29 @@ discard block |
||
86 | 86 | // this logic helps detecting empty tags |
87 | 87 | // get current position of SAX pointer in all the stream of data is has read so far: |
88 | 88 | // it points at the end of current tag |
89 | - $idx = xml_get_current_byte_index( $parser ); |
|
89 | + $idx = xml_get_current_byte_index($parser); |
|
90 | 90 | |
91 | 91 | // check whether the bounds of current tag are entirely in current buffer || the end of the current tag |
92 | 92 | // is outside current buffer (in the latter case, it's in next buffer to be read by the while loop); |
93 | 93 | // this check is necessary because we may have truncated a tag in half with current read, |
94 | 94 | // and the other half may be encountered in the next buffer it will be passed |
95 | - if ( isset( $this->currentBuffer[ $idx - $this->offset ] ) ) { |
|
95 | + if (isset($this->currentBuffer[$idx - $this->offset])) { |
|
96 | 96 | // if this tag entire lenght fitted in the buffer, the last char must be the last |
97 | 97 | // symbol before the '>'; if it's an empty tag, it is assumed that it's a '/' |
98 | 98 | $tmp_offset = $idx - $this->offset; |
99 | - $lastChar = $this->currentBuffer[ $tmp_offset ]; |
|
99 | + $lastChar = $this->currentBuffer[$tmp_offset]; |
|
100 | 100 | } else { |
101 | 101 | //if it's out, simple use the last character of the chunk |
102 | 102 | $tmp_offset = $this->len - 1; |
103 | - $lastChar = $this->currentBuffer[ $tmp_offset ]; |
|
103 | + $lastChar = $this->currentBuffer[$tmp_offset]; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | // trim last space |
107 | - $tag = rtrim( $tag ); |
|
107 | + $tag = rtrim($tag); |
|
108 | 108 | |
109 | 109 | // detect empty tag |
110 | - $this->isEmpty = ( $lastChar == '/' || $name == 'x' ); |
|
111 | - if ( $this->isEmpty ) { |
|
110 | + $this->isEmpty = ($lastChar == '/' || $name == 'x'); |
|
111 | + if ($this->isEmpty) { |
|
112 | 112 | $tag .= '/'; |
113 | 113 | } |
114 | 114 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | $tag .= ">"; |
117 | 117 | |
118 | 118 | // set a a Buffer for the segSource Source tag |
119 | - if ( 'source' == $name |
|
119 | + if ('source' == $name |
|
120 | 120 | || 'seg-source' === $name |
121 | 121 | || $this->bufferIsActive |
122 | 122 | || 'value' === $name |
@@ -125,19 +125,19 @@ discard block |
||
125 | 125 | || 'ph' === $name |
126 | 126 | || 'st' === $name |
127 | 127 | || 'note' === $name |
128 | - || 'context' === $name ) { // we are opening a critical CDATA section |
|
128 | + || 'context' === $name) { // we are opening a critical CDATA section |
|
129 | 129 | |
130 | 130 | // WARNING BECAUSE SOURCE AND SEG-SOURCE TAGS CAN BE EMPTY IN SOME CASES!!!!! |
131 | 131 | // so check for isEmpty also in conjunction with name |
132 | - if ( $this->isEmpty && ( 'source' == $name || 'seg-source' == $name ) ) { |
|
133 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
132 | + if ($this->isEmpty && ('source' == $name || 'seg-source' == $name)) { |
|
133 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
134 | 134 | } else { |
135 | 135 | //these are NOT source/seg-source/value empty tags, THERE IS A CONTENT, write it in buffer |
136 | 136 | $this->bufferIsActive = true; |
137 | - $this->CDATABuffer .= $tag; |
|
137 | + $this->CDATABuffer .= $tag; |
|
138 | 138 | } |
139 | 139 | } else { |
140 | - $this->postProcAndFlush( $this->outputFP, $tag ); |
|
140 | + $this->postProcAndFlush($this->outputFP, $tag); |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | } |
@@ -150,19 +150,19 @@ discard block |
||
150 | 150 | * |
151 | 151 | * @return string |
152 | 152 | */ |
153 | - protected function prepareTranslation( $seg, $transUnitTranslation = "" ) { |
|
153 | + protected function prepareTranslation($seg, $transUnitTranslation = "") { |
|
154 | 154 | $endTags = ""; |
155 | 155 | |
156 | - $segment = Strings::removeDangerousChars( $seg [ 'segment' ] ); |
|
157 | - $translation = Strings::removeDangerousChars( $seg [ 'translation' ] ); |
|
158 | - $dataRefMap = ( isset( $seg[ 'data_ref_map' ] ) && $seg[ 'data_ref_map' ] !== null ) ? Strings::jsonToArray( $seg[ 'data_ref_map' ] ) : []; |
|
156 | + $segment = Strings::removeDangerousChars($seg ['segment']); |
|
157 | + $translation = Strings::removeDangerousChars($seg ['translation']); |
|
158 | + $dataRefMap = (isset($seg['data_ref_map']) && $seg['data_ref_map'] !== null) ? Strings::jsonToArray($seg['data_ref_map']) : []; |
|
159 | 159 | |
160 | - if ( is_null( $seg [ 'translation' ] ) || $seg [ 'translation' ] == '' ) { |
|
160 | + if (is_null($seg ['translation']) || $seg ['translation'] == '') { |
|
161 | 161 | $translation = $segment; |
162 | 162 | } else { |
163 | - if ( $this->callback instanceof XliffReplacerCallbackInterface ) { |
|
163 | + if ($this->callback instanceof XliffReplacerCallbackInterface) { |
|
164 | 164 | $error = (isset($seg['error'])) ? $seg['error'] : null; |
165 | - if ( $this->callback->thereAreErrors( $seg[ 'sid' ], $segment, $translation, $dataRefMap, $error ) ) { |
|
165 | + if ($this->callback->thereAreErrors($seg['sid'], $segment, $translation, $dataRefMap, $error)) { |
|
166 | 166 | $translation = '|||UNTRANSLATED_CONTENT_START|||' . $segment . '|||UNTRANSLATED_CONTENT_END|||'; |
167 | 167 | } |
168 | 168 | } |
@@ -171,20 +171,20 @@ discard block |
||
171 | 171 | // for Trados the trailing spaces after </mrk> are meaningful |
172 | 172 | // so we trim the translation from Matecat DB and add them after </mrk> |
173 | 173 | $trailingSpaces = ''; |
174 | - for ( $s = 0; $s < Strings::getTheNumberOfTrailingSpaces( $translation ); $s++ ) { |
|
174 | + for ($s = 0; $s < Strings::getTheNumberOfTrailingSpaces($translation); $s++) { |
|
175 | 175 | $trailingSpaces .= ' '; |
176 | 176 | } |
177 | 177 | |
178 | - if ( $seg[ 'mrk_id' ] !== null && $seg[ 'mrk_id' ] != '' ) { |
|
179 | - if ( $this->targetLang === 'ja-JP' ) { |
|
180 | - $seg[ 'mrk_succ_tags' ] = ltrim( $seg[ 'mrk_succ_tags' ] ); |
|
178 | + if ($seg['mrk_id'] !== null && $seg['mrk_id'] != '') { |
|
179 | + if ($this->targetLang === 'ja-JP') { |
|
180 | + $seg['mrk_succ_tags'] = ltrim($seg['mrk_succ_tags']); |
|
181 | 181 | } |
182 | 182 | |
183 | - $translation = "<mrk mid=\"" . $seg[ 'mrk_id' ] . "\" mtype=\"seg\">" . $seg[ 'mrk_prev_tags' ] . rtrim( $translation ) . $seg[ 'mrk_succ_tags' ] . "</mrk>" . $trailingSpaces; |
|
183 | + $translation = "<mrk mid=\"" . $seg['mrk_id'] . "\" mtype=\"seg\">" . $seg['mrk_prev_tags'] . rtrim($translation) . $seg['mrk_succ_tags'] . "</mrk>" . $trailingSpaces; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | // we need to trim succ_tags here because we already added the trailing spaces after </mrk> |
187 | - $transUnitTranslation .= $seg[ 'prev_tags' ] . $translation . $endTags . ltrim( $seg[ 'succ_tags' ] ); |
|
187 | + $transUnitTranslation .= $seg['prev_tags'] . $translation . $endTags . ltrim($seg['succ_tags']); |
|
188 | 188 | |
189 | 189 | return $transUnitTranslation; |
190 | 190 | } |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | * |
195 | 195 | * @return string |
196 | 196 | */ |
197 | - protected function prepareTargetStatuses( $segment ) { |
|
197 | + protected function prepareTargetStatuses($segment) { |
|
198 | 198 | $statusMap = [ |
199 | 199 | 'NEW' => '', |
200 | 200 | 'DRAFT' => 'Draft', |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | 'REJECTED' => 'RejectedTranslation', |
204 | 204 | ]; |
205 | 205 | |
206 | - return "conf=\"{$statusMap[ $segment[ 'status' ] ]}\" "; |
|
206 | + return "conf=\"{$statusMap[$segment['status']]}\" "; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | * |
214 | 214 | * @return array |
215 | 215 | */ |
216 | - protected function setTransUnitState( $seg, $state_prop, $lastMrkState ) { |
|
217 | - return [ null, null ]; |
|
216 | + protected function setTransUnitState($seg, $state_prop, $lastMrkState) { |
|
217 | + return [null, null]; |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | * |
224 | 224 | * @return string |
225 | 225 | */ |
226 | - protected function getWordCountGroup( $raw_word_count, $eq_word_count ) { |
|
226 | + protected function getWordCountGroup($raw_word_count, $eq_word_count) { |
|
227 | 227 | return ''; |
228 | 228 | } |
229 | 229 | } |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | * @return string |
18 | 18 | * @throws Exception |
19 | 19 | */ |
20 | - public static function cleanCDATA( $testString ) { |
|
21 | - $cleanXMLContent = new SimpleXMLElement( '<rootNoteNode>' . $testString . '</rootNoteNode>', LIBXML_NOCDATA ); |
|
20 | + public static function cleanCDATA($testString) { |
|
21 | + $cleanXMLContent = new SimpleXMLElement('<rootNoteNode>' . $testString . '</rootNoteNode>', LIBXML_NOCDATA); |
|
22 | 22 | |
23 | 23 | return $cleanXMLContent->__toString(); |
24 | 24 | } |
@@ -28,28 +28,28 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return bool |
30 | 30 | */ |
31 | - public static function isJSON( $string ) { |
|
32 | - if ( is_numeric( $string ) ) { |
|
31 | + public static function isJSON($string) { |
|
32 | + if (is_numeric($string)) { |
|
33 | 33 | return false; |
34 | 34 | } |
35 | 35 | |
36 | 36 | try { |
37 | - $string = Strings::cleanCDATA( $string ); |
|
38 | - } catch ( Exception $e ) { |
|
37 | + $string = Strings::cleanCDATA($string); |
|
38 | + } catch (Exception $e) { |
|
39 | 39 | return false; |
40 | 40 | } |
41 | 41 | |
42 | - $string = trim( $string ); |
|
43 | - if ( empty( $string ) ) { |
|
42 | + $string = trim($string); |
|
43 | + if (empty($string)) { |
|
44 | 44 | return false; |
45 | 45 | } |
46 | 46 | |
47 | 47 | // String representation in json is "quoted", but we want to accept only object or arrays. |
48 | 48 | // exclude strings and numbers and other primitive types |
49 | - if ( in_array( $string [ 0 ], [ "{", "[" ] ) ) { |
|
50 | - json_decode( $string ); |
|
49 | + if (in_array($string [0], ["{", "["])) { |
|
50 | + json_decode($string); |
|
51 | 51 | |
52 | - return empty( self::getLastJsonError()[ 0 ] ); |
|
52 | + return empty(self::getLastJsonError()[0]); |
|
53 | 53 | } else { |
54 | 54 | return false; // Not accepted: string or primitive types. |
55 | 55 | } |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return array |
63 | 63 | */ |
64 | - public static function jsonToArray( $string ) { |
|
65 | - $decodedJSON = json_decode( $string, true ); |
|
64 | + public static function jsonToArray($string) { |
|
65 | + $decodedJSON = json_decode($string, true); |
|
66 | 66 | |
67 | - return ( is_array( $decodedJSON ) ) ? $decodedJSON : []; |
|
67 | + return (is_array($decodedJSON)) ? $decodedJSON : []; |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -75,10 +75,10 @@ discard block |
||
75 | 75 | */ |
76 | 76 | private static function raiseLastJsonException() { |
77 | 77 | |
78 | - list( $msg, $error ) = self::getLastJsonError(); |
|
78 | + list($msg, $error) = self::getLastJsonError(); |
|
79 | 79 | |
80 | - if ( $error != JSON_ERROR_NONE ) { |
|
81 | - throw new NotValidJSONException( $msg, $error ); |
|
80 | + if ($error != JSON_ERROR_NONE) { |
|
81 | + throw new NotValidJSONException($msg, $error); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | } |
@@ -88,11 +88,11 @@ discard block |
||
88 | 88 | */ |
89 | 89 | private static function getLastJsonError() { |
90 | 90 | |
91 | - if ( function_exists( "json_last_error" ) ) { |
|
91 | + if (function_exists("json_last_error")) { |
|
92 | 92 | |
93 | 93 | $error = json_last_error(); |
94 | 94 | |
95 | - switch ( $error ) { |
|
95 | + switch ($error) { |
|
96 | 96 | case JSON_ERROR_NONE: |
97 | 97 | $msg = null; # - No errors |
98 | 98 | break; |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | break; |
117 | 117 | } |
118 | 118 | |
119 | - return [ $msg, $error ]; |
|
119 | + return [$msg, $error]; |
|
120 | 120 | } |
121 | 121 | |
122 | - return [ null, JSON_ERROR_NONE ]; |
|
122 | + return [null, JSON_ERROR_NONE]; |
|
123 | 123 | |
124 | 124 | } |
125 | 125 | |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | * |
143 | 143 | * @return string |
144 | 144 | */ |
145 | - public static function fixNonWellFormedXml( $content, $escapeStrings = true ) { |
|
146 | - if ( self::$find_xliff_tags_reg === null ) { |
|
145 | + public static function fixNonWellFormedXml($content, $escapeStrings = true) { |
|
146 | + if (self::$find_xliff_tags_reg === null) { |
|
147 | 147 | // Convert the list of tags in a regexp list, for example "g|x|bx|ex" |
148 | 148 | $xliffTags = XliffTags::$tags; |
149 | - $xliff_tags_reg_list = implode( '|', $xliffTags ); |
|
149 | + $xliff_tags_reg_list = implode('|', $xliffTags); |
|
150 | 150 | // Regexp to find all the XLIFF tags: |
151 | 151 | // </? -> matches the tag start, for both opening and |
152 | 152 | // closure tags (see the optional slash) |
@@ -167,30 +167,30 @@ discard block |
||
167 | 167 | } |
168 | 168 | |
169 | 169 | // Find all the XLIFF tags |
170 | - preg_match_all( self::$find_xliff_tags_reg, $content, $matches ); |
|
171 | - $tags = (array)$matches[ 0 ]; |
|
170 | + preg_match_all(self::$find_xliff_tags_reg, $content, $matches); |
|
171 | + $tags = (array)$matches[0]; |
|
172 | 172 | |
173 | 173 | // Prepare placeholders |
174 | 174 | $tags_placeholders = []; |
175 | - $tagsNum = count( $tags ); |
|
176 | - for ( $i = 0; $i < $tagsNum; $i++ ) { |
|
177 | - $tag = $tags[ $i ]; |
|
178 | - $tags_placeholders[ $tag ] = "#@!XLIFF-TAG-$i!@#"; |
|
175 | + $tagsNum = count($tags); |
|
176 | + for ($i = 0; $i < $tagsNum; $i++) { |
|
177 | + $tag = $tags[$i]; |
|
178 | + $tags_placeholders[$tag] = "#@!XLIFF-TAG-$i!@#"; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | // Replace all XLIFF tags with placeholders that will not be escaped |
182 | - foreach ( $tags_placeholders as $tag => $placeholder ) { |
|
183 | - $content = str_replace( $tag, $placeholder, $content ); |
|
182 | + foreach ($tags_placeholders as $tag => $placeholder) { |
|
183 | + $content = str_replace($tag, $placeholder, $content); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | // Escape the string with the remaining non-XLIFF tags |
187 | - if ( $escapeStrings ) { |
|
188 | - $content = htmlspecialchars( $content, ENT_NOQUOTES, 'UTF-8', false ); |
|
187 | + if ($escapeStrings) { |
|
188 | + $content = htmlspecialchars($content, ENT_NOQUOTES, 'UTF-8', false); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | // Put again in place the original XLIFF tags replacing placeholders |
192 | - foreach ( $tags_placeholders as $tag => $placeholder ) { |
|
193 | - $content = str_replace( $placeholder, $tag, $content ); |
|
192 | + foreach ($tags_placeholders as $tag => $placeholder) { |
|
193 | + $content = str_replace($placeholder, $tag, $content); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | return $content; |
@@ -201,17 +201,17 @@ discard block |
||
201 | 201 | * |
202 | 202 | * @return string |
203 | 203 | */ |
204 | - public static function removeDangerousChars( $string ) { |
|
204 | + public static function removeDangerousChars($string) { |
|
205 | 205 | // clean invalid xml entities ( characters with ascii < 32 and different from 0A, 0D and 09 |
206 | 206 | $regexpEntity = '/&#x(0[0-8BCEF]|1[\dA-F]|7F);/u'; |
207 | 207 | |
208 | 208 | // remove binary chars in some xliff files |
209 | 209 | $regexpAscii = '/[\x{00}-\x{08}\x{0B}\x{0C}\x{0E}-\x{1F}\x{7F}]/u'; |
210 | 210 | |
211 | - $string = preg_replace( $regexpAscii, '', $string ); |
|
212 | - $string = preg_replace( $regexpEntity, '', $string ); |
|
211 | + $string = preg_replace($regexpAscii, '', $string); |
|
212 | + $string = preg_replace($regexpEntity, '', $string); |
|
213 | 213 | |
214 | - return !empty( $string ) || strlen( $string ) > 0 ? $string : ""; |
|
214 | + return !empty($string) || strlen($string) > 0 ? $string : ""; |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | * |
221 | 221 | * @return bool |
222 | 222 | */ |
223 | - public static function contains( $needle, $haystack ) { |
|
224 | - return mb_strpos( $haystack, $needle ) !== false; |
|
223 | + public static function contains($needle, $haystack) { |
|
224 | + return mb_strpos($haystack, $needle) !== false; |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -229,8 +229,8 @@ discard block |
||
229 | 229 | * |
230 | 230 | * @return string |
231 | 231 | */ |
232 | - public static function htmlentities( $string ) { |
|
233 | - return htmlentities( $string, ENT_NOQUOTES ); |
|
232 | + public static function htmlentities($string) { |
|
233 | + return htmlentities($string, ENT_NOQUOTES); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -239,15 +239,15 @@ discard block |
||
239 | 239 | * |
240 | 240 | * @return string |
241 | 241 | */ |
242 | - public static function htmlspecialchars_decode( $string, $onlyEscapedEntities = false ) { |
|
243 | - if ( false === $onlyEscapedEntities ) { |
|
244 | - return htmlspecialchars_decode( $string, ENT_NOQUOTES ); |
|
242 | + public static function htmlspecialchars_decode($string, $onlyEscapedEntities = false) { |
|
243 | + if (false === $onlyEscapedEntities) { |
|
244 | + return htmlspecialchars_decode($string, ENT_NOQUOTES); |
|
245 | 245 | } |
246 | 246 | |
247 | - return preg_replace_callback( self::$htmlEntityRegex, |
|
248 | - function ( $match ) { |
|
249 | - return self::htmlspecialchars_decode( $match[ 0 ] ); |
|
250 | - }, $string ); |
|
247 | + return preg_replace_callback(self::$htmlEntityRegex, |
|
248 | + function($match) { |
|
249 | + return self::htmlspecialchars_decode($match[0]); |
|
250 | + }, $string); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -262,8 +262,8 @@ discard block |
||
262 | 262 | * |
263 | 263 | * @return bool |
264 | 264 | */ |
265 | - public static function isADoubleEscapedEntity( $str ) { |
|
266 | - return preg_match( self::$htmlEntityRegex, $str ) != 0; |
|
265 | + public static function isADoubleEscapedEntity($str) { |
|
266 | + return preg_match(self::$htmlEntityRegex, $str) != 0; |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -271,8 +271,8 @@ discard block |
||
271 | 271 | * |
272 | 272 | * @return bool |
273 | 273 | */ |
274 | - public static function isAnEscapedHTML( $str ) { |
|
275 | - return preg_match( '#/[a-z]*>#i', $str ) != 0; |
|
274 | + public static function isAnEscapedHTML($str) { |
|
275 | + return preg_match('#/[a-z]*>#i', $str) != 0; |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -280,8 +280,8 @@ discard block |
||
280 | 280 | * |
281 | 281 | * @return bool |
282 | 282 | */ |
283 | - public static function isAValidUuid( $uuid ) { |
|
284 | - return preg_match( '/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/', $uuid ) === 1; |
|
283 | + public static function isAValidUuid($uuid) { |
|
284 | + return preg_match('/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/', $uuid) === 1; |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
@@ -290,8 +290,8 @@ discard block |
||
290 | 290 | * |
291 | 291 | * @return array|false|string[] |
292 | 292 | */ |
293 | - public static function preg_split( $pattern, $subject ) { |
|
294 | - return preg_split( $pattern, $subject, -1, PREG_SPLIT_NO_EMPTY ); |
|
293 | + public static function preg_split($pattern, $subject) { |
|
294 | + return preg_split($pattern, $subject, -1, PREG_SPLIT_NO_EMPTY); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -309,8 +309,8 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @return string |
311 | 311 | */ |
312 | - public static function escapeOnlyHTMLTags( $string ) { |
|
313 | - return preg_replace( '/<(.*?)>/iu', '<$1>', $string ); |
|
312 | + public static function escapeOnlyHTMLTags($string) { |
|
313 | + return preg_replace('/<(.*?)>/iu', '<$1>', $string); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | /** |
@@ -320,8 +320,8 @@ discard block |
||
320 | 320 | * |
321 | 321 | * @return string |
322 | 322 | */ |
323 | - public static function lastChar( $string ) { |
|
324 | - return mb_substr( $string, -1 ); |
|
323 | + public static function lastChar($string) { |
|
324 | + return mb_substr($string, -1); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | /** |
@@ -329,8 +329,8 @@ discard block |
||
329 | 329 | * |
330 | 330 | * @return int |
331 | 331 | */ |
332 | - public static function getTheNumberOfTrailingSpaces( $segment ) { |
|
333 | - return mb_strlen( $segment ) - mb_strlen( rtrim( $segment, ' ' ) ); |
|
332 | + public static function getTheNumberOfTrailingSpaces($segment) { |
|
333 | + return mb_strlen($segment) - mb_strlen(rtrim($segment, ' ')); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -340,15 +340,15 @@ discard block |
||
340 | 340 | * |
341 | 341 | * @return bool |
342 | 342 | */ |
343 | - public static function isHtmlString( $string ) { |
|
344 | - $string = stripslashes( $string ); |
|
343 | + public static function isHtmlString($string) { |
|
344 | + $string = stripslashes($string); |
|
345 | 345 | |
346 | - if ( $string === '<>' ) { |
|
346 | + if ($string === '<>') { |
|
347 | 347 | return false; |
348 | 348 | } |
349 | 349 | |
350 | - preg_match( "#</?[a-zA-Z1-6-]+((\s+[a-zA-Z1-6-]+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)/?>#", $string, $matches ); |
|
350 | + preg_match("#</?[a-zA-Z1-6-]+((\s+[a-zA-Z1-6-]+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)/?>#", $string, $matches); |
|
351 | 351 | |
352 | - return count( $matches ) !== 0; |
|
352 | + return count($matches) !== 0; |
|
353 | 353 | } |
354 | 354 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @param LoggerInterface $logger |
32 | 32 | */ |
33 | - public function __construct( LoggerInterface $logger = null ) { |
|
33 | + public function __construct(LoggerInterface $logger = null) { |
|
34 | 34 | $this->logger = $logger; |
35 | 35 | } |
36 | 36 | |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | * @param bool $setSourceInTarget |
46 | 46 | * @param XliffReplacerCallbackInterface|null $callback |
47 | 47 | */ |
48 | - public function replaceTranslation( $originalXliffPath, &$data, &$transUnits, $targetLang, $outputFile, $setSourceInTarget = false, XliffReplacerCallbackInterface $callback = null ) { |
|
48 | + public function replaceTranslation($originalXliffPath, &$data, &$transUnits, $targetLang, $outputFile, $setSourceInTarget = false, XliffReplacerCallbackInterface $callback = null) { |
|
49 | 49 | try { |
50 | - $parser = XliffReplacerFactory::getInstance( $originalXliffPath, $data, $transUnits, $targetLang, $outputFile, $setSourceInTarget, $this->logger, $callback ); |
|
50 | + $parser = XliffReplacerFactory::getInstance($originalXliffPath, $data, $transUnits, $targetLang, $outputFile, $setSourceInTarget, $this->logger, $callback); |
|
51 | 51 | $parser->replaceTranslation(); |
52 | - } catch ( Exception $exception ) { |
|
52 | + } catch (Exception $exception) { |
|
53 | 53 | // do nothing |
54 | 54 | } |
55 | 55 | } |
@@ -67,26 +67,26 @@ discard block |
||
67 | 67 | * @throws InvalidXmlException |
68 | 68 | * @throws XmlParsingException |
69 | 69 | */ |
70 | - public function xliffToArray( $xliffContent, $collapseEmptyTags = false ) { |
|
70 | + public function xliffToArray($xliffContent, $collapseEmptyTags = false) { |
|
71 | 71 | $xliff = []; |
72 | - $xliffContent = self::forceUft8Encoding( $xliffContent, $xliff ); |
|
73 | - $xliffVersion = XliffVersionDetector::detect( $xliffContent ); |
|
74 | - $info = XliffProprietaryDetect::getInfoFromXliffContent( $xliffContent ); |
|
72 | + $xliffContent = self::forceUft8Encoding($xliffContent, $xliff); |
|
73 | + $xliffVersion = XliffVersionDetector::detect($xliffContent); |
|
74 | + $info = XliffProprietaryDetect::getInfoFromXliffContent($xliffContent); |
|
75 | 75 | |
76 | - if ( $xliffVersion === 1 ) { |
|
77 | - $xliffContent = self::removeInternalFileTagFromContent( $xliffContent, $xliff ); |
|
76 | + if ($xliffVersion === 1) { |
|
77 | + $xliffContent = self::removeInternalFileTagFromContent($xliffContent, $xliff); |
|
78 | 78 | } |
79 | 79 | |
80 | - if ( $xliffVersion === 2 ) { |
|
81 | - $xliffContent = self::escapeDataInOriginalMap( $xliffContent ); |
|
80 | + if ($xliffVersion === 2) { |
|
81 | + $xliffContent = self::escapeDataInOriginalMap($xliffContent); |
|
82 | 82 | } |
83 | 83 | |
84 | - if ( $collapseEmptyTags === false ) { |
|
85 | - $xliffContent = self::insertPlaceholderInEmptyTags( $xliffContent ); |
|
84 | + if ($collapseEmptyTags === false) { |
|
85 | + $xliffContent = self::insertPlaceholderInEmptyTags($xliffContent); |
|
86 | 86 | } |
87 | 87 | |
88 | - $xliffProprietary = isset( $info[ 'proprietary_short_name' ] ) ? $info[ 'proprietary_short_name' ] : null; |
|
89 | - $parser = XliffParserFactory::getInstance( $xliffVersion, $xliffProprietary, $this->logger ); |
|
88 | + $xliffProprietary = isset($info['proprietary_short_name']) ? $info['proprietary_short_name'] : null; |
|
89 | + $parser = XliffParserFactory::getInstance($xliffVersion, $xliffProprietary, $this->logger); |
|
90 | 90 | |
91 | 91 | $dom = XmlDomLoader::load( |
92 | 92 | $xliffContent, |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | ) |
98 | 98 | ); |
99 | 99 | |
100 | - return $parser->parse( $dom, $xliff ); |
|
100 | + return $parser->parse($dom, $xliff); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -109,12 +109,12 @@ discard block |
||
109 | 109 | * |
110 | 110 | * @return string |
111 | 111 | */ |
112 | - private static function forceUft8Encoding( $xliffContent, &$xliff ) { |
|
113 | - $enc = mb_detect_encoding( $xliffContent ); |
|
112 | + private static function forceUft8Encoding($xliffContent, &$xliff) { |
|
113 | + $enc = mb_detect_encoding($xliffContent); |
|
114 | 114 | |
115 | - if ( $enc !== 'UTF-8' ) { |
|
116 | - $xliff[ 'parser-warnings' ][] = "Input identified as $enc ans converted UTF-8. May not be a problem if the content is English only"; |
|
117 | - $s = iconv( $enc, 'UTF-8', $xliffContent ); |
|
115 | + if ($enc !== 'UTF-8') { |
|
116 | + $xliff['parser-warnings'][] = "Input identified as $enc ans converted UTF-8. May not be a problem if the content is English only"; |
|
117 | + $s = iconv($enc, 'UTF-8', $xliffContent); |
|
118 | 118 | $xliffContent = $s !== false ? $s : ""; |
119 | 119 | } |
120 | 120 | |
@@ -131,24 +131,24 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @return mixed|string |
133 | 133 | */ |
134 | - private static function removeInternalFileTagFromContent( $xliffContent, &$xliff ) { |
|
134 | + private static function removeInternalFileTagFromContent($xliffContent, &$xliff) { |
|
135 | 135 | $index = 1; |
136 | - $a = Strings::preg_split( '|<internal-file[\s>]|i', $xliffContent ); |
|
136 | + $a = Strings::preg_split('|<internal-file[\s>]|i', $xliffContent); |
|
137 | 137 | |
138 | 138 | // no match, return original string |
139 | - if ( count( $a ) === 1 ) { |
|
140 | - return $a[ 0 ]; |
|
139 | + if (count($a) === 1) { |
|
140 | + return $a[0]; |
|
141 | 141 | } |
142 | 142 | |
143 | - $b = Strings::preg_split( '|</internal-file>|i', $a[ 1 ] ); |
|
144 | - $strippedContent = $a[ 0 ] . $b[ 1 ]; |
|
145 | - $xliff[ 'files' ][ $index ][ 'reference' ][] = self::extractBase64( $b[ 0 ] ); |
|
143 | + $b = Strings::preg_split('|</internal-file>|i', $a[1]); |
|
144 | + $strippedContent = $a[0] . $b[1]; |
|
145 | + $xliff['files'][$index]['reference'][] = self::extractBase64($b[0]); |
|
146 | 146 | $index++; |
147 | 147 | |
148 | - if ( isset( $a[ 2 ] ) ) { |
|
149 | - $c = Strings::preg_split( '|</internal-file[\s>]|i', $a[ 2 ] ); |
|
150 | - $strippedContent .= $c[ 1 ]; |
|
151 | - $xliff[ 'files' ][ $index ][ 'reference' ][] = self::extractBase64( $c[ 0 ] ); |
|
148 | + if (isset($a[2])) { |
|
149 | + $c = Strings::preg_split('|</internal-file[\s>]|i', $a[2]); |
|
150 | + $strippedContent .= $c[1]; |
|
151 | + $xliff['files'][$index]['reference'][] = self::extractBase64($c[0]); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | return $strippedContent; |
@@ -159,10 +159,10 @@ discard block |
||
159 | 159 | * |
160 | 160 | * @return array |
161 | 161 | */ |
162 | - private static function extractBase64( $base64 ) { |
|
162 | + private static function extractBase64($base64) { |
|
163 | 163 | return [ |
164 | 164 | 'form-type' => 'base64', |
165 | - 'base64' => trim( str_replace( 'form="base64">', '', $base64 ) ), |
|
165 | + 'base64' => trim(str_replace('form="base64">', '', $base64)), |
|
166 | 166 | ]; |
167 | 167 | } |
168 | 168 | |
@@ -182,9 +182,9 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @return string |
184 | 184 | */ |
185 | - private static function escapeDataInOriginalMap( $xliffContent ) { |
|
186 | - $xliffContent = preg_replace_callback( '|<data(.*?)>(.*?)</data>|iU', [ XliffParser::class, 'replaceSpace' ], $xliffContent ); |
|
187 | - $xliffContent = preg_replace_callback( '|<data(.*?)>(.*?)</data>|iU', [ XliffParser::class, 'replaceXliffTags' ], $xliffContent ); |
|
185 | + private static function escapeDataInOriginalMap($xliffContent) { |
|
186 | + $xliffContent = preg_replace_callback('|<data(.*?)>(.*?)</data>|iU', [XliffParser::class, 'replaceSpace'], $xliffContent); |
|
187 | + $xliffContent = preg_replace_callback('|<data(.*?)>(.*?)</data>|iU', [XliffParser::class, 'replaceXliffTags'], $xliffContent); |
|
188 | 188 | |
189 | 189 | return $xliffContent; |
190 | 190 | } |
@@ -203,15 +203,15 @@ discard block |
||
203 | 203 | * |
204 | 204 | * @return string |
205 | 205 | */ |
206 | - private static function insertPlaceholderInEmptyTags( $xliffContent ) { |
|
207 | - preg_match_all( '|<([a-zA-Z0-9._-]+)[^>]*></\1>|m', $xliffContent, $emptyTagMatches ); |
|
206 | + private static function insertPlaceholderInEmptyTags($xliffContent) { |
|
207 | + preg_match_all('|<([a-zA-Z0-9._-]+)[^>]*></\1>|m', $xliffContent, $emptyTagMatches); |
|
208 | 208 | |
209 | - if ( !empty( $emptyTagMatches[ 0 ] ) ) { |
|
210 | - foreach ( $emptyTagMatches[ 0 ] as $index => $emptyTagMatch ) { |
|
211 | - $matchedTag = $emptyTagMatches[ 1 ][ $index ]; |
|
209 | + if (!empty($emptyTagMatches[0])) { |
|
210 | + foreach ($emptyTagMatches[0] as $index => $emptyTagMatch) { |
|
211 | + $matchedTag = $emptyTagMatches[1][$index]; |
|
212 | 212 | $subst = Placeholder::EMPTY_TAG_PLACEHOLDER . '</' . $matchedTag . '>'; |
213 | - $replacedTag = str_replace( '</' . $matchedTag . '>', $subst, $emptyTagMatch ); |
|
214 | - $xliffContent = str_replace( $emptyTagMatch, $replacedTag, $xliffContent ); |
|
213 | + $replacedTag = str_replace('</' . $matchedTag . '>', $subst, $emptyTagMatch); |
|
214 | + $xliffContent = str_replace($emptyTagMatch, $replacedTag, $xliffContent); |
|
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
@@ -225,12 +225,12 @@ discard block |
||
225 | 225 | * |
226 | 226 | * @return string |
227 | 227 | */ |
228 | - private static function replaceSpace( $matches ) { |
|
229 | - $content = str_replace( ' ', Placeholder::WHITE_SPACE_PLACEHOLDER, $matches[ 2 ] ); |
|
230 | - $content = str_replace( '\n', Placeholder::NEW_LINE_PLACEHOLDER, $content ); |
|
231 | - $content = str_replace( '\t', Placeholder::TAB_PLACEHOLDER, $content ); |
|
228 | + private static function replaceSpace($matches) { |
|
229 | + $content = str_replace(' ', Placeholder::WHITE_SPACE_PLACEHOLDER, $matches[2]); |
|
230 | + $content = str_replace('\n', Placeholder::NEW_LINE_PLACEHOLDER, $content); |
|
231 | + $content = str_replace('\t', Placeholder::TAB_PLACEHOLDER, $content); |
|
232 | 232 | |
233 | - return '<data' . $matches[ 1 ] . '>' . $content . '</data>'; |
|
233 | + return '<data' . $matches[1] . '>' . $content . '</data>'; |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -238,15 +238,15 @@ discard block |
||
238 | 238 | * |
239 | 239 | * @return string |
240 | 240 | */ |
241 | - private static function replaceXliffTags( $matches ) { |
|
241 | + private static function replaceXliffTags($matches) { |
|
242 | 242 | $xliffTags = XliffTags::$tags; |
243 | - $content = $matches[ 2 ]; |
|
243 | + $content = $matches[2]; |
|
244 | 244 | |
245 | - foreach ( $xliffTags as $xliffTag ) { |
|
246 | - $content = preg_replace( '|<(' . $xliffTag . '.*?)>|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content ); |
|
247 | - $content = preg_replace( '|<(/' . $xliffTag . ')>|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content ); |
|
245 | + foreach ($xliffTags as $xliffTag) { |
|
246 | + $content = preg_replace('|<(' . $xliffTag . '.*?)>|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content); |
|
247 | + $content = preg_replace('|<(/' . $xliffTag . ')>|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content); |
|
248 | 248 | } |
249 | 249 | |
250 | - return '<data' . $matches[ 1 ] . '>' . $content . '</data>'; |
|
250 | + return '<data' . $matches[1] . '>' . $content . '</data>'; |
|
251 | 251 | } |
252 | 252 | } |
@@ -16,33 +16,33 @@ discard block |
||
16 | 16 | * @inheritDoc |
17 | 17 | * @throws Exception |
18 | 18 | */ |
19 | - public function parse( DOMDocument $dom, $output = [] ) { |
|
19 | + public function parse(DOMDocument $dom, $output = []) { |
|
20 | 20 | $i = 1; |
21 | 21 | /** @var DOMElement $file */ |
22 | - foreach ( $dom->getElementsByTagName( 'file' ) as $file ) { |
|
22 | + foreach ($dom->getElementsByTagName('file') as $file) { |
|
23 | 23 | |
24 | 24 | // metadata |
25 | - $output[ 'files' ][ $i ][ 'attr' ] = $this->extractMetadata( $file ); |
|
25 | + $output['files'][$i]['attr'] = $this->extractMetadata($file); |
|
26 | 26 | |
27 | 27 | // reference |
28 | - if ( !empty( $this->extractReference( $file ) ) ) { |
|
29 | - $output[ 'files' ][ $i ][ 'reference' ] = $this->extractReference( $file ); |
|
28 | + if (!empty($this->extractReference($file))) { |
|
29 | + $output['files'][$i]['reference'] = $this->extractReference($file); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | // trans-units |
33 | 33 | $transUnitIdArrayForUniquenessCheck = []; |
34 | 34 | $j = 1; |
35 | - foreach ( $file->childNodes as $body ) { |
|
36 | - if ( $body->nodeName === 'body' ) { |
|
37 | - foreach ( $body->childNodes as $childNode ) { |
|
38 | - $this->extractTuFromNode( $childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j ); |
|
35 | + foreach ($file->childNodes as $body) { |
|
36 | + if ($body->nodeName === 'body') { |
|
37 | + foreach ($body->childNodes as $childNode) { |
|
38 | + $this->extractTuFromNode($childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | // trans-unit re-count check |
42 | - $totalTransUnitsId = count( $transUnitIdArrayForUniquenessCheck ); |
|
43 | - $transUnitsUniqueId = count( array_unique( $transUnitIdArrayForUniquenessCheck ) ); |
|
44 | - if ( $totalTransUnitsId != $transUnitsUniqueId ) { |
|
45 | - throw new DuplicateTransUnitIdInXliff( "Invalid trans-unit id, duplicate found.", 400 ); |
|
42 | + $totalTransUnitsId = count($transUnitIdArrayForUniquenessCheck); |
|
43 | + $transUnitsUniqueId = count(array_unique($transUnitIdArrayForUniquenessCheck)); |
|
44 | + if ($totalTransUnitsId != $transUnitsUniqueId) { |
|
45 | + throw new DuplicateTransUnitIdInXliff("Invalid trans-unit id, duplicate found.", 400); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | $i++; |
@@ -58,50 +58,50 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return array |
60 | 60 | */ |
61 | - private function extractMetadata( DOMElement $file ) { |
|
61 | + private function extractMetadata(DOMElement $file) { |
|
62 | 62 | $metadata = []; |
63 | 63 | $customAttr = []; |
64 | 64 | |
65 | 65 | /** @var DOMAttr $attribute */ |
66 | - foreach ( $file->attributes as $attribute ) { |
|
67 | - switch ( $attribute->localName ) { |
|
66 | + foreach ($file->attributes as $attribute) { |
|
67 | + switch ($attribute->localName) { |
|
68 | 68 | // original |
69 | 69 | case 'original': |
70 | - $metadata[ 'original' ] = $attribute->value; |
|
70 | + $metadata['original'] = $attribute->value; |
|
71 | 71 | break; |
72 | 72 | |
73 | 73 | // source-language |
74 | 74 | case 'source-language': |
75 | - $metadata[ 'source-language' ] = $attribute->value; |
|
75 | + $metadata['source-language'] = $attribute->value; |
|
76 | 76 | break; |
77 | 77 | |
78 | 78 | // data-type |
79 | 79 | case 'datatype': |
80 | - $metadata[ 'data-type' ] = $attribute->value; |
|
80 | + $metadata['data-type'] = $attribute->value; |
|
81 | 81 | break; |
82 | 82 | |
83 | 83 | // target-language |
84 | 84 | case 'target-language': |
85 | - $metadata[ 'target-language' ] = $attribute->value; |
|
85 | + $metadata['target-language'] = $attribute->value; |
|
86 | 86 | break; |
87 | 87 | } |
88 | 88 | |
89 | 89 | // Custom MateCat x-Attribute |
90 | - preg_match( '|x-(.*?)|si', $attribute->localName, $temp ); |
|
91 | - if ( isset( $temp[ 1 ] ) ) { |
|
92 | - $customAttr[ $attribute->localName ] = $attribute->value; |
|
90 | + preg_match('|x-(.*?)|si', $attribute->localName, $temp); |
|
91 | + if (isset($temp[1])) { |
|
92 | + $customAttr[$attribute->localName] = $attribute->value; |
|
93 | 93 | } |
94 | - unset( $temp ); |
|
94 | + unset($temp); |
|
95 | 95 | |
96 | 96 | // Custom MateCat namespace Attribute mtc: |
97 | - preg_match( '|mtc:(.*?)|si', $attribute->nodeName, $temp ); |
|
98 | - if ( isset( $temp[ 1 ] ) ) { |
|
99 | - $customAttr[ $attribute->nodeName ] = $attribute->value; |
|
97 | + preg_match('|mtc:(.*?)|si', $attribute->nodeName, $temp); |
|
98 | + if (isset($temp[1])) { |
|
99 | + $customAttr[$attribute->nodeName] = $attribute->value; |
|
100 | 100 | } |
101 | - unset( $temp ); |
|
101 | + unset($temp); |
|
102 | 102 | |
103 | - if ( !empty( $customAttr ) ) { |
|
104 | - $metadata[ 'custom' ] = $customAttr; |
|
103 | + if (!empty($customAttr)) { |
|
104 | + $metadata['custom'] = $customAttr; |
|
105 | 105 | } |
106 | 106 | } |
107 | 107 | |
@@ -113,16 +113,16 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @return array |
115 | 115 | */ |
116 | - private function extractReference( DOMElement $file ) { |
|
116 | + private function extractReference(DOMElement $file) { |
|
117 | 117 | $reference = []; |
118 | 118 | |
119 | 119 | $order = 0; |
120 | - foreach ( $file->getElementsByTagName( 'reference' ) as $ref ) { |
|
120 | + foreach ($file->getElementsByTagName('reference') as $ref) { |
|
121 | 121 | /** @var DOMNode $childNode */ |
122 | - foreach ( $ref->childNodes as $childNode ) { |
|
123 | - if ( $childNode->nodeName === 'internal-file' ) { |
|
124 | - $reference[ $order ][ 'form-type' ] = $childNode->attributes->getNamedItem( 'form' )->nodeValue; |
|
125 | - $reference[ $order ][ 'base64' ] = trim( $childNode->nodeValue ); |
|
122 | + foreach ($ref->childNodes as $childNode) { |
|
123 | + if ($childNode->nodeName === 'internal-file') { |
|
124 | + $reference[$order]['form-type'] = $childNode->attributes->getNamedItem('form')->nodeValue; |
|
125 | + $reference[$order]['base64'] = trim($childNode->nodeValue); |
|
126 | 126 | $order++; |
127 | 127 | } |
128 | 128 | } |
@@ -144,60 +144,60 @@ discard block |
||
144 | 144 | * |
145 | 145 | * @throws Exception |
146 | 146 | */ |
147 | - protected function extractTransUnit( DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j, $contextGroups = [] ) { |
|
147 | + protected function extractTransUnit(DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j, $contextGroups = []) { |
|
148 | 148 | // metadata |
149 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ] = $this->extractTransUnitMetadata( $transUnit, $transUnitIdArrayForUniquenessCheck ); |
|
149 | + $output['files'][$i]['trans-units'][$j]['attr'] = $this->extractTransUnitMetadata($transUnit, $transUnitIdArrayForUniquenessCheck); |
|
150 | 150 | |
151 | 151 | // notes |
152 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'notes' ] = $this->extractTransUnitNotes( $dom, $transUnit ); |
|
152 | + $output['files'][$i]['trans-units'][$j]['notes'] = $this->extractTransUnitNotes($dom, $transUnit); |
|
153 | 153 | |
154 | 154 | // content |
155 | 155 | /** @var DOMElement $childNode */ |
156 | - foreach ( $transUnit->childNodes as $childNode ) { |
|
156 | + foreach ($transUnit->childNodes as $childNode) { |
|
157 | 157 | // source |
158 | - if ( $childNode->nodeName === 'source' ) { |
|
159 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'source' ] = $this->extractContent( $dom, $childNode ); |
|
158 | + if ($childNode->nodeName === 'source') { |
|
159 | + $output['files'][$i]['trans-units'][$j]['source'] = $this->extractContent($dom, $childNode); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | // seg-source |
163 | - if ( $childNode->nodeName === 'seg-source' ) { |
|
164 | - $rawSegment = $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'source' ][ 'raw-content' ]; |
|
165 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-source' ] = $this->extractContentWithMarksAndExtTags( $dom, $childNode, $rawSegment ); |
|
163 | + if ($childNode->nodeName === 'seg-source') { |
|
164 | + $rawSegment = $output['files'][$i]['trans-units'][$j]['source']['raw-content']; |
|
165 | + $output['files'][$i]['trans-units'][$j]['seg-source'] = $this->extractContentWithMarksAndExtTags($dom, $childNode, $rawSegment); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | // target |
169 | - if ( $childNode->nodeName === 'target' ) { |
|
170 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'target' ] = $this->extractContent( $dom, $childNode ); |
|
169 | + if ($childNode->nodeName === 'target') { |
|
170 | + $output['files'][$i]['trans-units'][$j]['target'] = $this->extractContent($dom, $childNode); |
|
171 | 171 | |
172 | 172 | // seg-target |
173 | - $targetRawContent = @$output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'target' ][ 'raw-content' ]; |
|
174 | - $segSource = @$output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-source' ]; |
|
175 | - if ( isset( $targetRawContent ) && !empty( $targetRawContent ) && isset( $segSource ) && count( $segSource ) > 0 ) { |
|
176 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-target' ] = $this->extractContentWithMarksAndExtTags( $dom, $childNode ); |
|
177 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-target' ][ 0 ]['attr'] = $this->extractTagAttributes($childNode); |
|
173 | + $targetRawContent = @$output['files'][$i]['trans-units'][$j]['target']['raw-content']; |
|
174 | + $segSource = @$output['files'][$i]['trans-units'][$j]['seg-source']; |
|
175 | + if (isset($targetRawContent) && !empty($targetRawContent) && isset($segSource) && count($segSource) > 0) { |
|
176 | + $output['files'][$i]['trans-units'][$j]['seg-target'] = $this->extractContentWithMarksAndExtTags($dom, $childNode); |
|
177 | + $output['files'][$i]['trans-units'][$j]['seg-target'][0]['attr'] = $this->extractTagAttributes($childNode); |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
181 | 181 | // locked |
182 | - if ( $childNode->nodeName === 'sdl:seg' ) { |
|
183 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'locked' ] = $this->extractLocked( $childNode ); |
|
182 | + if ($childNode->nodeName === 'sdl:seg') { |
|
183 | + $output['files'][$i]['trans-units'][$j]['locked'] = $this->extractLocked($childNode); |
|
184 | 184 | } |
185 | 185 | } |
186 | 186 | |
187 | 187 | // context-group |
188 | - if(!empty($contextGroups)){ |
|
189 | - foreach ($contextGroups as $contextGroup){ |
|
190 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'context-group' ][] = $this->extractTransUnitContextGroup( $dom, $contextGroup ); |
|
188 | + if (!empty($contextGroups)) { |
|
189 | + foreach ($contextGroups as $contextGroup) { |
|
190 | + $output['files'][$i]['trans-units'][$j]['context-group'][] = $this->extractTransUnitContextGroup($dom, $contextGroup); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
194 | - foreach ( $transUnit->getElementsByTagName( 'context-group' ) as $contextGroup ) { |
|
195 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'context-group' ][] = $this->extractTransUnitContextGroup( $dom, $contextGroup ); |
|
194 | + foreach ($transUnit->getElementsByTagName('context-group') as $contextGroup) { |
|
195 | + $output['files'][$i]['trans-units'][$j]['context-group'][] = $this->extractTransUnitContextGroup($dom, $contextGroup); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | // alt-trans |
199 | - foreach ( $transUnit->getElementsByTagName( 'alt-trans' ) as $altTrans ) { |
|
200 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'alt-trans' ][] = $this->extractTransUnitAltTrans( $altTrans ); |
|
199 | + foreach ($transUnit->getElementsByTagName('alt-trans') as $altTrans) { |
|
200 | + $output['files'][$i]['trans-units'][$j]['alt-trans'][] = $this->extractTransUnitAltTrans($altTrans); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | $j++; |
@@ -210,41 +210,41 @@ discard block |
||
210 | 210 | * @return array |
211 | 211 | * @throws Exception |
212 | 212 | */ |
213 | - private function extractTransUnitMetadata( DOMElement $transUnit, array &$transUnitIdArrayForUniquenessCheck ) { |
|
213 | + private function extractTransUnitMetadata(DOMElement $transUnit, array &$transUnitIdArrayForUniquenessCheck) { |
|
214 | 214 | $metadata = []; |
215 | 215 | |
216 | 216 | // id MUST NOT be null |
217 | - if ( null === $transUnit->attributes->getNamedItem( 'id' ) ) { |
|
218 | - throw new NotFoundIdInTransUnit( 'Invalid trans-unit id found. EMPTY value', 400 ); |
|
217 | + if (null === $transUnit->attributes->getNamedItem('id')) { |
|
218 | + throw new NotFoundIdInTransUnit('Invalid trans-unit id found. EMPTY value', 400); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
222 | 222 | * @var DOMAttr $element |
223 | 223 | */ |
224 | - foreach ( $transUnit->attributes as $element ) { |
|
224 | + foreach ($transUnit->attributes as $element) { |
|
225 | 225 | |
226 | - if ( $element->nodeName === "id" ) { |
|
226 | + if ($element->nodeName === "id") { |
|
227 | 227 | |
228 | 228 | $id = $element->nodeValue; |
229 | 229 | |
230 | - if ( strlen( $id ) > 100 ) { |
|
231 | - throw new SegmentIdTooLongException( 'Segment-id too long. Max 100 characters allowed', 400 ); |
|
230 | + if (strlen($id) > 100) { |
|
231 | + throw new SegmentIdTooLongException('Segment-id too long. Max 100 characters allowed', 400); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | $transUnitIdArrayForUniquenessCheck[] = $id; |
235 | - $metadata[ 'id' ] = $id; |
|
235 | + $metadata['id'] = $id; |
|
236 | 236 | |
237 | - } elseif ( $element->nodeName === "approved" ) { |
|
237 | + } elseif ($element->nodeName === "approved") { |
|
238 | 238 | // approved as BOOLEAN |
239 | 239 | // http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html#approved |
240 | - $metadata[ $element->nodeName ] = filter_var( $element->nodeValue, FILTER_VALIDATE_BOOLEAN ); |
|
241 | - } elseif ( $element->nodeName === "maxwidth" ) { |
|
240 | + $metadata[$element->nodeName] = filter_var($element->nodeValue, FILTER_VALIDATE_BOOLEAN); |
|
241 | + } elseif ($element->nodeName === "maxwidth") { |
|
242 | 242 | // we ignore ( but we get ) the attribute size-unit="char" assuming that a restriction is everytime done by character |
243 | 243 | // we duplicate the info to allow Xliff V1 and V2 to work the same |
244 | - $metadata[ 'sizeRestriction' ] = filter_var( $element->nodeValue, FILTER_SANITIZE_NUMBER_INT ); |
|
245 | - $metadata[ $element->nodeName ] = filter_var( $element->nodeValue, FILTER_SANITIZE_NUMBER_INT ); |
|
244 | + $metadata['sizeRestriction'] = filter_var($element->nodeValue, FILTER_SANITIZE_NUMBER_INT); |
|
245 | + $metadata[$element->nodeName] = filter_var($element->nodeValue, FILTER_SANITIZE_NUMBER_INT); |
|
246 | 246 | } else { |
247 | - $metadata[ $element->nodeName ] = $element->nodeValue; |
|
247 | + $metadata[$element->nodeName] = $element->nodeValue; |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | } |
@@ -258,19 +258,19 @@ discard block |
||
258 | 258 | * @return array |
259 | 259 | * @throws Exception |
260 | 260 | */ |
261 | - private function extractTransUnitNotes( DOMDocument $dom, DOMElement $transUnit ) { |
|
261 | + private function extractTransUnitNotes(DOMDocument $dom, DOMElement $transUnit) { |
|
262 | 262 | $notes = []; |
263 | - foreach ( $transUnit->getElementsByTagName( 'note' ) as $note ) { |
|
263 | + foreach ($transUnit->getElementsByTagName('note') as $note) { |
|
264 | 264 | |
265 | - $noteValue = $this->extractTagContent( $dom, $note ); |
|
265 | + $noteValue = $this->extractTagContent($dom, $note); |
|
266 | 266 | |
267 | - if ( '' !== $noteValue ) { |
|
267 | + if ('' !== $noteValue) { |
|
268 | 268 | |
269 | - $extractedNote = $this->JSONOrRawContentArray( $noteValue ); |
|
269 | + $extractedNote = $this->JSONOrRawContentArray($noteValue); |
|
270 | 270 | |
271 | 271 | // extract all the attributes |
272 | - foreach ( $note->attributes as $attribute ) { |
|
273 | - $extractedNote[ $attribute->name ] = $attribute->value; |
|
272 | + foreach ($note->attributes as $attribute) { |
|
273 | + $extractedNote[$attribute->name] = $attribute->value; |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | $notes[] = $extractedNote; |
@@ -285,14 +285,14 @@ discard block |
||
285 | 285 | * |
286 | 286 | * @return array |
287 | 287 | */ |
288 | - private function extractTransUnitContextGroup( DOMDocument $dom, DOMElement $contextGroup ) { |
|
288 | + private function extractTransUnitContextGroup(DOMDocument $dom, DOMElement $contextGroup) { |
|
289 | 289 | $cg = []; |
290 | - $cg[ 'attr' ] = $this->extractTagAttributes( $contextGroup ); |
|
290 | + $cg['attr'] = $this->extractTagAttributes($contextGroup); |
|
291 | 291 | |
292 | 292 | /** @var DOMNode $context */ |
293 | - foreach ( $contextGroup->childNodes as $context ) { |
|
294 | - if ( $context->nodeName === 'context' ) { |
|
295 | - $cg[ 'contexts' ][] = $this->extractContent( $dom, $context ); |
|
293 | + foreach ($contextGroup->childNodes as $context) { |
|
294 | + if ($context->nodeName === 'context') { |
|
295 | + $cg['contexts'][] = $this->extractContent($dom, $context); |
|
296 | 296 | } |
297 | 297 | } |
298 | 298 | |
@@ -304,16 +304,16 @@ discard block |
||
304 | 304 | * |
305 | 305 | * @return array |
306 | 306 | */ |
307 | - private function extractTransUnitAltTrans( DOMElement $altTrans ) { |
|
307 | + private function extractTransUnitAltTrans(DOMElement $altTrans) { |
|
308 | 308 | $at = []; |
309 | - $at[ 'attr' ] = $this->extractTagAttributes( $altTrans ); |
|
309 | + $at['attr'] = $this->extractTagAttributes($altTrans); |
|
310 | 310 | |
311 | - if ( $altTrans->getElementsByTagName( 'source' )->length > 0 ) { |
|
312 | - $at[ 'source' ] = $altTrans->getElementsByTagName( 'source' )->item( 0 )->nodeValue; |
|
311 | + if ($altTrans->getElementsByTagName('source')->length > 0) { |
|
312 | + $at['source'] = $altTrans->getElementsByTagName('source')->item(0)->nodeValue; |
|
313 | 313 | } |
314 | 314 | |
315 | - if ( $altTrans->getElementsByTagName( 'target' ) ) { |
|
316 | - $at[ 'target' ] = $altTrans->getElementsByTagName( 'target' )->item( 0 )->nodeValue; |
|
315 | + if ($altTrans->getElementsByTagName('target')) { |
|
316 | + $at['target'] = $altTrans->getElementsByTagName('target')->item(0)->nodeValue; |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | return $at; |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | * |
325 | 325 | * @return bool |
326 | 326 | */ |
327 | - private function extractLocked( DOMElement $locked ) { |
|
328 | - return null !== $locked->getAttribute( 'locked' ); |
|
327 | + private function extractLocked(DOMElement $locked) { |
|
328 | + return null !== $locked->getAttribute('locked'); |
|
329 | 329 | } |
330 | 330 | } |