Passed
Push — master ( e40a60...993831 )
by Domenico
03:11
created
src/XliffParser/XliffParserV1.php 1 patch
Spacing   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -15,33 +15,33 @@  discard block
 block discarded – undo
15 15
      * @inheritDoc
16 16
      * @throws Exception
17 17
      */
18
-    public function parse( DOMDocument $dom, $output = [] ) {
18
+    public function parse(DOMDocument $dom, $output = []) {
19 19
         $i = 1;
20 20
         /** @var DOMElement $file */
21
-        foreach ( $dom->getElementsByTagName( 'file' ) as $file ) {
21
+        foreach ($dom->getElementsByTagName('file') as $file) {
22 22
 
23 23
             // metadata
24
-            $output[ 'files' ][ $i ][ 'attr' ] = $this->extractMetadata( $file );
24
+            $output['files'][$i]['attr'] = $this->extractMetadata($file);
25 25
 
26 26
             // reference
27
-            if ( !empty( $this->extractReference( $file ) ) ) {
28
-                $output[ 'files' ][ $i ][ 'reference' ] = $this->extractReference( $file );
27
+            if (!empty($this->extractReference($file))) {
28
+                $output['files'][$i]['reference'] = $this->extractReference($file);
29 29
             }
30 30
 
31 31
             // trans-units
32 32
             $transUnitIdArrayForUniquenessCheck = [];
33 33
             $j                                  = 1;
34
-            foreach ( $file->childNodes as $body ) {
35
-                if ( $body->nodeName === 'body' ) {
36
-                    foreach ( $body->childNodes as $childNode ) {
37
-                        $this->extractTuFromNode( $childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j );
34
+            foreach ($file->childNodes as $body) {
35
+                if ($body->nodeName === 'body') {
36
+                    foreach ($body->childNodes as $childNode) {
37
+                        $this->extractTuFromNode($childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j);
38 38
                     }
39 39
 
40 40
                     // trans-unit re-count check
41
-                    $totalTransUnitsId  = count( $transUnitIdArrayForUniquenessCheck );
42
-                    $transUnitsUniqueId = count( array_unique( $transUnitIdArrayForUniquenessCheck ) );
43
-                    if ( $totalTransUnitsId != $transUnitsUniqueId ) {
44
-                        throw new DuplicateTransUnitIdInXliff( "Invalid trans-unit id, duplicate found.", 400 );
41
+                    $totalTransUnitsId  = count($transUnitIdArrayForUniquenessCheck);
42
+                    $transUnitsUniqueId = count(array_unique($transUnitIdArrayForUniquenessCheck));
43
+                    if ($totalTransUnitsId != $transUnitsUniqueId) {
44
+                        throw new DuplicateTransUnitIdInXliff("Invalid trans-unit id, duplicate found.", 400);
45 45
                     }
46 46
 
47 47
                     $i++;
@@ -57,50 +57,50 @@  discard block
 block discarded – undo
57 57
      *
58 58
      * @return array
59 59
      */
60
-    private function extractMetadata( DOMElement $file ) {
60
+    private function extractMetadata(DOMElement $file) {
61 61
         $metadata   = [];
62 62
         $customAttr = [];
63 63
 
64 64
         /** @var \DOMAttr $attribute */
65
-        foreach ( $file->attributes as $attribute ) {
66
-            switch ( $attribute->localName ) {
65
+        foreach ($file->attributes as $attribute) {
66
+            switch ($attribute->localName) {
67 67
                 // original
68 68
                 case 'original':
69
-                    $metadata[ 'original' ] = $attribute->value;
69
+                    $metadata['original'] = $attribute->value;
70 70
                     break;
71 71
 
72 72
                 // source-language
73 73
                 case 'source-language':
74
-                    $metadata[ 'source-language' ] = $attribute->value;
74
+                    $metadata['source-language'] = $attribute->value;
75 75
                     break;
76 76
 
77 77
                 // data-type
78 78
                 case 'datatype':
79
-                    $metadata[ 'data-type' ] = $attribute->value;
79
+                    $metadata['data-type'] = $attribute->value;
80 80
                     break;
81 81
 
82 82
                 // target-language
83 83
                 case 'target-language':
84
-                    $metadata[ 'target-language' ] = $attribute->value;
84
+                    $metadata['target-language'] = $attribute->value;
85 85
                     break;
86 86
             }
87 87
 
88 88
             // Custom MateCat x-Attribute
89
-            preg_match( '|x-(.*?)|si', $attribute->localName, $temp );
90
-            if ( isset( $temp[ 1 ] ) ) {
91
-                $customAttr[ $attribute->localName ] = $attribute->value;
89
+            preg_match('|x-(.*?)|si', $attribute->localName, $temp);
90
+            if (isset($temp[1])) {
91
+                $customAttr[$attribute->localName] = $attribute->value;
92 92
             }
93
-            unset( $temp );
93
+            unset($temp);
94 94
 
95 95
             // Custom MateCat namespace Attribute mtc:
96
-            preg_match( '|mtc:(.*?)|si', $attribute->nodeName, $temp );
97
-            if ( isset( $temp[ 1 ] ) ) {
98
-                $customAttr[ $attribute->nodeName ] = $attribute->value;
96
+            preg_match('|mtc:(.*?)|si', $attribute->nodeName, $temp);
97
+            if (isset($temp[1])) {
98
+                $customAttr[$attribute->nodeName] = $attribute->value;
99 99
             }
100
-            unset( $temp );
100
+            unset($temp);
101 101
 
102
-            if ( !empty( $customAttr ) ) {
103
-                $metadata[ 'custom' ] = $customAttr;
102
+            if (!empty($customAttr)) {
103
+                $metadata['custom'] = $customAttr;
104 104
             }
105 105
         }
106 106
 
@@ -112,16 +112,16 @@  discard block
 block discarded – undo
112 112
      *
113 113
      * @return array
114 114
      */
115
-    private function extractReference( DOMElement $file ) {
115
+    private function extractReference(DOMElement $file) {
116 116
         $reference = [];
117 117
 
118 118
         $order = 0;
119
-        foreach ( $file->getElementsByTagName( 'reference' ) as $ref ) {
119
+        foreach ($file->getElementsByTagName('reference') as $ref) {
120 120
             /** @var DOMNode $childNode */
121
-            foreach ( $ref->childNodes as $childNode ) {
122
-                if ( $childNode->nodeName === 'internal-file' ) {
123
-                    $reference[ $order ][ 'form-type' ] = $childNode->attributes->getNamedItem( 'form' )->nodeValue;
124
-                    $reference[ $order ][ 'base64' ]    = trim( $childNode->nodeValue );
121
+            foreach ($ref->childNodes as $childNode) {
122
+                if ($childNode->nodeName === 'internal-file') {
123
+                    $reference[$order]['form-type'] = $childNode->attributes->getNamedItem('form')->nodeValue;
124
+                    $reference[$order]['base64']    = trim($childNode->nodeValue);
125 125
                     $order++;
126 126
                 }
127 127
             }
@@ -142,53 +142,53 @@  discard block
 block discarded – undo
142 142
      *
143 143
      * @throws Exception
144 144
      */
145
-    protected function extractTransUnit( $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j ) {
145
+    protected function extractTransUnit($transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j) {
146 146
         // metadata
147
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ] = $this->extractTransUnitMetadata( $transUnit, $transUnitIdArrayForUniquenessCheck );
147
+        $output['files'][$i]['trans-units'][$j]['attr'] = $this->extractTransUnitMetadata($transUnit, $transUnitIdArrayForUniquenessCheck);
148 148
 
149 149
         // notes
150
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'notes' ] = $this->extractTransUnitNotes( $dom, $transUnit );
150
+        $output['files'][$i]['trans-units'][$j]['notes'] = $this->extractTransUnitNotes($dom, $transUnit);
151 151
 
152 152
         // content
153 153
         /** @var DOMElement $childNode */
154
-        foreach ( $transUnit->childNodes as $childNode ) {
154
+        foreach ($transUnit->childNodes as $childNode) {
155 155
             // source
156
-            if ( $childNode->nodeName === 'source' ) {
157
-                $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'source' ] = $this->extractContent( $dom, $childNode );
156
+            if ($childNode->nodeName === 'source') {
157
+                $output['files'][$i]['trans-units'][$j]['source'] = $this->extractContent($dom, $childNode);
158 158
             }
159 159
 
160 160
             // seg-source
161
-            if ( $childNode->nodeName === 'seg-source' ) {
162
-                $rawSegment                                                     = $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'source' ][ 'raw-content' ];
163
-                $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-source' ] = $this->extractContentWithMarksAndExtTags( $dom, $childNode, $rawSegment );
161
+            if ($childNode->nodeName === 'seg-source') {
162
+                $rawSegment                                                     = $output['files'][$i]['trans-units'][$j]['source']['raw-content'];
163
+                $output['files'][$i]['trans-units'][$j]['seg-source'] = $this->extractContentWithMarksAndExtTags($dom, $childNode, $rawSegment);
164 164
             }
165 165
 
166 166
             // target
167
-            if ( $childNode->nodeName === 'target' ) {
168
-                $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'target' ] = $this->extractContent( $dom, $childNode );
167
+            if ($childNode->nodeName === 'target') {
168
+                $output['files'][$i]['trans-units'][$j]['target'] = $this->extractContent($dom, $childNode);
169 169
 
170 170
                 // seg-target
171
-                $targetRawContent = @$output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'target' ][ 'raw-content' ];
172
-                $segSource        = @$output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-source' ];
173
-                if ( isset( $targetRawContent ) && !empty( $targetRawContent ) && isset( $segSource ) && count( $segSource ) > 0 ) {
174
-                    $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-target' ] = $this->extractContentWithMarksAndExtTags( $dom, $childNode, $targetRawContent );
171
+                $targetRawContent = @$output['files'][$i]['trans-units'][$j]['target']['raw-content'];
172
+                $segSource        = @$output['files'][$i]['trans-units'][$j]['seg-source'];
173
+                if (isset($targetRawContent) && !empty($targetRawContent) && isset($segSource) && count($segSource) > 0) {
174
+                    $output['files'][$i]['trans-units'][$j]['seg-target'] = $this->extractContentWithMarksAndExtTags($dom, $childNode, $targetRawContent);
175 175
                 }
176 176
             }
177 177
 
178 178
             // locked
179
-            if ( $childNode->nodeName === 'sdl:seg' ) {
180
-                $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'locked' ] = $this->extractLocked( $childNode );
179
+            if ($childNode->nodeName === 'sdl:seg') {
180
+                $output['files'][$i]['trans-units'][$j]['locked'] = $this->extractLocked($childNode);
181 181
             }
182 182
         }
183 183
 
184 184
         // context-group
185
-        foreach ( $transUnit->getElementsByTagName( 'context-group' ) as $contextGroup ) {
186
-            $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'context-group' ][] = $this->extractTransUnitContextGroup( $dom, $contextGroup );
185
+        foreach ($transUnit->getElementsByTagName('context-group') as $contextGroup) {
186
+            $output['files'][$i]['trans-units'][$j]['context-group'][] = $this->extractTransUnitContextGroup($dom, $contextGroup);
187 187
         }
188 188
 
189 189
         // alt-trans
190
-        foreach ( $transUnit->getElementsByTagName( 'alt-trans' ) as $altTrans ) {
191
-            $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'alt-trans' ][] = $this->extractTransUnitAltTrans( $altTrans );
190
+        foreach ($transUnit->getElementsByTagName('alt-trans') as $altTrans) {
191
+            $output['files'][$i]['trans-units'][$j]['alt-trans'][] = $this->extractTransUnitAltTrans($altTrans);
192 192
         }
193 193
 
194 194
         $j++;
@@ -201,32 +201,32 @@  discard block
 block discarded – undo
201 201
      * @return array
202 202
      * @throws Exception
203 203
      */
204
-    private function extractTransUnitMetadata( DOMElement $transUnit, array &$transUnitIdArrayForUniquenessCheck ) {
204
+    private function extractTransUnitMetadata(DOMElement $transUnit, array &$transUnitIdArrayForUniquenessCheck) {
205 205
         $metadata = [];
206 206
 
207 207
         // id
208
-        if ( null === $transUnit->attributes->getNamedItem( 'id' ) ) {
209
-            throw new NotFoundIdInTransUnit( 'Invalid trans-unit id found. EMPTY value', 400 );
208
+        if (null === $transUnit->attributes->getNamedItem('id')) {
209
+            throw new NotFoundIdInTransUnit('Invalid trans-unit id found. EMPTY value', 400);
210 210
         }
211 211
 
212
-        $id = $transUnit->attributes->getNamedItem( 'id' )->nodeValue;
212
+        $id = $transUnit->attributes->getNamedItem('id')->nodeValue;
213 213
 
214
-        if ( strlen( $id ) > 100 ) {
215
-            throw new SegmentIdTooLongException( 'Segment-id too long. Max 100 characters allowed', 400 );
214
+        if (strlen($id) > 100) {
215
+            throw new SegmentIdTooLongException('Segment-id too long. Max 100 characters allowed', 400);
216 216
         }
217 217
 
218 218
         $transUnitIdArrayForUniquenessCheck[] = $id;
219
-        $metadata[ 'id' ]                     = $id;
219
+        $metadata['id']                     = $id;
220 220
 
221 221
         // translate
222
-        if ( null !== $transUnit->attributes->getNamedItem( 'translate' ) ) {
223
-            $metadata[ 'translate' ] = $transUnit->attributes->getNamedItem( 'translate' )->nodeValue;
222
+        if (null !== $transUnit->attributes->getNamedItem('translate')) {
223
+            $metadata['translate'] = $transUnit->attributes->getNamedItem('translate')->nodeValue;
224 224
         }
225 225
 
226 226
         // approved
227 227
         // http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html#approved
228
-        if ( null !== $transUnit->attributes->getNamedItem( 'approved' ) ) {
229
-            $metadata[ 'approved' ] = filter_var( $transUnit->attributes->getNamedItem( 'approved' )->nodeValue, FILTER_VALIDATE_BOOLEAN );
228
+        if (null !== $transUnit->attributes->getNamedItem('approved')) {
229
+            $metadata['approved'] = filter_var($transUnit->attributes->getNamedItem('approved')->nodeValue, FILTER_VALIDATE_BOOLEAN);
230 230
         }
231 231
 
232 232
         return $metadata;
@@ -238,19 +238,19 @@  discard block
 block discarded – undo
238 238
      * @return array
239 239
      * @throws Exception
240 240
      */
241
-    private function extractTransUnitNotes( DOMDocument $dom, DOMElement $transUnit ) {
241
+    private function extractTransUnitNotes(DOMDocument $dom, DOMElement $transUnit) {
242 242
         $notes = [];
243
-        foreach ( $transUnit->getElementsByTagName( 'note' ) as $note ) {
243
+        foreach ($transUnit->getElementsByTagName('note') as $note) {
244 244
 
245
-            $noteValue = $this->extractTagContent( $dom, $note );
245
+            $noteValue = $this->extractTagContent($dom, $note);
246 246
 
247
-            if ( '' !== $noteValue ) {
247
+            if ('' !== $noteValue) {
248 248
 
249
-                $extractedNote = $this->JSONOrRawContentArray( $noteValue );
249
+                $extractedNote = $this->JSONOrRawContentArray($noteValue);
250 250
 
251 251
                 // extract all the attributes
252
-                foreach ( $note->attributes as $attribute ) {
253
-                    $extractedNote[ $attribute->name ] = $attribute->value;
252
+                foreach ($note->attributes as $attribute) {
253
+                    $extractedNote[$attribute->name] = $attribute->value;
254 254
                 }
255 255
 
256 256
                 $notes[] = $extractedNote;
@@ -265,14 +265,14 @@  discard block
 block discarded – undo
265 265
      *
266 266
      * @return array
267 267
      */
268
-    private function extractTransUnitContextGroup( DOMDocument $dom, DOMElement $contextGroup ) {
268
+    private function extractTransUnitContextGroup(DOMDocument $dom, DOMElement $contextGroup) {
269 269
         $cg           = [];
270
-        $cg[ 'attr' ] = $this->extractTagAttributes( $contextGroup );
270
+        $cg['attr'] = $this->extractTagAttributes($contextGroup);
271 271
 
272 272
         /** @var DOMNode $context */
273
-        foreach ( $contextGroup->childNodes as $context ) {
274
-            if ( $context->nodeName === 'context' ) {
275
-                $cg[ 'contexts' ][] = $this->extractContent( $dom, $context );
273
+        foreach ($contextGroup->childNodes as $context) {
274
+            if ($context->nodeName === 'context') {
275
+                $cg['contexts'][] = $this->extractContent($dom, $context);
276 276
             }
277 277
         }
278 278
 
@@ -284,16 +284,16 @@  discard block
 block discarded – undo
284 284
      *
285 285
      * @return array
286 286
      */
287
-    private function extractTransUnitAltTrans( DOMElement $altTrans ) {
287
+    private function extractTransUnitAltTrans(DOMElement $altTrans) {
288 288
         $at           = [];
289
-        $at[ 'attr' ] = $this->extractTagAttributes( $altTrans );
289
+        $at['attr'] = $this->extractTagAttributes($altTrans);
290 290
 
291
-        if ( $altTrans->getElementsByTagName( 'source' )->length > 0 ) {
292
-            $at[ 'source' ] = $altTrans->getElementsByTagName( 'source' )->item( 0 )->nodeValue;
291
+        if ($altTrans->getElementsByTagName('source')->length > 0) {
292
+            $at['source'] = $altTrans->getElementsByTagName('source')->item(0)->nodeValue;
293 293
         }
294 294
 
295
-        if ( $altTrans->getElementsByTagName( 'target' ) ) {
296
-            $at[ 'target' ] = $altTrans->getElementsByTagName( 'target' )->item( 0 )->nodeValue;
295
+        if ($altTrans->getElementsByTagName('target')) {
296
+            $at['target'] = $altTrans->getElementsByTagName('target')->item(0)->nodeValue;
297 297
         }
298 298
 
299 299
         return $at;
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
      *
305 305
      * @return bool
306 306
      */
307
-    private function extractLocked( DOMElement $locked ) {
308
-        return null !== $locked->getAttribute( 'locked' );
307
+    private function extractLocked(DOMElement $locked) {
308
+        return null !== $locked->getAttribute('locked');
309 309
     }
310 310
 }
Please login to merge, or discard this patch.
src/XliffParser/XliffParserV2.php 1 patch
Spacing   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -16,30 +16,30 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
             }
@@ -113,33 +113,33 @@  discard block
 block discarded – undo
113 113
      *
114 114
      * @throws \Exception
115 115
      */
116
-    protected function extractTransUnit( $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j ) {
116
+    protected function extractTransUnit($transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j) {
117 117
         // metadata
118
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ] = $this->extractTransUnitMetadata( $transUnit, $transUnitIdArrayForUniquenessCheck );
118
+        $output['files'][$i]['trans-units'][$j]['attr'] = $this->extractTransUnitMetadata($transUnit, $transUnitIdArrayForUniquenessCheck);
119 119
 
120 120
         // notes
121 121
         // merge <notes> with key and key-note contained in metadata <mda:metaGroup>
122
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'notes' ] = $this->extractTransUnitNotes( $transUnit );
122
+        $output['files'][$i]['trans-units'][$j]['notes'] = $this->extractTransUnitNotes($transUnit);
123 123
 
124 124
         // uuid
125
-        foreach ( $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'notes' ] as $note ) {
126
-            if ( isset( $note[ 'raw-content' ] ) && Strings::isAValidUuid( $note[ 'raw-content' ] ) ) {
127
-                $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ][ 'uuid' ] = $note[ 'raw-content' ];
125
+        foreach ($output['files'][$i]['trans-units'][$j]['notes'] as $note) {
126
+            if (isset($note['raw-content']) && Strings::isAValidUuid($note['raw-content'])) {
127
+                $output['files'][$i]['trans-units'][$j]['attr']['uuid'] = $note['raw-content'];
128 128
             }
129 129
         }
130 130
 
131 131
         // original-data (exclusive for V2)
132 132
         // http://docs.oasis-open.org/xliff/xliff-core/v2.0/xliff-core-v2.0.html#originaldata
133
-        $originalData = $this->extractTransUnitOriginalData( $transUnit );
134
-        if ( !empty( $originalData ) ) {
135
-            $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'original-data' ] = $originalData;
136
-            $dataRefMap                                                        = $this->getDataRefMap( $originalData );
133
+        $originalData = $this->extractTransUnitOriginalData($transUnit);
134
+        if (!empty($originalData)) {
135
+            $output['files'][$i]['trans-units'][$j]['original-data'] = $originalData;
136
+            $dataRefMap                                                        = $this->getDataRefMap($originalData);
137 137
         }
138 138
 
139 139
         // additionalTagData (exclusive for V2)
140
-        $additionalTagData = $this->extractTransUnitAdditionalTagData( $transUnit );
141
-        if ( !empty( $additionalTagData ) ) {
142
-            $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'additional-tag-data' ] = $additionalTagData;
140
+        $additionalTagData = $this->extractTransUnitAdditionalTagData($transUnit);
141
+        if (!empty($additionalTagData)) {
142
+            $output['files'][$i]['trans-units'][$j]['additional-tag-data'] = $additionalTagData;
143 143
         }
144 144
 
145 145
         // content
@@ -159,62 +159,62 @@  discard block
 block discarded – undo
159 159
 
160 160
         /** @var DOMElement $segment */
161 161
         $c = 0;
162
-        foreach ( $transUnit->childNodes as $segment ) {
163
-            if ( $segment->nodeName === 'segment' ) {
162
+        foreach ($transUnit->childNodes as $segment) {
163
+            if ($segment->nodeName === 'segment') {
164 164
 
165 165
                 // check segment id consistency
166
-                $attr = $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ];
167
-                $this->checkSegmentIdConsistency( $segment, $attr );
166
+                $attr = $output['files'][$i]['trans-units'][$j]['attr'];
167
+                $this->checkSegmentIdConsistency($segment, $attr);
168 168
 
169 169
                 // loop <segment> to get nested <source> and <target> tag
170
-                foreach ( $segment->childNodes as $childNode ) {
171
-                    if ( $childNode->nodeName === 'source' ) {
172
-                        $extractedSource               = $this->extractContent( $dom, $childNode );
173
-                        $source[ 'raw-content' ][ $c ] = $extractedSource[ 'raw-content' ];
170
+                foreach ($segment->childNodes as $childNode) {
171
+                    if ($childNode->nodeName === 'source') {
172
+                        $extractedSource               = $this->extractContent($dom, $childNode);
173
+                        $source['raw-content'][$c] = $extractedSource['raw-content'];
174 174
 
175
-                        if ( !empty( $originalData ) ) {
176
-                            $source[ 'replaced-content' ][ $c ] = ( new DataRefReplacer( $dataRefMap ) )->replace( $source[ 'raw-content' ][ $c ] );
175
+                        if (!empty($originalData)) {
176
+                            $source['replaced-content'][$c] = (new DataRefReplacer($dataRefMap))->replace($source['raw-content'][$c]);
177 177
                         }
178 178
 
179
-                        if ( !empty( $extractedSource[ 'attr' ] ) ) {
180
-                            $source[ 'attr' ][ $c ] = $extractedSource[ 'attr' ];
179
+                        if (!empty($extractedSource['attr'])) {
180
+                            $source['attr'][$c] = $extractedSource['attr'];
181 181
                         }
182 182
 
183 183
                         // append value to 'seg-source'
184
-                        if ( $this->stringContainsMarks( $extractedSource[ 'raw-content' ] ) ) {
185
-                            $segSource = $this->extractContentWithMarksAndExtTags( $dom, $childNode, $extractedSource[ 'raw-content' ], $originalData );
184
+                        if ($this->stringContainsMarks($extractedSource['raw-content'])) {
185
+                            $segSource = $this->extractContentWithMarksAndExtTags($dom, $childNode, $extractedSource['raw-content'], $originalData);
186 186
                         } else {
187 187
                             $segSource[] = [
188
-                                    'mid'              => count( $segSource ) > 0 ? count( $segSource ) : 0,
188
+                                    'mid'              => count($segSource) > 0 ? count($segSource) : 0,
189 189
                                     'ext-prec-tags'    => '',
190
-                                    'raw-content'      => $extractedSource[ 'raw-content' ],
191
-                                    'replaced-content' => ( !empty( $originalData ) ) ? ( new DataRefReplacer( $dataRefMap ) )->replace( $extractedSource[ 'raw-content' ] ) : null,
190
+                                    'raw-content'      => $extractedSource['raw-content'],
191
+                                    'replaced-content' => (!empty($originalData)) ? (new DataRefReplacer($dataRefMap))->replace($extractedSource['raw-content']) : null,
192 192
                                     'ext-succ-tags'    => '',
193 193
                             ];
194 194
                         }
195 195
                     }
196 196
 
197
-                    if ( $childNode->nodeName === 'target' ) {
198
-                        $extractedTarget               = $this->extractContent( $dom, $childNode );
199
-                        $target[ 'raw-content' ][ $c ] = $extractedTarget[ 'raw-content' ];
197
+                    if ($childNode->nodeName === 'target') {
198
+                        $extractedTarget               = $this->extractContent($dom, $childNode);
199
+                        $target['raw-content'][$c] = $extractedTarget['raw-content'];
200 200
 
201
-                        if ( !empty( $originalData ) ) {
202
-                            $target[ 'replaced-content' ][ $c ] = ( new DataRefReplacer( $dataRefMap ) )->replace( $target[ 'raw-content' ][ $c ] );
201
+                        if (!empty($originalData)) {
202
+                            $target['replaced-content'][$c] = (new DataRefReplacer($dataRefMap))->replace($target['raw-content'][$c]);
203 203
                         }
204 204
 
205
-                        if ( !empty( $extractedTarget[ 'attr' ] ) ) {
206
-                            $target[ 'attr' ][ $c ] = $extractedTarget[ 'attr' ];
205
+                        if (!empty($extractedTarget['attr'])) {
206
+                            $target['attr'][$c] = $extractedTarget['attr'];
207 207
                         }
208 208
 
209 209
                         // append value to 'seg-target'
210
-                        if ( $this->stringContainsMarks( $extractedTarget[ 'raw-content' ] ) ) {
211
-                            $segTarget = $this->extractContentWithMarksAndExtTags( $dom, $childNode, $extractedTarget[ 'raw-content' ], $originalData );
210
+                        if ($this->stringContainsMarks($extractedTarget['raw-content'])) {
211
+                            $segTarget = $this->extractContentWithMarksAndExtTags($dom, $childNode, $extractedTarget['raw-content'], $originalData);
212 212
                         } else {
213 213
                             $segTarget[] = [
214
-                                    'mid'              => count( $segTarget ) > 0 ? count( $segTarget ) : 0,
214
+                                    'mid'              => count($segTarget) > 0 ? count($segTarget) : 0,
215 215
                                     'ext-prec-tags'    => '',
216
-                                    'raw-content'      => $extractedTarget[ 'raw-content' ],
217
-                                    'replaced-content' => ( !empty( $originalData ) ) ? ( new DataRefReplacer( $dataRefMap ) )->replace( $extractedTarget[ 'raw-content' ] ) : null,
216
+                                    'raw-content'      => $extractedTarget['raw-content'],
217
+                                    'replaced-content' => (!empty($originalData)) ? (new DataRefReplacer($dataRefMap))->replace($extractedTarget['raw-content']) : null,
218 218
                                     'ext-succ-tags'    => '',
219 219
                             ];
220 220
                         }
@@ -225,10 +225,10 @@  discard block
 block discarded – undo
225 225
             }
226 226
         }
227 227
 
228
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'source' ]     = $source;
229
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'target' ]     = $target;
230
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-source' ] = $segSource;
231
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-target' ] = $segTarget;
228
+        $output['files'][$i]['trans-units'][$j]['source']     = $source;
229
+        $output['files'][$i]['trans-units'][$j]['target']     = $target;
230
+        $output['files'][$i]['trans-units'][$j]['seg-source'] = $segSource;
231
+        $output['files'][$i]['trans-units'][$j]['seg-target'] = $segTarget;
232 232
 
233 233
         $j++;
234 234
     }
@@ -239,41 +239,41 @@  discard block
 block discarded – undo
239 239
      *
240 240
      * @return array
241 241
      */
242
-    private function extractTransUnitMetadata( DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck ) {
242
+    private function extractTransUnitMetadata(DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck) {
243 243
         $metadata = [];
244 244
 
245 245
         // id
246
-        if ( null === $transUnit->attributes->getNamedItem( 'id' ) ) {
247
-            throw new NotFoundIdInTransUnit( 'Invalid trans-unit id found. EMPTY value', 400 );
246
+        if (null === $transUnit->attributes->getNamedItem('id')) {
247
+            throw new NotFoundIdInTransUnit('Invalid trans-unit id found. EMPTY value', 400);
248 248
         }
249 249
 
250
-        $id = $transUnit->attributes->getNamedItem( 'id' )->nodeValue;
250
+        $id = $transUnit->attributes->getNamedItem('id')->nodeValue;
251 251
 
252
-        if ( strlen( $id ) > 100 ) {
253
-            throw new SegmentIdTooLongException( 'Segment-id too long. Max 100 characters allowed', 400 );
252
+        if (strlen($id) > 100) {
253
+            throw new SegmentIdTooLongException('Segment-id too long. Max 100 characters allowed', 400);
254 254
         }
255 255
 
256 256
         $transUnitIdArrayForUniquenessCheck[] = $id;
257
-        $metadata[ 'id' ]                     = $id;
257
+        $metadata['id']                     = $id;
258 258
 
259 259
         // translate
260
-        if ( null !== $transUnit->attributes->getNamedItem( 'translate' ) ) {
261
-            $metadata[ 'translate' ] = $transUnit->attributes->getNamedItem( 'translate' )->nodeValue;
260
+        if (null !== $transUnit->attributes->getNamedItem('translate')) {
261
+            $metadata['translate'] = $transUnit->attributes->getNamedItem('translate')->nodeValue;
262 262
         }
263 263
 
264 264
         // tGroupBegin
265
-        if ( null !== $transUnit->attributes->getNamedItem( 'tGroupBegin' ) ) {
266
-            $metadata[ 'tGroupBegin' ] = $transUnit->attributes->getNamedItem( 'tGroupBegin' )->nodeValue;
265
+        if (null !== $transUnit->attributes->getNamedItem('tGroupBegin')) {
266
+            $metadata['tGroupBegin'] = $transUnit->attributes->getNamedItem('tGroupBegin')->nodeValue;
267 267
         }
268 268
 
269 269
         // tGroupEnd
270
-        if ( null !== $transUnit->attributes->getNamedItem( 'tGroupEnd' ) ) {
271
-            $metadata[ 'tGroupEnd' ] = $transUnit->attributes->getNamedItem( 'tGroupEnd' )->nodeValue;
270
+        if (null !== $transUnit->attributes->getNamedItem('tGroupEnd')) {
271
+            $metadata['tGroupEnd'] = $transUnit->attributes->getNamedItem('tGroupEnd')->nodeValue;
272 272
         }
273 273
 
274 274
         // sizeRestriction
275
-        if ( null !== $transUnit->attributes->getNamedItem( 'sizeRestriction' ) && '' !== $transUnit->attributes->getNamedItem( 'sizeRestriction' )->nodeValue ) {
276
-            $metadata[ 'sizeRestriction' ] = (int)$transUnit->attributes->getNamedItem( 'sizeRestriction' )->nodeValue;
275
+        if (null !== $transUnit->attributes->getNamedItem('sizeRestriction') && '' !== $transUnit->attributes->getNamedItem('sizeRestriction')->nodeValue) {
276
+            $metadata['sizeRestriction'] = (int)$transUnit->attributes->getNamedItem('sizeRestriction')->nodeValue;
277 277
         }
278 278
 
279 279
         return $metadata;
@@ -285,31 +285,31 @@  discard block
 block discarded – undo
285 285
      * @return array
286 286
      * @throws \Exception
287 287
      */
288
-    private function extractTransUnitOriginalData( DOMElement $transUnit ) {
288
+    private function extractTransUnitOriginalData(DOMElement $transUnit) {
289 289
         $originalData = [];
290 290
 
291 291
         // loop <originalData> to get nested content
292
-        foreach ( $transUnit->childNodes as $childNode ) {
293
-            if ( $childNode->nodeName === 'originalData' ) {
294
-                foreach ( $childNode->childNodes as $data ) {
295
-                    if ( null !== $data->attributes && null !== $data->attributes->getNamedItem( 'id' ) ) {
296
-                        $dataId = $data->attributes->getNamedItem( 'id' )->nodeValue;
292
+        foreach ($transUnit->childNodes as $childNode) {
293
+            if ($childNode->nodeName === 'originalData') {
294
+                foreach ($childNode->childNodes as $data) {
295
+                    if (null !== $data->attributes && null !== $data->attributes->getNamedItem('id')) {
296
+                        $dataId = $data->attributes->getNamedItem('id')->nodeValue;
297 297
 
298
-                        $dataValue = str_replace( Placeholder::WHITE_SPACE_PLACEHOLDER, ' ', $data->nodeValue );
299
-                        $dataValue = str_replace( Placeholder::NEW_LINE_PLACEHOLDER, '\n', $dataValue );
300
-                        $dataValue = str_replace( Placeholder::TAB_PLACEHOLDER, '\t', $dataValue );
298
+                        $dataValue = str_replace(Placeholder::WHITE_SPACE_PLACEHOLDER, ' ', $data->nodeValue);
299
+                        $dataValue = str_replace(Placeholder::NEW_LINE_PLACEHOLDER, '\n', $dataValue);
300
+                        $dataValue = str_replace(Placeholder::TAB_PLACEHOLDER, '\t', $dataValue);
301 301
 
302
-                        if ( '' !== $dataValue ) {
302
+                        if ('' !== $dataValue) {
303 303
 
304
-                            $jsonOrRawContentArray = $this->JSONOrRawContentArray( $dataValue, false );
304
+                            $jsonOrRawContentArray = $this->JSONOrRawContentArray($dataValue, false);
305 305
 
306 306
                             // restore xliff tags
307
-                            if ( isset( $jsonOrRawContentArray[ 'json' ] ) ) {
308
-                                $jsonOrRawContentArray[ 'json' ] = str_replace( [ Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER ], [ '&lt;', '&gt;' ], $jsonOrRawContentArray[ 'json' ] );
307
+                            if (isset($jsonOrRawContentArray['json'])) {
308
+                                $jsonOrRawContentArray['json'] = str_replace([Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER], ['&lt;', '&gt;'], $jsonOrRawContentArray['json']);
309 309
                             }
310 310
 
311
-                            if ( isset( $jsonOrRawContentArray[ 'raw-content' ] ) ) {
312
-                                $jsonOrRawContentArray[ 'raw-content' ] = str_replace( [ Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER ], [ '&lt;', '&gt;' ], $jsonOrRawContentArray[ 'raw-content' ] );
311
+                            if (isset($jsonOrRawContentArray['raw-content'])) {
312
+                                $jsonOrRawContentArray['raw-content'] = str_replace([Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER], ['&lt;', '&gt;'], $jsonOrRawContentArray['raw-content']);
313 313
                             }
314 314
 
315 315
                             $originalData[] = array_merge(
@@ -334,41 +334,41 @@  discard block
 block discarded – undo
334 334
      *
335 335
      * @return array
336 336
      */
337
-    private function extractTransUnitAdditionalTagData( DOMElement $transUnit ) {
337
+    private function extractTransUnitAdditionalTagData(DOMElement $transUnit) {
338 338
         $additionalTagData = [];
339 339
 
340 340
         // loop <originalData> to get nested content
341
-        foreach ( $transUnit->childNodes as $childNode ) {
342
-            if ( $childNode->nodeName === 'memsource:additionalTagData' ) {
343
-                foreach ( $childNode->childNodes as $data ) {
341
+        foreach ($transUnit->childNodes as $childNode) {
342
+            if ($childNode->nodeName === 'memsource:additionalTagData') {
343
+                foreach ($childNode->childNodes as $data) {
344 344
                     $dataArray = [];
345 345
 
346 346
                     // id
347
-                    if ( $data->nodeName === 'memsource:tag' ) {
348
-                        if ( null !== $data->attributes && null !== $data->attributes->getNamedItem( 'id' ) ) {
349
-                            $dataId                      = $data->attributes->getNamedItem( 'id' )->nodeValue;
350
-                            $dataArray[ 'attr' ][ 'id' ] = $dataId;
347
+                    if ($data->nodeName === 'memsource:tag') {
348
+                        if (null !== $data->attributes && null !== $data->attributes->getNamedItem('id')) {
349
+                            $dataId                      = $data->attributes->getNamedItem('id')->nodeValue;
350
+                            $dataArray['attr']['id'] = $dataId;
351 351
                         }
352 352
                     }
353 353
 
354 354
                     // in PHP 7.4 $data->childNodes is an empty DomNodeList, it is iterable with size 0
355 355
                     // PHP 5.6 check: in php 5.6 $data->childNodes can be null
356
-                    if ( $data->childNodes != null ) {
356
+                    if ($data->childNodes != null) {
357 357
 
358 358
                         // content
359
-                        foreach ( $data->childNodes as $datum ) {
360
-                            if ( $datum->nodeName === 'memsource:tagId' ) {
361
-                                $dataArray[ 'raw-content' ][ 'tagId' ] = $datum->nodeValue;
359
+                        foreach ($data->childNodes as $datum) {
360
+                            if ($datum->nodeName === 'memsource:tagId') {
361
+                                $dataArray['raw-content']['tagId'] = $datum->nodeValue;
362 362
                             }
363 363
 
364
-                            if ( $datum->nodeName === 'memsource:type' ) {
365
-                                $dataArray[ 'raw-content' ][ 'type' ] = $datum->nodeValue;
364
+                            if ($datum->nodeName === 'memsource:type') {
365
+                                $dataArray['raw-content']['type'] = $datum->nodeValue;
366 366
                             }
367 367
                         }
368 368
 
369 369
                     }
370 370
 
371
-                    if ( !empty( $dataArray ) ) {
371
+                    if (!empty($dataArray)) {
372 372
                         $additionalTagData[] = $dataArray;
373 373
                     }
374 374
                 }
@@ -384,15 +384,15 @@  discard block
 block discarded – undo
384 384
      * @param DOMElement $segment
385 385
      * @param array      $attr
386 386
      */
387
-    private function checkSegmentIdConsistency( DOMElement $segment, array $attr ) {
388
-        if ( isset( $attr[ 'tGroupBegin' ] ) && isset( $attr[ 'tGroupEnd' ] ) && $segment->attributes->getNamedItem( 'id' ) ) {
389
-            $id  = $segment->attributes->getNamedItem( 'id' )->nodeValue;
390
-            $min = (int)$attr[ 'tGroupBegin' ];
391
-            $max = (int)$attr[ 'tGroupEnd' ];
392
-
393
-            if ( false === ( ( $min <= $id ) && ( $id <= $max ) ) ) {
394
-                if ( $this->logger ) {
395
-                    $this->logger->warning( 'Segment #' . $id . ' is not included within tGroupBegin and tGroupEnd' );
387
+    private function checkSegmentIdConsistency(DOMElement $segment, array $attr) {
388
+        if (isset($attr['tGroupBegin']) && isset($attr['tGroupEnd']) && $segment->attributes->getNamedItem('id')) {
389
+            $id  = $segment->attributes->getNamedItem('id')->nodeValue;
390
+            $min = (int)$attr['tGroupBegin'];
391
+            $max = (int)$attr['tGroupEnd'];
392
+
393
+            if (false === (($min <= $id) && ($id <= $max))) {
394
+                if ($this->logger) {
395
+                    $this->logger->warning('Segment #' . $id . ' is not included within tGroupBegin and tGroupEnd');
396 396
                 }
397 397
             }
398 398
         }
@@ -404,31 +404,31 @@  discard block
 block discarded – undo
404 404
      * @return array
405 405
      * @throws \Exception
406 406
      */
407
-    private function extractTransUnitNotes( DOMElement $transUnit ) {
407
+    private function extractTransUnitNotes(DOMElement $transUnit) {
408 408
         $notes = [];
409 409
 
410 410
         // loop <notes> to get nested <note> tag
411
-        foreach ( $transUnit->childNodes as $childNode ) {
412
-            if ( $childNode->nodeName == 'notes' ) {
413
-                foreach ( $childNode->childNodes as $note ) {
414
-                    $noteValue = trim( $note->nodeValue );
415
-                    if ( '' !== $noteValue ) {
416
-                        $notes[] = $this->JSONOrRawContentArray( $noteValue );
411
+        foreach ($transUnit->childNodes as $childNode) {
412
+            if ($childNode->nodeName == 'notes') {
413
+                foreach ($childNode->childNodes as $note) {
414
+                    $noteValue = trim($note->nodeValue);
415
+                    if ('' !== $noteValue) {
416
+                        $notes[] = $this->JSONOrRawContentArray($noteValue);
417 417
                     }
418 418
                 }
419 419
             }
420 420
 
421
-            if ( $childNode->nodeName === 'mda:metadata' ) {
422
-                foreach ( $childNode->childNodes as $metadata ) {
423
-                    if ( $metadata->nodeName === 'mda:metaGroup' ) {
424
-                        foreach ( $metadata->childNodes as $meta ) {
425
-                            if ( null !== $meta->attributes && null !== $meta->attributes->getNamedItem( 'type' ) ) {
426
-                                $type      = $meta->attributes->getNamedItem( 'type' )->nodeValue;
427
-                                $metaValue = trim( $meta->nodeValue );
421
+            if ($childNode->nodeName === 'mda:metadata') {
422
+                foreach ($childNode->childNodes as $metadata) {
423
+                    if ($metadata->nodeName === 'mda:metaGroup') {
424
+                        foreach ($metadata->childNodes as $meta) {
425
+                            if (null !== $meta->attributes && null !== $meta->attributes->getNamedItem('type')) {
426
+                                $type      = $meta->attributes->getNamedItem('type')->nodeValue;
427
+                                $metaValue = trim($meta->nodeValue);
428 428
 
429
-                                if ( '' !== $metaValue ) {
429
+                                if ('' !== $metaValue) {
430 430
                                     $notes[] = array_merge(
431
-                                            $this->JSONOrRawContentArray( $metaValue ),
431
+                                            $this->JSONOrRawContentArray($metaValue),
432 432
                                             [
433 433
                                                     'attr' => [
434 434
                                                             'type' => $type
Please login to merge, or discard this patch.
src/Utils/HtmlParser.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -55,11 +55,11 @@  discard block
 block discarded – undo
55 55
 
56 56
         foreach ($matches[0] as $key => $match) {
57 57
 
58
-            $current = $matches[ 0 ][ $key ][ 0 ];
58
+            $current = $matches[0][$key][0];
59 59
 
60
-            if(isset($matches[0][$key+1][0])){
61
-                $next = $matches[0][$key+1][0];
62
-                $nextOffset = $matches[0][$key+1][1];
60
+            if (isset($matches[0][$key + 1][0])) {
61
+                $next = $matches[0][$key + 1][0];
62
+                $nextOffset = $matches[0][$key + 1][1];
63 63
                 $realNextOffset = ($delta === 0) ? $nextOffset : ($nextOffset + $delta);
64 64
             }
65 65
 
@@ -67,13 +67,13 @@  discard block
 block discarded – undo
67 67
             $offset = $matches[0][$key][1];
68 68
             $realOffset = ($delta === 0) ? $offset : ($offset + $delta);
69 69
 
70
-            if( $current === '<' && isset($next)){
70
+            if ($current === '<' && isset($next)) {
71 71
 
72 72
                 // 1. if next is > or
73 73
                 // 2. next is < and is not html tag (like < >)
74
-                $insideAngularTags = substr($html, $realOffset, ($realNextOffset-$realOffset+1));
74
+                $insideAngularTags = substr($html, $realOffset, ($realNextOffset - $realOffset + 1));
75 75
 
76
-                if($next !== '>' || !Strings::isHtmlString($insideAngularTags) ){
76
+                if ($next !== '>' || !Strings::isHtmlString($insideAngularTags)) {
77 77
                     $html = substr_replace($html, self::LT_PLACEHOLDER, $realOffset, $length);
78 78
                     $delta = $delta + strlen(self::LT_PLACEHOLDER) - $length;
79 79
                 }
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
      *
99 99
      * @return string
100 100
      */
101
-    private static function protectNotClosedHtmlTags( $html)
101
+    private static function protectNotClosedHtmlTags($html)
102 102
     {
103 103
         preg_match_all('/<|>/iu', $html, $matches, PREG_OFFSET_CAPTURE);
104 104
 
@@ -108,17 +108,17 @@  discard block
 block discarded – undo
108 108
 
109 109
         // 1. Map all tags
110 110
         foreach ($matches[0] as $key => $match) {
111
-            $current       = $matches[ 0 ][ $key ][ 0 ];
112
-            $currentOffset = $matches[ 0 ][ $key ][ 1 ];
111
+            $current       = $matches[0][$key][0];
112
+            $currentOffset = $matches[0][$key][1];
113 113
 
114 114
             // check every string inside angular brackets (< and >)
115
-            if( $current === '<' && isset($matches[0][$key+1][0]) && $matches[0][$key+1][0] === '>' ){
116
-                $nextOffset = $matches[0][$key+1][1];
117
-                $tag = substr($html, ($currentOffset + 1), ( $nextOffset - $currentOffset - 1 ));
115
+            if ($current === '<' && isset($matches[0][$key + 1][0]) && $matches[0][$key + 1][0] === '>') {
116
+                $nextOffset = $matches[0][$key + 1][1];
117
+                $tag = substr($html, ($currentOffset + 1), ($nextOffset - $currentOffset - 1));
118 118
                 $trimmedTag = trim($tag);
119 119
 
120 120
                 // if the tag is self closed do nothing
121
-                if(Strings::lastChar($tag) !== '/'){
121
+                if (Strings::lastChar($tag) !== '/') {
122 122
                     $tags[] = $trimmedTag;
123 123
                     $offsets[] = $currentOffset;
124 124
                     $originalLengths[] = strlen($tag) + 2; // add 2 to length because there are < and >
@@ -129,18 +129,18 @@  discard block
 block discarded – undo
129 129
         // 2. Removing closed tags
130 130
         $indexes = [];
131 131
 
132
-        if(count($tags) > 0){
133
-            foreach ($tags as $index => $tag){
132
+        if (count($tags) > 0) {
133
+            foreach ($tags as $index => $tag) {
134 134
 
135
-                if(Strings::contains('/', $tag)){
135
+                if (Strings::contains('/', $tag)) {
136 136
                     $complementaryTag = $tag;
137 137
                 } else {
138
-                    $complementaryTag = '/'.explode(' ', $tag)[0];
138
+                    $complementaryTag = '/' . explode(' ', $tag)[0];
139 139
                 }
140 140
 
141 141
                 $complementaryTagIndex = array_search($complementaryTag, $tags);
142 142
 
143
-                if(false !== $complementaryTagIndex){
143
+                if (false !== $complementaryTagIndex) {
144 144
                     $indexes[] = $index;
145 145
                     $indexes[] = $complementaryTagIndex;
146 146
                 }
@@ -148,15 +148,15 @@  discard block
 block discarded – undo
148 148
         }
149 149
 
150 150
         $indexes = array_unique($indexes);
151
-        foreach ($indexes as $index){
151
+        foreach ($indexes as $index) {
152 152
             unset($tags[$index]);
153 153
         }
154 154
 
155 155
         // 3. Loop not closed tags
156 156
         $delta = 0;
157 157
 
158
-        if(count($tags)){
159
-            foreach ($tags as $index => $tag){
158
+        if (count($tags)) {
159
+            foreach ($tags as $index => $tag) {
160 160
 
161 161
                 $length = $originalLengths[$index];
162 162
                 $offset = $offsets[$index];
@@ -178,9 +178,9 @@  discard block
 block discarded – undo
178 178
      *
179 179
      * @return array
180 180
      */
181
-    private static function extractHtmlNode( $html, $toBeEscaped = false)
181
+    private static function extractHtmlNode($html, $toBeEscaped = false)
182 182
     {
183
-        $pattern = "/<([a-zA-Z0-9._-]+)([^>]|[^<]*?)(([\s]*\/>)|".
183
+        $pattern = "/<([a-zA-Z0-9._-]+)([^>]|[^<]*?)(([\s]*\/>)|" .
184 184
                 "(>((([^<]*?|<\!\-\-.*?\-\->)|(?R))*)<\/\\1[\s]*>))/sm";
185 185
         preg_match_all($pattern, $html, $matches, PREG_OFFSET_CAPTURE);
186 186
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
         foreach ($matches[0] as $key => $match) {
190 190
 
191 191
             $attributes = isset($matches[2][$key][0]) ? self::getAttributes($matches[2][$key][0]) : [];
192
-            $base64Decoded = (isset($attributes['equiv-text'])) ? base64_decode(str_replace("base64:", "", $attributes['equiv-text'])): null;
192
+            $base64Decoded = (isset($attributes['equiv-text'])) ? base64_decode(str_replace("base64:", "", $attributes['equiv-text'])) : null;
193 193
             $tagName = $matches[1][$key][0];
194 194
             $text = (isset($matches[6][$key][0]) && '' !== $matches[6][$key][0]) ? $matches[6][$key][0] : null;
195 195
             $originalText = $text;
@@ -239,9 +239,9 @@  discard block
 block discarded – undo
239 239
      *
240 240
      * @return string|string[]
241 241
      */
242
-    private static function restoreLessThanAndGreaterThanSymbols( $text)
242
+    private static function restoreLessThanAndGreaterThanSymbols($text)
243 243
     {
244
-        return str_replace([self::LT_PLACEHOLDER, self::GT_PLACEHOLDER], ['<','>'], $text);
244
+        return str_replace([self::LT_PLACEHOLDER, self::GT_PLACEHOLDER], ['<', '>'], $text);
245 245
     }
246 246
 
247 247
     /**
@@ -256,13 +256,13 @@  discard block
 block discarded – undo
256 256
     {
257 257
         $node = '';
258 258
 
259
-        if($start !== null){
259
+        if ($start !== null) {
260 260
             $node .= ($toBeEscaped) ? Strings::escapeOnlyHTMLTags($start) : $start;
261 261
         }
262 262
 
263 263
         $node .= ($toBeEscaped) ? Strings::escapeOnlyHTMLTags($originalText) : $originalText;
264 264
 
265
-        if($end !== null){
265
+        if ($end !== null) {
266 266
             $node .= ($toBeEscaped) ? Strings::escapeOnlyHTMLTags($end) : $end;
267 267
         }
268 268
 
Please login to merge, or discard this patch.
src/Utils/Strings.php 1 patch
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
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
     }
@@ -29,21 +29,21 @@  discard block
 block discarded – undo
29 29
      * @return bool
30 30
      * @throws Exception
31 31
      */
32
-    public static function isJSON( $string ) {
33
-        if ( is_numeric( $string ) ) {
32
+    public static function isJSON($string) {
33
+        if (is_numeric($string)) {
34 34
             return false;
35 35
         }
36 36
 
37 37
         try {
38
-            $string = Strings::cleanCDATA( $string );
38
+            $string = Strings::cleanCDATA($string);
39 39
 
40
-            if ( empty( $string ) ) {
40
+            if (empty($string)) {
41 41
                 throw new Exception();
42 42
             }
43 43
 
44
-            json_decode( $string );
44
+            json_decode($string);
45 45
             self::raiseJsonExceptionError();
46
-        } catch ( Exception $exception ) {
46
+        } catch (Exception $exception) {
47 47
             return false;
48 48
         }
49 49
 
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
      *
56 56
      * @return array
57 57
      */
58
-    public static function jsonToArray( $string ) {
59
-        return ( is_array( json_decode( $string, true ) ) ) ? json_decode( $string, true ) : [];
58
+    public static function jsonToArray($string) {
59
+        return (is_array(json_decode($string, true))) ? json_decode($string, true) : [];
60 60
     }
61 61
 
62 62
     /**
@@ -65,11 +65,11 @@  discard block
 block discarded – undo
65 65
      * @return string|null
66 66
      * @throws NotValidJSONException
67 67
      */
68
-    private static function raiseJsonExceptionError( $raise = true ) {
69
-        if ( function_exists( "json_last_error" ) ) {
68
+    private static function raiseJsonExceptionError($raise = true) {
69
+        if (function_exists("json_last_error")) {
70 70
             $error = json_last_error();
71 71
 
72
-            switch ( $error ) {
72
+            switch ($error) {
73 73
                 case JSON_ERROR_NONE:
74 74
                     $msg = null; # - No errors
75 75
                     break;
@@ -93,9 +93,9 @@  discard block
 block discarded – undo
93 93
                     break;
94 94
             }
95 95
 
96
-            if ( $raise && $error != JSON_ERROR_NONE ) {
97
-                throw new NotValidJSONException( $msg, $error );
98
-            } elseif ( $error != JSON_ERROR_NONE ) {
96
+            if ($raise && $error != JSON_ERROR_NONE) {
97
+                throw new NotValidJSONException($msg, $error);
98
+            } elseif ($error != JSON_ERROR_NONE) {
99 99
                 return $msg;
100 100
             }
101 101
         }
@@ -120,11 +120,11 @@  discard block
 block discarded – undo
120 120
      *
121 121
      * @return string
122 122
      */
123
-    public static function fixNonWellFormedXml( $content, $escapeStrings = true ) {
124
-        if ( self::$find_xliff_tags_reg === null ) {
123
+    public static function fixNonWellFormedXml($content, $escapeStrings = true) {
124
+        if (self::$find_xliff_tags_reg === null) {
125 125
             // Convert the list of tags in a regexp list, for example "g|x|bx|ex"
126 126
             $xliffTags           = XliffTags::$tags;
127
-            $xliff_tags_reg_list = implode( '|', $xliffTags );
127
+            $xliff_tags_reg_list = implode('|', $xliffTags);
128 128
             // Regexp to find all the XLIFF tags:
129 129
             //   </?               -> matches the tag start, for both opening and
130 130
             //                        closure tags (see the optional slash)
@@ -145,30 +145,30 @@  discard block
 block discarded – undo
145 145
         }
146 146
 
147 147
         // Find all the XLIFF tags
148
-        preg_match_all( self::$find_xliff_tags_reg, $content, $matches );
149
-        $tags = (array)$matches[ 0 ];
148
+        preg_match_all(self::$find_xliff_tags_reg, $content, $matches);
149
+        $tags = (array)$matches[0];
150 150
 
151 151
         // Prepare placeholders
152 152
         $tags_placeholders = [];
153
-        $tagsNum           = count( $tags );
154
-        for ( $i = 0; $i < $tagsNum; $i++ ) {
155
-            $tag                       = $tags[ $i ];
156
-            $tags_placeholders[ $tag ] = "#@!XLIFF-TAG-$i!@#";
153
+        $tagsNum           = count($tags);
154
+        for ($i = 0; $i < $tagsNum; $i++) {
155
+            $tag                       = $tags[$i];
156
+            $tags_placeholders[$tag] = "#@!XLIFF-TAG-$i!@#";
157 157
         }
158 158
 
159 159
         // Replace all XLIFF tags with placeholders that will not be escaped
160
-        foreach ( $tags_placeholders as $tag => $placeholder ) {
161
-            $content = str_replace( $tag, $placeholder, $content );
160
+        foreach ($tags_placeholders as $tag => $placeholder) {
161
+            $content = str_replace($tag, $placeholder, $content);
162 162
         }
163 163
 
164 164
         // Escape the string with the remaining non-XLIFF tags
165
-        if ( $escapeStrings ) {
166
-            $content = htmlspecialchars( $content, ENT_NOQUOTES, 'UTF-8', false );
165
+        if ($escapeStrings) {
166
+            $content = htmlspecialchars($content, ENT_NOQUOTES, 'UTF-8', false);
167 167
         }
168 168
 
169 169
         // Put again in place the original XLIFF tags replacing placeholders
170
-        foreach ( $tags_placeholders as $tag => $placeholder ) {
171
-            $content = str_replace( $placeholder, $tag, $content );
170
+        foreach ($tags_placeholders as $tag => $placeholder) {
171
+            $content = str_replace($placeholder, $tag, $content);
172 172
         }
173 173
 
174 174
         return $content;
@@ -179,17 +179,17 @@  discard block
 block discarded – undo
179 179
      *
180 180
      * @return string
181 181
      */
182
-    public static function removeDangerousChars( $string ) {
182
+    public static function removeDangerousChars($string) {
183 183
         // clean invalid xml entities ( characters with ascii < 32 and different from 0A, 0D and 09
184 184
         $regexpEntity = '/&#x(0[0-8BCEF]|1[0-9A-F]|7F);/u';
185 185
 
186 186
         // remove binary chars in some xliff files
187 187
         $regexpAscii = '/[\x{00}-\x{08}\x{0B}\x{0C}\x{0E}-\x{1F}\x{7F}]/u';
188 188
 
189
-        $string = preg_replace( $regexpAscii, '', $string );
190
-        $string = preg_replace( $regexpEntity, '', $string );
189
+        $string = preg_replace($regexpAscii, '', $string);
190
+        $string = preg_replace($regexpEntity, '', $string);
191 191
 
192
-        return !empty( $string ) ? $string : "";
192
+        return !empty($string) ? $string : "";
193 193
     }
194 194
 
195 195
     /**
@@ -198,8 +198,8 @@  discard block
 block discarded – undo
198 198
      *
199 199
      * @return bool
200 200
      */
201
-    public static function contains( $needle, $haystack ) {
202
-        return strpos( $haystack, $needle ) !== false;
201
+    public static function contains($needle, $haystack) {
202
+        return strpos($haystack, $needle) !== false;
203 203
     }
204 204
 
205 205
     /**
@@ -207,8 +207,8 @@  discard block
 block discarded – undo
207 207
      *
208 208
      * @return string
209 209
      */
210
-    public static function htmlentities( $string ) {
211
-        return htmlentities( $string, ENT_NOQUOTES );
210
+    public static function htmlentities($string) {
211
+        return htmlentities($string, ENT_NOQUOTES);
212 212
     }
213 213
 
214 214
     /**
@@ -217,15 +217,15 @@  discard block
 block discarded – undo
217 217
      *
218 218
      * @return string
219 219
      */
220
-    public static function htmlspecialchars_decode( $string, $onlyEscapedEntities = false ) {
221
-        if ( false === $onlyEscapedEntities ) {
222
-            return htmlspecialchars_decode( $string, ENT_NOQUOTES );
220
+    public static function htmlspecialchars_decode($string, $onlyEscapedEntities = false) {
221
+        if (false === $onlyEscapedEntities) {
222
+            return htmlspecialchars_decode($string, ENT_NOQUOTES);
223 223
         }
224 224
 
225
-        return preg_replace_callback( self::$htmlEntityRegex,
226
-                function ( $match ) {
227
-                    return self::htmlspecialchars_decode( $match[ 0 ] );
228
-                }, $string );
225
+        return preg_replace_callback(self::$htmlEntityRegex,
226
+                function($match) {
227
+                    return self::htmlspecialchars_decode($match[0]);
228
+                }, $string);
229 229
     }
230 230
 
231 231
     /**
@@ -240,8 +240,8 @@  discard block
 block discarded – undo
240 240
      *
241 241
      * @return bool
242 242
      */
243
-    public static function isADoubleEscapedEntity( $str ) {
244
-        return preg_match( self::$htmlEntityRegex, $str ) != 0;
243
+    public static function isADoubleEscapedEntity($str) {
244
+        return preg_match(self::$htmlEntityRegex, $str) != 0;
245 245
     }
246 246
 
247 247
     /**
@@ -249,8 +249,8 @@  discard block
 block discarded – undo
249 249
      *
250 250
      * @return bool
251 251
      */
252
-    public static function isAnEscapedHTML( $str ) {
253
-        return preg_match( "/\/[a-z]*&gt;/i", $str ) != 0;
252
+    public static function isAnEscapedHTML($str) {
253
+        return preg_match("/\/[a-z]*&gt;/i", $str) != 0;
254 254
     }
255 255
 
256 256
     /**
@@ -258,8 +258,8 @@  discard block
 block discarded – undo
258 258
      *
259 259
      * @return bool
260 260
      */
261
-    public static function isAValidUuid( $uuid ) {
262
-        return preg_match( '/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/', $uuid ) === 1;
261
+    public static function isAValidUuid($uuid) {
262
+        return preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/', $uuid) === 1;
263 263
     }
264 264
 
265 265
     /**
@@ -268,8 +268,8 @@  discard block
 block discarded – undo
268 268
      *
269 269
      * @return array|false|string[]
270 270
      */
271
-    public static function preg_split( $pattern, $subject ) {
272
-        return preg_split( $pattern, $subject, -1, PREG_SPLIT_NO_EMPTY );
271
+    public static function preg_split($pattern, $subject) {
272
+        return preg_split($pattern, $subject, -1, PREG_SPLIT_NO_EMPTY);
273 273
     }
274 274
 
275 275
     /**
@@ -287,8 +287,8 @@  discard block
 block discarded – undo
287 287
      *
288 288
      * @return string
289 289
      */
290
-    public static function escapeOnlyHTMLTags( $string ) {
291
-        return preg_replace( '/<(.*?)>/iu', '&lt;$1&gt;', $string );
290
+    public static function escapeOnlyHTMLTags($string) {
291
+        return preg_replace('/<(.*?)>/iu', '&lt;$1&gt;', $string);
292 292
     }
293 293
 
294 294
     /**
@@ -298,8 +298,8 @@  discard block
 block discarded – undo
298 298
      *
299 299
      * @return false|string
300 300
      */
301
-    public static function lastChar( $string ) {
302
-        return substr( $string, -1 );
301
+    public static function lastChar($string) {
302
+        return substr($string, -1);
303 303
     }
304 304
 
305 305
     /**
@@ -307,10 +307,10 @@  discard block
 block discarded – undo
307 307
      *
308 308
      * @return int
309 309
      */
310
-    public static function getTheNumberOfTrailingSpaces( $segment ) {
310
+    public static function getTheNumberOfTrailingSpaces($segment) {
311 311
         $number = 0;
312 312
 
313
-        return self::recursiveIncrementNumberOfTrailingSpaces( $segment, $number );
313
+        return self::recursiveIncrementNumberOfTrailingSpaces($segment, $number);
314 314
     }
315 315
 
316 316
     /**
@@ -319,12 +319,12 @@  discard block
 block discarded – undo
319 319
      *
320 320
      * @return int
321 321
      */
322
-    private static function recursiveIncrementNumberOfTrailingSpaces( $segment, &$number ) {
323
-        if ( self::lastChar( $segment ) === ' ' ) {
322
+    private static function recursiveIncrementNumberOfTrailingSpaces($segment, &$number) {
323
+        if (self::lastChar($segment) === ' ') {
324 324
             $number++;
325
-            $segment = substr( $segment, 0, -1 );
325
+            $segment = substr($segment, 0, -1);
326 326
 
327
-            return self::recursiveIncrementNumberOfTrailingSpaces( $segment, $number );
327
+            return self::recursiveIncrementNumberOfTrailingSpaces($segment, $number);
328 328
         }
329 329
 
330 330
         return $number;
@@ -337,15 +337,15 @@  discard block
 block discarded – undo
337 337
      *
338 338
      * @return bool
339 339
      */
340
-    public static function isHtmlString( $string ) {
341
-        $string = stripslashes( $string );
340
+    public static function isHtmlString($string) {
341
+        $string = stripslashes($string);
342 342
 
343
-        if ( $string === '<>' ) {
343
+        if ($string === '<>') {
344 344
             return false;
345 345
         }
346 346
 
347
-        preg_match( "/<\/?[a-zA-Z1-6-]+((\s+[a-zA-Z1-6-]+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)\/?>/", $string, $matches );
347
+        preg_match("/<\/?[a-zA-Z1-6-]+((\s+[a-zA-Z1-6-]+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)\/?>/", $string, $matches);
348 348
 
349
-        return count( $matches ) !== 0;
349
+        return count($matches) !== 0;
350 350
     }
351 351
 }
Please login to merge, or discard this patch.
src/Utils/Files.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -18,15 +18,15 @@  discard block
 block discarded – undo
18 18
      *
19 19
      * @return array|mixed
20 20
      */
21
-    public static function pathInfo( $path, $options = 15 ) {
22
-        $rawPath = explode( DIRECTORY_SEPARATOR, $path );
21
+    public static function pathInfo($path, $options = 15) {
22
+        $rawPath = explode(DIRECTORY_SEPARATOR, $path);
23 23
 
24
-        $basename = array_pop( $rawPath );
25
-        $dirname  = implode( DIRECTORY_SEPARATOR, $rawPath );
24
+        $basename = array_pop($rawPath);
25
+        $dirname  = implode(DIRECTORY_SEPARATOR, $rawPath);
26 26
 
27
-        $explodedFileName = explode( ".", $basename );
28
-        $extension        = strtolower( array_pop( $explodedFileName ) );
29
-        $filename         = implode( ".", $explodedFileName );
27
+        $explodedFileName = explode(".", $basename);
28
+        $extension        = strtolower(array_pop($explodedFileName));
29
+        $filename         = implode(".", $explodedFileName);
30 30
 
31 31
         $returnArray = [];
32 32
 
@@ -39,17 +39,17 @@  discard block
 block discarded – undo
39 39
 
40 40
         // foreach flag, add in $return_array the corresponding field,
41 41
         // obtained by variable name correspondence
42
-        foreach ( $flagMap as $field => $i ) {
42
+        foreach ($flagMap as $field => $i) {
43 43
             //binary AND
44
-            if ( ( $options & $i ) > 0 ) {
44
+            if (($options & $i) > 0) {
45 45
                 //variable substitution: $field can be one between 'dirname', 'basename', 'extension', 'filename'
46 46
                 // $$field gets the value of the variable named $field
47
-                $returnArray[ $field ] = $$field;
47
+                $returnArray[$field] = $$field;
48 48
             }
49 49
         }
50 50
 
51
-        if ( count( $returnArray ) == 1 ) {
52
-            $returnArray = array_pop( $returnArray );
51
+        if (count($returnArray) == 1) {
52
+            $returnArray = array_pop($returnArray);
53 53
         }
54 54
 
55 55
         return $returnArray;
@@ -60,14 +60,14 @@  discard block
 block discarded – undo
60 60
      *
61 61
      * @return false|string
62 62
      */
63
-    public static function getExtension( $path ) {
64
-        $pathInfo = self::pathInfo( $path );
63
+    public static function getExtension($path) {
64
+        $pathInfo = self::pathInfo($path);
65 65
 
66
-        if ( empty( $pathInfo ) ) {
66
+        if (empty($pathInfo)) {
67 67
             return false;
68 68
         }
69 69
 
70
-        return strtolower( $pathInfo[ 'extension' ] );
70
+        return strtolower($pathInfo['extension']);
71 71
     }
72 72
 
73 73
     /**
@@ -75,14 +75,14 @@  discard block
 block discarded – undo
75 75
      *
76 76
      * @return bool
77 77
      */
78
-    public static function isXliff( $path ) {
79
-        $extension = self::getExtension( $path );
78
+    public static function isXliff($path) {
79
+        $extension = self::getExtension($path);
80 80
 
81
-        if ( !$extension ) {
81
+        if (!$extension) {
82 82
             return false;
83 83
         }
84 84
 
85
-        switch ( $extension ) {
85
+        switch ($extension) {
86 86
             case 'xliff':
87 87
             case 'sdlxliff':
88 88
             case 'tmx':
@@ -98,14 +98,14 @@  discard block
 block discarded – undo
98 98
      *
99 99
      * @return bool|string
100 100
      */
101
-    public static function getMemoryFileType( $path ) {
102
-        $pathInfo = self::pathInfo( $path );
101
+    public static function getMemoryFileType($path) {
102
+        $pathInfo = self::pathInfo($path);
103 103
 
104
-        if ( empty( $pathInfo ) ) {
104
+        if (empty($pathInfo)) {
105 105
             return false;
106 106
         }
107 107
 
108
-        switch ( strtolower( $pathInfo[ 'extension' ] ) ) {
108
+        switch (strtolower($pathInfo['extension'])) {
109 109
             case 'tmx':
110 110
                 return 'tmx';
111 111
             case 'g':
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
      *
121 121
      * @return bool
122 122
      */
123
-    public static function isTMXFile( $path ) {
124
-        return self::getMemoryFileType( $path ) === 'tmx';
123
+    public static function isTMXFile($path) {
124
+        return self::getMemoryFileType($path) === 'tmx';
125 125
     }
126 126
 
127 127
     /**
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      *
130 130
      * @return bool
131 131
      */
132
-    public static function isGlossaryFile( $path ) {
133
-        return self::getMemoryFileType( $path ) === 'glossary';
132
+    public static function isGlossaryFile($path) {
133
+        return self::getMemoryFileType($path) === 'glossary';
134 134
     }
135 135
 }
Please login to merge, or discard this patch.