@@ -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( $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j, $contextGroups = [] ) { |
|
147 | + protected function extractTransUnit($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, $targetRawContent ); |
|
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, $targetRawContent); |
|
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 | } |
@@ -16,30 +16,30 @@ 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( $dom ); |
|
25 | + $output['files'][$i]['attr'] = $this->extractMetadata($dom); |
|
26 | 26 | |
27 | 27 | // notes |
28 | - $output[ 'files' ][ $i ][ 'notes' ] = $this->extractNotes( $file ); |
|
28 | + $output['files'][$i]['notes'] = $this->extractNotes($file); |
|
29 | 29 | |
30 | 30 | // trans-units |
31 | 31 | $transUnitIdArrayForUniquenessCheck = []; |
32 | 32 | $j = 1; |
33 | 33 | /** @var DOMElement $transUnit */ |
34 | - foreach ( $file->childNodes as $childNode ) { |
|
35 | - $this->extractTuFromNode( $childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j ); |
|
34 | + foreach ($file->childNodes as $childNode) { |
|
35 | + $this->extractTuFromNode($childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | // trans-unit re-count check |
39 | - $totalTransUnitsId = count( $transUnitIdArrayForUniquenessCheck ); |
|
40 | - $transUnitsUniqueId = count( array_unique( $transUnitIdArrayForUniquenessCheck ) ); |
|
41 | - if ( $totalTransUnitsId != $transUnitsUniqueId ) { |
|
42 | - throw new DuplicateTransUnitIdInXliff( "Invalid trans-unit id, duplicate found.", 400 ); |
|
39 | + $totalTransUnitsId = count($transUnitIdArrayForUniquenessCheck); |
|
40 | + $transUnitsUniqueId = count(array_unique($transUnitIdArrayForUniquenessCheck)); |
|
41 | + if ($totalTransUnitsId != $transUnitsUniqueId) { |
|
42 | + throw new DuplicateTransUnitIdInXliff("Invalid trans-unit id, duplicate found.", 400); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | $i++; |
@@ -53,23 +53,23 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return array |
55 | 55 | */ |
56 | - private function extractMetadata( DOMDocument $dom ) { |
|
56 | + private function extractMetadata(DOMDocument $dom) { |
|
57 | 57 | $metadata = []; |
58 | 58 | |
59 | - $xliffNode = $dom->getElementsByTagName( 'xliff' )->item( 0 ); |
|
60 | - $fileNode = $dom->getElementsByTagName( 'file' )->item( 0 ); |
|
59 | + $xliffNode = $dom->getElementsByTagName('xliff')->item(0); |
|
60 | + $fileNode = $dom->getElementsByTagName('file')->item(0); |
|
61 | 61 | |
62 | 62 | // original |
63 | - $metadata[ 'original' ] = ( null !== $fileNode->attributes->getNamedItem( 'original' ) ) ? $fileNode->attributes->getNamedItem( 'original' )->nodeValue : 'no-name'; |
|
63 | + $metadata['original'] = (null !== $fileNode->attributes->getNamedItem('original')) ? $fileNode->attributes->getNamedItem('original')->nodeValue : 'no-name'; |
|
64 | 64 | |
65 | 65 | // source-language |
66 | - $metadata[ 'source-language' ] = ( null !== $xliffNode->attributes->getNamedItem( 'srcLang' ) ) ? $xliffNode->attributes->getNamedItem( 'srcLang' )->nodeValue : 'en-US'; |
|
66 | + $metadata['source-language'] = (null !== $xliffNode->attributes->getNamedItem('srcLang')) ? $xliffNode->attributes->getNamedItem('srcLang')->nodeValue : 'en-US'; |
|
67 | 67 | |
68 | 68 | // datatype |
69 | 69 | // @TODO to be implemented |
70 | 70 | |
71 | 71 | // target-language |
72 | - $metadata[ 'target-language' ] = ( null !== $xliffNode->attributes->getNamedItem( 'trgLang' ) ) ? $xliffNode->attributes->getNamedItem( 'trgLang' )->nodeValue : 'en-US'; |
|
72 | + $metadata['target-language'] = (null !== $xliffNode->attributes->getNamedItem('trgLang')) ? $xliffNode->attributes->getNamedItem('trgLang')->nodeValue : 'en-US'; |
|
73 | 73 | |
74 | 74 | // custom MateCat x-attribute |
75 | 75 | // @TODO to be implemented |
@@ -83,16 +83,16 @@ discard block |
||
83 | 83 | * @return array |
84 | 84 | * @throws \Exception |
85 | 85 | */ |
86 | - private function extractNotes( DOMElement $file ) { |
|
86 | + private function extractNotes(DOMElement $file) { |
|
87 | 87 | $notes = []; |
88 | 88 | |
89 | 89 | // loop <notes> to get nested <note> tag |
90 | - foreach ( $file->childNodes as $childNode ) { |
|
91 | - if ( $childNode->nodeName === 'notes' ) { |
|
92 | - foreach ( $childNode->childNodes as $note ) { |
|
93 | - $noteValue = trim( $note->nodeValue ); |
|
94 | - if ( '' !== $noteValue ) { |
|
95 | - $notes[] = $this->JSONOrRawContentArray( $noteValue ); |
|
90 | + foreach ($file->childNodes as $childNode) { |
|
91 | + if ($childNode->nodeName === 'notes') { |
|
92 | + foreach ($childNode->childNodes as $note) { |
|
93 | + $noteValue = trim($note->nodeValue); |
|
94 | + if ('' !== $noteValue) { |
|
95 | + $notes[] = $this->JSONOrRawContentArray($noteValue); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | } |
@@ -114,34 +114,34 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @throws \Exception |
116 | 116 | */ |
117 | - protected function extractTransUnit( $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j, $contextGroups = [] ) { |
|
117 | + protected function extractTransUnit($transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j, $contextGroups = []) { |
|
118 | 118 | // metadata |
119 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ] = $this->extractTransUnitMetadata( $transUnit, $transUnitIdArrayForUniquenessCheck ); |
|
119 | + $output['files'][$i]['trans-units'][$j]['attr'] = $this->extractTransUnitMetadata($transUnit, $transUnitIdArrayForUniquenessCheck); |
|
120 | 120 | |
121 | 121 | // notes |
122 | 122 | // merge <notes> with key and key-note contained in metadata <mda:metaGroup> |
123 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'notes' ] = $this->extractTransUnitNotes( $transUnit ); |
|
123 | + $output['files'][$i]['trans-units'][$j]['notes'] = $this->extractTransUnitNotes($transUnit); |
|
124 | 124 | |
125 | 125 | // uuid |
126 | - foreach ( $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'notes' ] as $note ) { |
|
127 | - if ( isset( $note[ 'raw-content' ] ) && Strings::isAValidUuid( $note[ 'raw-content' ] ) ) { |
|
128 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ][ 'uuid' ] = $note[ 'raw-content' ]; |
|
126 | + foreach ($output['files'][$i]['trans-units'][$j]['notes'] as $note) { |
|
127 | + if (isset($note['raw-content']) && Strings::isAValidUuid($note['raw-content'])) { |
|
128 | + $output['files'][$i]['trans-units'][$j]['attr']['uuid'] = $note['raw-content']; |
|
129 | 129 | } |
130 | 130 | } |
131 | 131 | |
132 | 132 | // original-data (exclusive for V2) |
133 | 133 | // http://docs.oasis-open.org/xliff/xliff-core/v2.0/xliff-core-v2.0.html#originaldata |
134 | - $originalData = $this->extractTransUnitOriginalData( $transUnit ); |
|
134 | + $originalData = $this->extractTransUnitOriginalData($transUnit); |
|
135 | 135 | $dataRefMap = null; |
136 | - if ( !empty( $originalData ) ) { |
|
137 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'original-data' ] = $originalData; |
|
138 | - $dataRefMap = $this->getDataRefMap( $originalData ); |
|
136 | + if (!empty($originalData)) { |
|
137 | + $output['files'][$i]['trans-units'][$j]['original-data'] = $originalData; |
|
138 | + $dataRefMap = $this->getDataRefMap($originalData); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | // additionalTagData (exclusive for V2) |
142 | - $additionalTagData = $this->extractTransUnitAdditionalTagData( $transUnit ); |
|
143 | - if ( !empty( $additionalTagData ) ) { |
|
144 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'additional-tag-data' ] = $additionalTagData; |
|
142 | + $additionalTagData = $this->extractTransUnitAdditionalTagData($transUnit); |
|
143 | + if (!empty($additionalTagData)) { |
|
144 | + $output['files'][$i]['trans-units'][$j]['additional-tag-data'] = $additionalTagData; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | // content |
@@ -161,64 +161,64 @@ discard block |
||
161 | 161 | |
162 | 162 | /** @var DOMElement $segment */ |
163 | 163 | $c = 0; |
164 | - foreach ( $transUnit->childNodes as $segment ) { |
|
165 | - if ( $segment->nodeName === 'segment' ) { |
|
164 | + foreach ($transUnit->childNodes as $segment) { |
|
165 | + if ($segment->nodeName === 'segment') { |
|
166 | 166 | |
167 | 167 | // check segment id consistency |
168 | - $attr = $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ]; |
|
169 | - $this->checkSegmentIdConsistency( $segment, $attr ); |
|
168 | + $attr = $output['files'][$i]['trans-units'][$j]['attr']; |
|
169 | + $this->checkSegmentIdConsistency($segment, $attr); |
|
170 | 170 | |
171 | 171 | // loop <segment> to get nested <source> and <target> tag |
172 | - foreach ( $segment->childNodes as $childNode ) { |
|
173 | - if ( $childNode->nodeName === 'source' ) { |
|
174 | - $extractedSource = $this->extractContent( $dom, $childNode ); |
|
175 | - $source[ 'raw-content' ][ $c ] = $extractedSource[ 'raw-content' ]; |
|
172 | + foreach ($segment->childNodes as $childNode) { |
|
173 | + if ($childNode->nodeName === 'source') { |
|
174 | + $extractedSource = $this->extractContent($dom, $childNode); |
|
175 | + $source['raw-content'][$c] = $extractedSource['raw-content']; |
|
176 | 176 | |
177 | - if ( !empty( $originalData ) ) { |
|
178 | - $source[ 'replaced-content' ][ $c ] = ( new DataRefReplacer( $dataRefMap ) )->replace( $source[ 'raw-content' ][ $c ] ); |
|
177 | + if (!empty($originalData)) { |
|
178 | + $source['replaced-content'][$c] = (new DataRefReplacer($dataRefMap))->replace($source['raw-content'][$c]); |
|
179 | 179 | } |
180 | 180 | |
181 | - if ( !empty( $extractedSource[ 'attr' ] ) ) { |
|
182 | - $source[ 'attr' ][ $c ] = $extractedSource[ 'attr' ]; |
|
181 | + if (!empty($extractedSource['attr'])) { |
|
182 | + $source['attr'][$c] = $extractedSource['attr']; |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | // append value to 'seg-source' |
186 | - if ( $this->stringContainsMarks( $extractedSource[ 'raw-content' ] ) ) { |
|
187 | - $segSource = $this->extractContentWithMarksAndExtTags( $dom, $childNode, $extractedSource[ 'raw-content' ], $originalData ); |
|
186 | + if ($this->stringContainsMarks($extractedSource['raw-content'])) { |
|
187 | + $segSource = $this->extractContentWithMarksAndExtTags($dom, $childNode, $extractedSource['raw-content'], $originalData); |
|
188 | 188 | } else { |
189 | 189 | $segSource[] = [ |
190 | - 'attr' => $this->extractTagAttributes( $segment), |
|
191 | - 'mid' => count( $segSource ) > 0 ? count( $segSource ) : 0, |
|
190 | + 'attr' => $this->extractTagAttributes($segment), |
|
191 | + 'mid' => count($segSource) > 0 ? count($segSource) : 0, |
|
192 | 192 | 'ext-prec-tags' => '', |
193 | - 'raw-content' => $extractedSource[ 'raw-content' ], |
|
194 | - 'replaced-content' => ( !empty( $originalData ) ) ? ( new DataRefReplacer( $dataRefMap ) )->replace( $extractedSource[ 'raw-content' ] ) : null, |
|
193 | + 'raw-content' => $extractedSource['raw-content'], |
|
194 | + 'replaced-content' => (!empty($originalData)) ? (new DataRefReplacer($dataRefMap))->replace($extractedSource['raw-content']) : null, |
|
195 | 195 | 'ext-succ-tags' => '', |
196 | 196 | ]; |
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
200 | - if ( $childNode->nodeName === 'target' ) { |
|
201 | - $extractedTarget = $this->extractContent( $dom, $childNode ); |
|
202 | - $target[ 'raw-content' ][ $c ] = $extractedTarget[ 'raw-content' ]; |
|
200 | + if ($childNode->nodeName === 'target') { |
|
201 | + $extractedTarget = $this->extractContent($dom, $childNode); |
|
202 | + $target['raw-content'][$c] = $extractedTarget['raw-content']; |
|
203 | 203 | |
204 | - if ( !empty( $originalData ) ) { |
|
205 | - $target[ 'replaced-content' ][ $c ] = ( new DataRefReplacer( $dataRefMap ) )->replace( $target[ 'raw-content' ][ $c ] ); |
|
204 | + if (!empty($originalData)) { |
|
205 | + $target['replaced-content'][$c] = (new DataRefReplacer($dataRefMap))->replace($target['raw-content'][$c]); |
|
206 | 206 | } |
207 | 207 | |
208 | - if ( !empty( $extractedTarget[ 'attr' ] ) ) { |
|
209 | - $target[ 'attr' ][ $c ] = $extractedTarget[ 'attr' ]; |
|
208 | + if (!empty($extractedTarget['attr'])) { |
|
209 | + $target['attr'][$c] = $extractedTarget['attr']; |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | // append value to 'seg-target' |
213 | - if ( $this->stringContainsMarks( $extractedTarget[ 'raw-content' ] ) ) { |
|
214 | - $segTarget = $this->extractContentWithMarksAndExtTags( $dom, $childNode, $extractedTarget[ 'raw-content' ], $originalData ); |
|
213 | + if ($this->stringContainsMarks($extractedTarget['raw-content'])) { |
|
214 | + $segTarget = $this->extractContentWithMarksAndExtTags($dom, $childNode, $extractedTarget['raw-content'], $originalData); |
|
215 | 215 | } else { |
216 | 216 | $segTarget[] = [ |
217 | - 'attr' => $this->extractTagAttributes( $segment), |
|
218 | - 'mid' => count( $segTarget ) > 0 ? count( $segTarget ) : 0, |
|
217 | + 'attr' => $this->extractTagAttributes($segment), |
|
218 | + 'mid' => count($segTarget) > 0 ? count($segTarget) : 0, |
|
219 | 219 | 'ext-prec-tags' => '', |
220 | - 'raw-content' => $extractedTarget[ 'raw-content' ], |
|
221 | - 'replaced-content' => ( !empty( $originalData ) ) ? ( new DataRefReplacer( $dataRefMap ) )->replace( $extractedTarget[ 'raw-content' ] ) : null, |
|
220 | + 'raw-content' => $extractedTarget['raw-content'], |
|
221 | + 'replaced-content' => (!empty($originalData)) ? (new DataRefReplacer($dataRefMap))->replace($extractedTarget['raw-content']) : null, |
|
222 | 222 | 'ext-succ-tags' => '', |
223 | 223 | ]; |
224 | 224 | } |
@@ -229,10 +229,10 @@ discard block |
||
229 | 229 | } |
230 | 230 | } |
231 | 231 | |
232 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'source' ] = $source; |
|
233 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'target' ] = $target; |
|
234 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-source' ] = $segSource; |
|
235 | - $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-target' ] = $segTarget; |
|
232 | + $output['files'][$i]['trans-units'][$j]['source'] = $source; |
|
233 | + $output['files'][$i]['trans-units'][$j]['target'] = $target; |
|
234 | + $output['files'][$i]['trans-units'][$j]['seg-source'] = $segSource; |
|
235 | + $output['files'][$i]['trans-units'][$j]['seg-target'] = $segTarget; |
|
236 | 236 | |
237 | 237 | $j++; |
238 | 238 | } |
@@ -243,41 +243,41 @@ discard block |
||
243 | 243 | * |
244 | 244 | * @return array |
245 | 245 | */ |
246 | - private function extractTransUnitMetadata( DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck ) { |
|
246 | + private function extractTransUnitMetadata(DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck) { |
|
247 | 247 | $metadata = []; |
248 | 248 | |
249 | 249 | // id |
250 | - if ( null === $transUnit->attributes->getNamedItem( 'id' ) ) { |
|
251 | - throw new NotFoundIdInTransUnit( 'Invalid trans-unit id found. EMPTY value', 400 ); |
|
250 | + if (null === $transUnit->attributes->getNamedItem('id')) { |
|
251 | + throw new NotFoundIdInTransUnit('Invalid trans-unit id found. EMPTY value', 400); |
|
252 | 252 | } |
253 | 253 | |
254 | - $id = $transUnit->attributes->getNamedItem( 'id' )->nodeValue; |
|
254 | + $id = $transUnit->attributes->getNamedItem('id')->nodeValue; |
|
255 | 255 | |
256 | - if ( strlen( $id ) > 100 ) { |
|
257 | - throw new SegmentIdTooLongException( 'Segment-id too long. Max 100 characters allowed', 400 ); |
|
256 | + if (strlen($id) > 100) { |
|
257 | + throw new SegmentIdTooLongException('Segment-id too long. Max 100 characters allowed', 400); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | $transUnitIdArrayForUniquenessCheck[] = $id; |
261 | - $metadata[ 'id' ] = $id; |
|
261 | + $metadata['id'] = $id; |
|
262 | 262 | |
263 | 263 | // translate |
264 | - if ( null !== $transUnit->attributes->getNamedItem( 'translate' ) ) { |
|
265 | - $metadata[ 'translate' ] = $transUnit->attributes->getNamedItem( 'translate' )->nodeValue; |
|
264 | + if (null !== $transUnit->attributes->getNamedItem('translate')) { |
|
265 | + $metadata['translate'] = $transUnit->attributes->getNamedItem('translate')->nodeValue; |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | // tGroupBegin |
269 | - if ( null !== $transUnit->attributes->getNamedItem( 'tGroupBegin' ) ) { |
|
270 | - $metadata[ 'tGroupBegin' ] = $transUnit->attributes->getNamedItem( 'tGroupBegin' )->nodeValue; |
|
269 | + if (null !== $transUnit->attributes->getNamedItem('tGroupBegin')) { |
|
270 | + $metadata['tGroupBegin'] = $transUnit->attributes->getNamedItem('tGroupBegin')->nodeValue; |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | // tGroupEnd |
274 | - if ( null !== $transUnit->attributes->getNamedItem( 'tGroupEnd' ) ) { |
|
275 | - $metadata[ 'tGroupEnd' ] = $transUnit->attributes->getNamedItem( 'tGroupEnd' )->nodeValue; |
|
274 | + if (null !== $transUnit->attributes->getNamedItem('tGroupEnd')) { |
|
275 | + $metadata['tGroupEnd'] = $transUnit->attributes->getNamedItem('tGroupEnd')->nodeValue; |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | // sizeRestriction |
279 | - if ( null !== $transUnit->attributes->getNamedItem( 'sizeRestriction' ) && '' !== $transUnit->attributes->getNamedItem( 'sizeRestriction' )->nodeValue ) { |
|
280 | - $metadata[ 'sizeRestriction' ] = (int)$transUnit->attributes->getNamedItem( 'sizeRestriction' )->nodeValue; |
|
279 | + if (null !== $transUnit->attributes->getNamedItem('sizeRestriction') && '' !== $transUnit->attributes->getNamedItem('sizeRestriction')->nodeValue) { |
|
280 | + $metadata['sizeRestriction'] = (int)$transUnit->attributes->getNamedItem('sizeRestriction')->nodeValue; |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | return $metadata; |
@@ -289,31 +289,31 @@ discard block |
||
289 | 289 | * @return array |
290 | 290 | * @throws \Exception |
291 | 291 | */ |
292 | - private function extractTransUnitOriginalData( DOMElement $transUnit ) { |
|
292 | + private function extractTransUnitOriginalData(DOMElement $transUnit) { |
|
293 | 293 | $originalData = []; |
294 | 294 | |
295 | 295 | // loop <originalData> to get nested content |
296 | - foreach ( $transUnit->childNodes as $childNode ) { |
|
297 | - if ( $childNode->nodeName === 'originalData' ) { |
|
298 | - foreach ( $childNode->childNodes as $data ) { |
|
299 | - if ( null !== $data->attributes && null !== $data->attributes->getNamedItem( 'id' ) ) { |
|
300 | - $dataId = $data->attributes->getNamedItem( 'id' )->nodeValue; |
|
296 | + foreach ($transUnit->childNodes as $childNode) { |
|
297 | + if ($childNode->nodeName === 'originalData') { |
|
298 | + foreach ($childNode->childNodes as $data) { |
|
299 | + if (null !== $data->attributes && null !== $data->attributes->getNamedItem('id')) { |
|
300 | + $dataId = $data->attributes->getNamedItem('id')->nodeValue; |
|
301 | 301 | |
302 | - $dataValue = str_replace( Placeholder::WHITE_SPACE_PLACEHOLDER, ' ', $data->nodeValue ); |
|
303 | - $dataValue = str_replace( Placeholder::NEW_LINE_PLACEHOLDER, '\n', $dataValue ); |
|
304 | - $dataValue = str_replace( Placeholder::TAB_PLACEHOLDER, '\t', $dataValue ); |
|
302 | + $dataValue = str_replace(Placeholder::WHITE_SPACE_PLACEHOLDER, ' ', $data->nodeValue); |
|
303 | + $dataValue = str_replace(Placeholder::NEW_LINE_PLACEHOLDER, '\n', $dataValue); |
|
304 | + $dataValue = str_replace(Placeholder::TAB_PLACEHOLDER, '\t', $dataValue); |
|
305 | 305 | |
306 | - if ( '' !== $dataValue ) { |
|
306 | + if ('' !== $dataValue) { |
|
307 | 307 | |
308 | - $jsonOrRawContentArray = $this->JSONOrRawContentArray( $dataValue, false ); |
|
308 | + $jsonOrRawContentArray = $this->JSONOrRawContentArray($dataValue, false); |
|
309 | 309 | |
310 | 310 | // restore xliff tags |
311 | - if ( isset( $jsonOrRawContentArray[ 'json' ] ) ) { |
|
312 | - $jsonOrRawContentArray[ 'json' ] = str_replace( [ Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER ], [ '<', '>' ], $jsonOrRawContentArray[ 'json' ] ); |
|
311 | + if (isset($jsonOrRawContentArray['json'])) { |
|
312 | + $jsonOrRawContentArray['json'] = str_replace([Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER], ['<', '>'], $jsonOrRawContentArray['json']); |
|
313 | 313 | } |
314 | 314 | |
315 | - if ( isset( $jsonOrRawContentArray[ 'raw-content' ] ) ) { |
|
316 | - $jsonOrRawContentArray[ 'raw-content' ] = str_replace( [ Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER ], [ '<', '>' ], $jsonOrRawContentArray[ 'raw-content' ] ); |
|
315 | + if (isset($jsonOrRawContentArray['raw-content'])) { |
|
316 | + $jsonOrRawContentArray['raw-content'] = str_replace([Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER], ['<', '>'], $jsonOrRawContentArray['raw-content']); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | $originalData[] = array_merge( |
@@ -338,41 +338,41 @@ discard block |
||
338 | 338 | * |
339 | 339 | * @return array |
340 | 340 | */ |
341 | - private function extractTransUnitAdditionalTagData( DOMElement $transUnit ) { |
|
341 | + private function extractTransUnitAdditionalTagData(DOMElement $transUnit) { |
|
342 | 342 | $additionalTagData = []; |
343 | 343 | |
344 | 344 | // loop <originalData> to get nested content |
345 | - foreach ( $transUnit->childNodes as $childNode ) { |
|
346 | - if ( $childNode->nodeName === 'memsource:additionalTagData' ) { |
|
347 | - foreach ( $childNode->childNodes as $data ) { |
|
345 | + foreach ($transUnit->childNodes as $childNode) { |
|
346 | + if ($childNode->nodeName === 'memsource:additionalTagData') { |
|
347 | + foreach ($childNode->childNodes as $data) { |
|
348 | 348 | $dataArray = []; |
349 | 349 | |
350 | 350 | // id |
351 | - if ( $data->nodeName === 'memsource:tag' ) { |
|
352 | - if ( null !== $data->attributes && null !== $data->attributes->getNamedItem( 'id' ) ) { |
|
353 | - $dataId = $data->attributes->getNamedItem( 'id' )->nodeValue; |
|
354 | - $dataArray[ 'attr' ][ 'id' ] = $dataId; |
|
351 | + if ($data->nodeName === 'memsource:tag') { |
|
352 | + if (null !== $data->attributes && null !== $data->attributes->getNamedItem('id')) { |
|
353 | + $dataId = $data->attributes->getNamedItem('id')->nodeValue; |
|
354 | + $dataArray['attr']['id'] = $dataId; |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | |
358 | 358 | // in PHP 7.4 $data->childNodes is an empty DomNodeList, it is iterable with size 0 |
359 | 359 | // PHP 5.6 check: in php 5.6 $data->childNodes can be null |
360 | - if ( $data->childNodes != null ) { |
|
360 | + if ($data->childNodes != null) { |
|
361 | 361 | |
362 | 362 | // content |
363 | - foreach ( $data->childNodes as $datum ) { |
|
364 | - if ( $datum->nodeName === 'memsource:tagId' ) { |
|
365 | - $dataArray[ 'raw-content' ][ 'tagId' ] = $datum->nodeValue; |
|
363 | + foreach ($data->childNodes as $datum) { |
|
364 | + if ($datum->nodeName === 'memsource:tagId') { |
|
365 | + $dataArray['raw-content']['tagId'] = $datum->nodeValue; |
|
366 | 366 | } |
367 | 367 | |
368 | - if ( $datum->nodeName === 'memsource:type' ) { |
|
369 | - $dataArray[ 'raw-content' ][ 'type' ] = $datum->nodeValue; |
|
368 | + if ($datum->nodeName === 'memsource:type') { |
|
369 | + $dataArray['raw-content']['type'] = $datum->nodeValue; |
|
370 | 370 | } |
371 | 371 | } |
372 | 372 | |
373 | 373 | } |
374 | 374 | |
375 | - if ( !empty( $dataArray ) ) { |
|
375 | + if (!empty($dataArray)) { |
|
376 | 376 | $additionalTagData[] = $dataArray; |
377 | 377 | } |
378 | 378 | } |
@@ -388,15 +388,15 @@ discard block |
||
388 | 388 | * @param DOMElement $segment |
389 | 389 | * @param array $attr |
390 | 390 | */ |
391 | - private function checkSegmentIdConsistency( DOMElement $segment, array $attr ) { |
|
392 | - if ( isset( $attr[ 'tGroupBegin' ] ) && isset( $attr[ 'tGroupEnd' ] ) && $segment->attributes->getNamedItem( 'id' ) ) { |
|
393 | - $id = $segment->attributes->getNamedItem( 'id' )->nodeValue; |
|
394 | - $min = (int)$attr[ 'tGroupBegin' ]; |
|
395 | - $max = (int)$attr[ 'tGroupEnd' ]; |
|
396 | - |
|
397 | - if ( false === ( ( $min <= $id ) && ( $id <= $max ) ) ) { |
|
398 | - if ( $this->logger ) { |
|
399 | - $this->logger->warning( 'Segment #' . $id . ' is not included within tGroupBegin and tGroupEnd' ); |
|
391 | + private function checkSegmentIdConsistency(DOMElement $segment, array $attr) { |
|
392 | + if (isset($attr['tGroupBegin']) && isset($attr['tGroupEnd']) && $segment->attributes->getNamedItem('id')) { |
|
393 | + $id = $segment->attributes->getNamedItem('id')->nodeValue; |
|
394 | + $min = (int)$attr['tGroupBegin']; |
|
395 | + $max = (int)$attr['tGroupEnd']; |
|
396 | + |
|
397 | + if (false === (($min <= $id) && ($id <= $max))) { |
|
398 | + if ($this->logger) { |
|
399 | + $this->logger->warning('Segment #' . $id . ' is not included within tGroupBegin and tGroupEnd'); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 | } |
@@ -408,31 +408,31 @@ discard block |
||
408 | 408 | * @return array |
409 | 409 | * @throws \Exception |
410 | 410 | */ |
411 | - private function extractTransUnitNotes( DOMElement $transUnit ) { |
|
411 | + private function extractTransUnitNotes(DOMElement $transUnit) { |
|
412 | 412 | $notes = []; |
413 | 413 | |
414 | 414 | // loop <notes> to get nested <note> tag |
415 | - foreach ( $transUnit->childNodes as $childNode ) { |
|
416 | - if ( $childNode->nodeName == 'notes' ) { |
|
417 | - foreach ( $childNode->childNodes as $note ) { |
|
418 | - $noteValue = trim( $note->nodeValue ); |
|
419 | - if ( '' !== $noteValue ) { |
|
420 | - $notes[] = $this->JSONOrRawContentArray( $noteValue ); |
|
415 | + foreach ($transUnit->childNodes as $childNode) { |
|
416 | + if ($childNode->nodeName == 'notes') { |
|
417 | + foreach ($childNode->childNodes as $note) { |
|
418 | + $noteValue = trim($note->nodeValue); |
|
419 | + if ('' !== $noteValue) { |
|
420 | + $notes[] = $this->JSONOrRawContentArray($noteValue); |
|
421 | 421 | } |
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
425 | - if ( $childNode->nodeName === 'mda:metadata' ) { |
|
426 | - foreach ( $childNode->childNodes as $metadata ) { |
|
427 | - if ( $metadata->nodeName === 'mda:metaGroup' ) { |
|
428 | - foreach ( $metadata->childNodes as $meta ) { |
|
429 | - if ( null !== $meta->attributes && null !== $meta->attributes->getNamedItem( 'type' ) ) { |
|
430 | - $type = $meta->attributes->getNamedItem( 'type' )->nodeValue; |
|
431 | - $metaValue = trim( $meta->nodeValue ); |
|
425 | + if ($childNode->nodeName === 'mda:metadata') { |
|
426 | + foreach ($childNode->childNodes as $metadata) { |
|
427 | + if ($metadata->nodeName === 'mda:metaGroup') { |
|
428 | + foreach ($metadata->childNodes as $meta) { |
|
429 | + if (null !== $meta->attributes && null !== $meta->attributes->getNamedItem('type')) { |
|
430 | + $type = $meta->attributes->getNamedItem('type')->nodeValue; |
|
431 | + $metaValue = trim($meta->nodeValue); |
|
432 | 432 | |
433 | - if ( '' !== $metaValue ) { |
|
433 | + if ('' !== $metaValue) { |
|
434 | 434 | $notes[] = array_merge( |
435 | - $this->JSONOrRawContentArray( $metaValue ), |
|
435 | + $this->JSONOrRawContentArray($metaValue), |
|
436 | 436 | [ |
437 | 437 | 'attr' => [ |
438 | 438 | 'type' => $type |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @param string|null $xliffProprietary |
38 | 38 | * @param LoggerInterface|null $logger |
39 | 39 | */ |
40 | - public function __construct( $xliffVersion, $xliffProprietary = null, LoggerInterface $logger = null ) { |
|
40 | + public function __construct($xliffVersion, $xliffProprietary = null, LoggerInterface $logger = null) { |
|
41 | 41 | $this->xliffVersion = $xliffVersion; |
42 | 42 | $this->logger = $logger; |
43 | 43 | $this->xliffProprietary = $xliffProprietary; |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @return string |
48 | 48 | */ |
49 | 49 | protected function getTuTagName() { |
50 | - return ( $this->xliffVersion === 1 ) ? 'trans-unit' : 'unit'; |
|
50 | + return ($this->xliffVersion === 1) ? 'trans-unit' : 'unit'; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return array |
57 | 57 | */ |
58 | - abstract public function parse( DOMDocument $dom, $output = [] ); |
|
58 | + abstract public function parse(DOMDocument $dom, $output = []); |
|
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Extract trans-unit content from the current node |
@@ -69,33 +69,33 @@ discard block |
||
69 | 69 | * @param array $contextGroups |
70 | 70 | * @param int $recursionLevel |
71 | 71 | */ |
72 | - protected function extractTuFromNode( $childNode, &$transUnitIdArrayForUniquenessCheck, DOMDocument $dom, &$output, &$i, &$j, $contextGroups = [], $recursionLevel = 0 ) { |
|
73 | - if ( $childNode->nodeName === 'group' ) { |
|
72 | + protected function extractTuFromNode($childNode, &$transUnitIdArrayForUniquenessCheck, DOMDocument $dom, &$output, &$i, &$j, $contextGroups = [], $recursionLevel = 0) { |
|
73 | + if ($childNode->nodeName === 'group') { |
|
74 | 74 | |
75 | 75 | // add nested context-groups |
76 | - foreach ( $childNode->childNodes as $nestedChildNode ) { |
|
77 | - if ( $nestedChildNode->nodeName === 'context-group' ) { |
|
76 | + foreach ($childNode->childNodes as $nestedChildNode) { |
|
77 | + if ($nestedChildNode->nodeName === 'context-group') { |
|
78 | 78 | $contextGroups[] = $nestedChildNode; |
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | - foreach ( $childNode->childNodes as $nestedChildNode ) { |
|
82 | + foreach ($childNode->childNodes as $nestedChildNode) { |
|
83 | 83 | |
84 | 84 | // nested groups |
85 | - if ( $nestedChildNode->nodeName === 'group' ) { |
|
85 | + if ($nestedChildNode->nodeName === 'group') { |
|
86 | 86 | |
87 | 87 | // avoid infinite recursion |
88 | 88 | $recursionLevel++; |
89 | - if($recursionLevel < self::MAX_GROUP_RECURSION_LEVEL){ |
|
90 | - $this->extractTuFromNode( $nestedChildNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j, $contextGroups, $recursionLevel ); |
|
89 | + if ($recursionLevel < self::MAX_GROUP_RECURSION_LEVEL) { |
|
90 | + $this->extractTuFromNode($nestedChildNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j, $contextGroups, $recursionLevel); |
|
91 | 91 | } |
92 | 92 | |
93 | - } elseif ( $nestedChildNode->nodeName === $this->getTuTagName() ) { |
|
94 | - $this->extractTransUnit( $nestedChildNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j, $contextGroups ); |
|
93 | + } elseif ($nestedChildNode->nodeName === $this->getTuTagName()) { |
|
94 | + $this->extractTransUnit($nestedChildNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j, $contextGroups); |
|
95 | 95 | } |
96 | 96 | } |
97 | - } elseif ( $childNode->nodeName === $this->getTuTagName() ) { |
|
98 | - $this->extractTransUnit( $childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j, $contextGroups ); |
|
97 | + } elseif ($childNode->nodeName === $this->getTuTagName()) { |
|
98 | + $this->extractTransUnit($childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j, $contextGroups); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return mixed |
114 | 114 | */ |
115 | - abstract protected function extractTransUnit( $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j,$contextGroups = [] ); |
|
115 | + abstract protected function extractTransUnit($transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j, $contextGroups = []); |
|
116 | 116 | |
117 | 117 | /** |
118 | 118 | * @param DOMDocument $dom |
@@ -120,10 +120,10 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @return array |
122 | 122 | */ |
123 | - protected function extractContent( DOMDocument $dom, DOMNode $node ) { |
|
123 | + protected function extractContent(DOMDocument $dom, DOMNode $node) { |
|
124 | 124 | return [ |
125 | - 'raw-content' => $this->extractTagContent( $dom, $node ), |
|
126 | - 'attr' => $this->extractTagAttributes( $node ) |
|
125 | + 'raw-content' => $this->extractTagContent($dom, $node), |
|
126 | + 'attr' => $this->extractTagAttributes($node) |
|
127 | 127 | ]; |
128 | 128 | } |
129 | 129 | |
@@ -140,12 +140,12 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return array |
142 | 142 | */ |
143 | - protected function extractTagAttributes( DOMNode $element ) { |
|
143 | + protected function extractTagAttributes(DOMNode $element) { |
|
144 | 144 | $tagAttributes = []; |
145 | 145 | |
146 | - if ( $element->hasAttributes() ) { |
|
147 | - foreach ( $element->attributes as $attr ) { |
|
148 | - $tagAttributes[ $attr->nodeName ] = $attr->nodeValue; |
|
146 | + if ($element->hasAttributes()) { |
|
147 | + foreach ($element->attributes as $attr) { |
|
148 | + $tagAttributes[$attr->nodeName] = $attr->nodeValue; |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
@@ -160,17 +160,17 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @return string |
162 | 162 | */ |
163 | - protected function extractTagContent( DOMDocument $dom, DOMNode $element ) { |
|
163 | + protected function extractTagContent(DOMDocument $dom, DOMNode $element) { |
|
164 | 164 | $childNodes = $element->hasChildNodes(); |
165 | 165 | $extractedContent = ''; |
166 | 166 | |
167 | - if ( !empty( $childNodes ) ) { |
|
168 | - foreach ( $element->childNodes as $node ) { |
|
169 | - $extractedContent .= Emoji::toEntity( Strings::fixNonWellFormedXml( $dom->saveXML( $node ) ) ); |
|
167 | + if (!empty($childNodes)) { |
|
168 | + foreach ($element->childNodes as $node) { |
|
169 | + $extractedContent .= Emoji::toEntity(Strings::fixNonWellFormedXml($dom->saveXML($node))); |
|
170 | 170 | } |
171 | 171 | } |
172 | 172 | |
173 | - return str_replace( Placeholder::EMPTY_TAG_PLACEHOLDER, '', $extractedContent ); |
|
173 | + return str_replace(Placeholder::EMPTY_TAG_PLACEHOLDER, '', $extractedContent); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -183,50 +183,50 @@ discard block |
||
183 | 183 | * |
184 | 184 | * @return array |
185 | 185 | */ |
186 | - protected function extractContentWithMarksAndExtTags( DOMDocument $dom, DOMElement $childNode, $originalRawContent, array $originalData = [] ) { |
|
186 | + protected function extractContentWithMarksAndExtTags(DOMDocument $dom, DOMElement $childNode, $originalRawContent, array $originalData = []) { |
|
187 | 187 | $source = []; |
188 | 188 | |
189 | 189 | // example: |
190 | 190 | // <g id="1"><mrk mid="0" mtype="seg">An English string with g tags</mrk></g> |
191 | - $raw = $this->extractTagContent( $dom, $childNode ); |
|
191 | + $raw = $this->extractTagContent($dom, $childNode); |
|
192 | 192 | |
193 | - $markers = preg_split( '#<mrk\s#si', $raw, -1 ); |
|
193 | + $markers = preg_split('#<mrk\s#si', $raw, -1); |
|
194 | 194 | |
195 | 195 | $mi = 0; |
196 | - while ( isset( $markers[ $mi + 1 ] ) ) { |
|
197 | - unset( $mid ); |
|
196 | + while (isset($markers[$mi + 1])) { |
|
197 | + unset($mid); |
|
198 | 198 | |
199 | - preg_match( '|mid\s?=\s?["\'](.*?)["\']|si', $markers[ $mi + 1 ], $mid ); |
|
199 | + preg_match('|mid\s?=\s?["\'](.*?)["\']|si', $markers[$mi + 1], $mid); |
|
200 | 200 | |
201 | 201 | // if it's a Trados file the trailing spaces after </mrk> are meaningful |
202 | 202 | // so we add them to |
203 | 203 | $trailingSpaces = ''; |
204 | - if ( $this->xliffProprietary === 'trados' ) { |
|
205 | - preg_match_all( '/<\/mrk>[\s]+/iu', $markers[ $mi + 1 ], $trailingSpacesMatches ); |
|
204 | + if ($this->xliffProprietary === 'trados') { |
|
205 | + preg_match_all('/<\/mrk>[\s]+/iu', $markers[$mi + 1], $trailingSpacesMatches); |
|
206 | 206 | |
207 | - if ( isset( $trailingSpacesMatches[ 0 ] ) && count( $trailingSpacesMatches[ 0 ] ) > 0 ) { |
|
208 | - foreach ( $trailingSpacesMatches[ 0 ] as $match ) { |
|
209 | - $trailingSpaces = str_replace( '</mrk>', '', $match ); |
|
207 | + if (isset($trailingSpacesMatches[0]) && count($trailingSpacesMatches[0]) > 0) { |
|
208 | + foreach ($trailingSpacesMatches[0] as $match) { |
|
209 | + $trailingSpaces = str_replace('</mrk>', '', $match); |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
214 | 214 | //re-build the mrk tag after the split |
215 | - $originalMark = trim( '<mrk ' . $markers[ $mi + 1 ] ); |
|
215 | + $originalMark = trim('<mrk ' . $markers[$mi + 1]); |
|
216 | 216 | |
217 | - $mark_string = preg_replace( '#^<mrk\s[^>]+>(.*)#', '$1', $originalMark ); // at this point we have: ---> 'Test </mrk> </g>>' |
|
218 | - $mark_content = preg_split( '#</mrk>#si', $mark_string ); |
|
217 | + $mark_string = preg_replace('#^<mrk\s[^>]+>(.*)#', '$1', $originalMark); // at this point we have: ---> 'Test </mrk> </g>>' |
|
218 | + $mark_content = preg_split('#</mrk>#si', $mark_string); |
|
219 | 219 | |
220 | 220 | $sourceArray = [ |
221 | - 'mid' => ( isset( $mid[ 1 ] ) ) ? $mid[ 1 ] : $mi, |
|
222 | - 'ext-prec-tags' => ( $mi == 0 ? $markers[ 0 ] : "" ), |
|
223 | - 'raw-content' => ( isset( $mark_content[ 0 ] ) ) ? $mark_content[ 0 ] . $trailingSpaces : '', |
|
224 | - 'ext-succ-tags' => ( isset( $mark_content[ 1 ] ) ) ? $mark_content[ 1 ] : '', |
|
221 | + 'mid' => (isset($mid[1])) ? $mid[1] : $mi, |
|
222 | + 'ext-prec-tags' => ($mi == 0 ? $markers[0] : ""), |
|
223 | + 'raw-content' => (isset($mark_content[0])) ? $mark_content[0] . $trailingSpaces : '', |
|
224 | + 'ext-succ-tags' => (isset($mark_content[1])) ? $mark_content[1] : '', |
|
225 | 225 | ]; |
226 | 226 | |
227 | - if ( !empty( $originalData ) ) { |
|
228 | - $dataRefMap = $this->getDataRefMap( $originalData ); |
|
229 | - $sourceArray[ 'replaced-content' ] = ( new DataRefReplacer( $dataRefMap ) )->replace( $mark_content[ 0 ] ); |
|
227 | + if (!empty($originalData)) { |
|
228 | + $dataRefMap = $this->getDataRefMap($originalData); |
|
229 | + $sourceArray['replaced-content'] = (new DataRefReplacer($dataRefMap))->replace($mark_content[0]); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | $source[] = $sourceArray; |
@@ -242,12 +242,12 @@ discard block |
||
242 | 242 | * |
243 | 243 | * @return array |
244 | 244 | */ |
245 | - protected function getDataRefMap( $originalData ) { |
|
245 | + protected function getDataRefMap($originalData) { |
|
246 | 246 | // dataRef map |
247 | 247 | $dataRefMap = []; |
248 | - foreach ( $originalData as $datum ) { |
|
249 | - if ( isset( $datum[ 'attr' ][ 'id' ] ) ) { |
|
250 | - $dataRefMap[ $datum[ 'attr' ][ 'id' ] ] = $datum[ 'raw-content' ]; |
|
248 | + foreach ($originalData as $datum) { |
|
249 | + if (isset($datum['attr']['id'])) { |
|
250 | + $dataRefMap[$datum['attr']['id']] = $datum['raw-content']; |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | |
@@ -259,10 +259,10 @@ discard block |
||
259 | 259 | * |
260 | 260 | * @return bool |
261 | 261 | */ |
262 | - protected function stringContainsMarks( $raw ) { |
|
263 | - $markers = preg_split( '#<mrk\s#si', $raw, -1 ); |
|
262 | + protected function stringContainsMarks($raw) { |
|
263 | + $markers = preg_split('#<mrk\s#si', $raw, -1); |
|
264 | 264 | |
265 | - return isset( $markers[ 1 ] ); |
|
265 | + return isset($markers[1]); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | * @return array |
273 | 273 | * @throws \Exception |
274 | 274 | */ |
275 | - protected function JSONOrRawContentArray( $noteValue, $escapeStrings = true ) { |
|
275 | + protected function JSONOrRawContentArray($noteValue, $escapeStrings = true) { |
|
276 | 276 | // |
277 | 277 | // convert double escaped entites |
278 | 278 | // |
@@ -282,17 +282,17 @@ discard block |
||
282 | 282 | // &amp; ---> & |
283 | 283 | // &apos ---> ' |
284 | 284 | // |
285 | - if ( Strings::isADoubleEscapedEntity( $noteValue ) ) { |
|
286 | - $noteValue = Strings::htmlspecialchars_decode( $noteValue, true ); |
|
285 | + if (Strings::isADoubleEscapedEntity($noteValue)) { |
|
286 | + $noteValue = Strings::htmlspecialchars_decode($noteValue, true); |
|
287 | 287 | } else { |
288 | 288 | // for non escaped entities $escapeStrings is always true for security reasons |
289 | 289 | $escapeStrings = true; |
290 | 290 | } |
291 | 291 | |
292 | - if ( Strings::isJSON( $noteValue ) ) { |
|
293 | - return [ 'json' => Strings::cleanCDATA( $noteValue ) ]; |
|
292 | + if (Strings::isJSON($noteValue)) { |
|
293 | + return ['json' => Strings::cleanCDATA($noteValue)]; |
|
294 | 294 | } |
295 | 295 | |
296 | - return [ 'raw-content' => Strings::fixNonWellFormedXml( $noteValue, $escapeStrings ) ]; |
|
296 | + return ['raw-content' => Strings::fixNonWellFormedXml($noteValue, $escapeStrings)]; |
|
297 | 297 | } |
298 | 298 | } |