Passed
Push — master ( a19423...673e99 )
by Domenico
02:59 queued 29s
created
src/Utils/CatUtils.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@  discard block
 block discarded – undo
10 10
      *
11 11
      * @return bool
12 12
      */
13
-    public static function contains( $needle, $haystack ) {
14
-        return mb_strpos( $haystack, $needle ) !== false;
13
+    public static function contains($needle, $haystack) {
14
+        return mb_strpos($haystack, $needle) !== false;
15 15
     }
16 16
 
17 17
     /**
@@ -24,25 +24,25 @@  discard block
 block discarded – undo
24 24
      * @return int
25 25
      *
26 26
      */
27
-    public static function fastUnicode2ord( $mb_char ) {
28
-        switch ( strlen( $mb_char ) ) {
27
+    public static function fastUnicode2ord($mb_char) {
28
+        switch (strlen($mb_char)) {
29 29
             case 1:
30
-                return ord( $mb_char );
30
+                return ord($mb_char);
31 31
                 break;
32 32
             case 2:
33
-                return ( ord( $mb_char[ 0 ] ) - 0xC0 ) * 0x40 +
34
-                        ord( $mb_char[ 1 ] ) - 0x80;
33
+                return (ord($mb_char[0]) - 0xC0) * 0x40 +
34
+                        ord($mb_char[1]) - 0x80;
35 35
                 break;
36 36
             case 3:
37
-                return ( ord( $mb_char[ 0 ] ) - 0xE0 ) * 0x1000 +
38
-                        ( ord( $mb_char[ 1 ] ) - 0x80 ) * 0x40 +
39
-                        ord( $mb_char[ 2 ] ) - 0x80;
37
+                return (ord($mb_char[0]) - 0xE0) * 0x1000 +
38
+                        (ord($mb_char[1]) - 0x80) * 0x40 +
39
+                        ord($mb_char[2]) - 0x80;
40 40
                 break;
41 41
             case 4:
42
-                return ( ord( $mb_char[ 0 ] ) - 0xF0 ) * 0x40000 +
43
-                        ( ord( $mb_char[ 1 ] ) - 0x80 ) * 0x1000 +
44
-                        ( ord( $mb_char[ 2 ] ) - 0x80 ) * 0x40 +
45
-                        ord( $mb_char[ 3 ] ) - 0x80;
42
+                return (ord($mb_char[0]) - 0xF0) * 0x40000 +
43
+                        (ord($mb_char[1]) - 0x80) * 0x1000 +
44
+                        (ord($mb_char[2]) - 0x80) * 0x40 +
45
+                        ord($mb_char[3]) - 0x80;
46 46
                 break;
47 47
         }
48 48
 
@@ -54,8 +54,8 @@  discard block
 block discarded – undo
54 54
      *
55 55
      * @return string
56 56
      */
57
-    public static function htmlentitiesFromUnicode( $str ) {
58
-        return "&#" . self::fastUnicode2ord( $str[ 1 ] ) . ";";
57
+    public static function htmlentitiesFromUnicode($str) {
58
+        return "&#".self::fastUnicode2ord($str[1]).";";
59 59
     }
60 60
 
61 61
     /**
@@ -68,11 +68,11 @@  discard block
 block discarded – undo
68 68
      *
69 69
      * @return string
70 70
      */
71
-    public static function unicode2chr( $o ) {
72
-        if ( function_exists( 'mb_convert_encoding' ) ) {
73
-            return mb_convert_encoding( '&#' . intval( $o ) . ';', 'UTF-8', 'HTML-ENTITIES' );
71
+    public static function unicode2chr($o) {
72
+        if (function_exists('mb_convert_encoding')) {
73
+            return mb_convert_encoding('&#'.intval($o).';', 'UTF-8', 'HTML-ENTITIES');
74 74
         }
75 75
 
76
-        return chr( intval( $o ) );
76
+        return chr(intval($o));
77 77
     }
78 78
 }
79 79
\ No newline at end of file
Please login to merge, or discard this patch.
src/Utils/DataRefReplacer.php 1 patch
Spacing   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
      *
26 26
      * @param array $map
27 27
      */
28
-    public function __construct( array $map = null ) {
28
+    public function __construct(array $map = null) {
29 29
         $this->map = $map;
30 30
     }
31 31
 
@@ -43,36 +43,36 @@  discard block
 block discarded – undo
43 43
      * @throws InvalidXmlException
44 44
      * @throws XmlParsingException
45 45
      */
46
-    public function replace( $string ) {
46
+    public function replace($string) {
47 47
 
48 48
         // if map is empty
49 49
         // or the string has not a dataRef attribute
50 50
         // return string as is
51
-        if ( empty( $this->map ) || !$this->hasAnyDataRefAttribute( $string ) ) {
51
+        if (empty($this->map) || !$this->hasAnyDataRefAttribute($string)) {
52 52
             return $string;
53 53
         }
54 54
 
55 55
         // (recursively) clean string from equiv-text eventually present
56
-        $string = $this->cleanFromEquivText( $string );
56
+        $string = $this->cleanFromEquivText($string);
57 57
 
58
-        $html = XmlParser::parse( $string, true );
58
+        $html = XmlParser::parse($string, true);
59 59
 
60 60
         // 1. Replace <ph>|<sc>|<ec> tags
61
-        foreach ( $html as $node ) {
62
-            $string = $this->recursiveAddEquivTextToPhTag( $node, $string );
61
+        foreach ($html as $node) {
62
+            $string = $this->recursiveAddEquivTextToPhTag($node, $string);
63 63
         }
64 64
 
65 65
         // 2. Replace <pc> tags
66
-        if ( $this->stringContainsPcTags( $string ) ) {
66
+        if ($this->stringContainsPcTags($string)) {
67 67
 
68 68
             // replace self-closed <pc />
69
-            $string = $this->replaceSelfClosedPcTags( $string );
69
+            $string = $this->replaceSelfClosedPcTags($string);
70 70
 
71 71
             // create a dataRefEnd map
72 72
             // (needed for correct handling of </pc> closing tags)
73
-            $dataRefEndMap = $this->buildDataRefEndMap( $html );
74
-            $string        = $this->replaceOpeningPcTags( $string );
75
-            $string        = $this->replaceClosingPcTags( $string, $dataRefEndMap );
73
+            $dataRefEndMap = $this->buildDataRefEndMap($html);
74
+            $string        = $this->replaceOpeningPcTags($string);
75
+            $string        = $this->replaceClosingPcTags($string, $dataRefEndMap);
76 76
         }
77 77
 
78 78
         return $string;
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
      *
84 84
      * @return bool
85 85
      */
86
-    private function hasAnyDataRefAttribute( $string ) {
87
-        return (bool)preg_match( '/(dataRef|dataRefStart|dataRefEnd)=[\'"].*?[\'"]/', $string );
86
+    private function hasAnyDataRefAttribute($string) {
87
+        return (bool) preg_match('/(dataRef|dataRefStart|dataRefEnd)=[\'"].*?[\'"]/', $string);
88 88
     }
89 89
 
90 90
     /**
@@ -95,11 +95,11 @@  discard block
 block discarded – undo
95 95
      * @throws InvalidXmlException
96 96
      * @throws XmlParsingException
97 97
      */
98
-    private function cleanFromEquivText( $string ) {
99
-        $html = XmlParser::parse( $string, true );
98
+    private function cleanFromEquivText($string) {
99
+        $html = XmlParser::parse($string, true);
100 100
 
101
-        foreach ( $html as $node ) {
102
-            $string = $this->recursiveCleanFromEquivText( $node, $string );
101
+        foreach ($html as $node) {
102
+            $string = $this->recursiveCleanFromEquivText($node, $string);
103 103
         }
104 104
 
105 105
         return $string;
@@ -118,56 +118,56 @@  discard block
 block discarded – undo
118 118
      *
119 119
      * @return string
120 120
      */
121
-    private function recursiveAddEquivTextToPhTag( $node, $string ) {
122
-        if ( $node->has_children ) {
123
-            foreach ( $node->inner_html as $childNode ) {
124
-                $string = $this->recursiveAddEquivTextToPhTag( $childNode, $string );
121
+    private function recursiveAddEquivTextToPhTag($node, $string) {
122
+        if ($node->has_children) {
123
+            foreach ($node->inner_html as $childNode) {
124
+                $string = $this->recursiveAddEquivTextToPhTag($childNode, $string);
125 125
             }
126 126
         } else {
127
-            if ( $node->tagName === 'ph' || $node->tagName === 'sc' || $node->tagName === 'ec' ) {
128
-                if ( !isset( $node->attributes[ 'dataRef' ] ) ) {
127
+            if ($node->tagName === 'ph' || $node->tagName === 'sc' || $node->tagName === 'ec') {
128
+                if (!isset($node->attributes['dataRef'])) {
129 129
                     return $string;
130 130
                 }
131 131
 
132
-                $a = $node->node;  // complete match. Eg:  <ph id="source1" dataRef="source1"/>
133
-                $b = $node->attributes[ 'dataRef' ];   // map identifier. Eg: source1
132
+                $a = $node->node; // complete match. Eg:  <ph id="source1" dataRef="source1"/>
133
+                $b = $node->attributes['dataRef']; // map identifier. Eg: source1
134 134
 
135 135
                 // if isset a value in the map calculate base64 encoded value
136 136
                 // otherwise skip
137
-                if ( !in_array( $b, array_keys( $this->map ) ) ) {
137
+                if (!in_array($b, array_keys($this->map))) {
138 138
                     return $string;
139 139
                 }
140 140
 
141 141
                 // check if is null, in this case convert it to NULL string
142
-                if ( is_null( $this->map[ $b ] ) ) {
143
-                    $this->map[ $b ] = 'NULL';
142
+                if (is_null($this->map[$b])) {
143
+                    $this->map[$b] = 'NULL';
144 144
                 }
145 145
 
146
-                $value              = $this->map[ $b ];
147
-                $base64EncodedValue = base64_encode( $value );
146
+                $value              = $this->map[$b];
147
+                $base64EncodedValue = base64_encode($value);
148 148
 
149
-                if ( empty( $base64EncodedValue ) ) {
149
+                if (empty($base64EncodedValue)) {
150 150
                     return $string;
151 151
                 }
152 152
 
153 153
                 // if there is no id copy it from dataRef
154
-                $id = ( !isset( $node->attributes[ 'id' ] ) ) ? ' id="' . $b . '" removeId="true"' : '';
154
+                $id = (!isset($node->attributes['id'])) ? ' id="'.$b.'" removeId="true"' : '';
155 155
 
156 156
                 // introduce dataType for <ec>/<sc> tag handling
157
-                $dataType = ( $this->isAEcOrScTag( $node ) ) ? ' dataType="' . $node->tagName . '"' : '';
157
+                $dataType = ($this->isAEcOrScTag($node)) ? ' dataType="'.$node->tagName.'"' : '';
158 158
 
159 159
                 // replacement
160
-                $d = str_replace( '/', $id . $dataType . ' equiv-text="base64:' . $base64EncodedValue . '"/', $a );
161
-                $a = $this->removeAngleBrackets( $a );
162
-                $d = $this->removeAngleBrackets( $d );
160
+                $d = str_replace('/', $id.$dataType.' equiv-text="base64:'.$base64EncodedValue.'"/', $a);
161
+                $a = $this->removeAngleBrackets($a);
162
+                $d = $this->removeAngleBrackets($d);
163 163
 
164 164
                 // convert <ec>/<sc> into <ph>
165
-                if ( $this->isAEcOrScTag( $node ) ) {
166
-                    $d = 'ph' . substr( $d, 2 );
167
-                    $d = trim( $d );
165
+                if ($this->isAEcOrScTag($node)) {
166
+                    $d = 'ph'.substr($d, 2);
167
+                    $d = trim($d);
168 168
                 }
169 169
 
170
-                return str_replace( $a, $d, $string );
170
+                return str_replace($a, $d, $string);
171 171
             }
172 172
         }
173 173
 
@@ -179,10 +179,10 @@  discard block
 block discarded – undo
179 179
      *
180 180
      * @return bool
181 181
      */
182
-    private function stringContainsPcTags( $string ) {
183
-        preg_match_all( '/<pc [^>]+?>/iu', $string, $openingPcMatches );
182
+    private function stringContainsPcTags($string) {
183
+        preg_match_all('/<pc [^>]+?>/iu', $string, $openingPcMatches);
184 184
 
185
-        return ( isset( $openingPcMatches[ 0 ] ) && count( $openingPcMatches[ 0 ] ) > 0 );
185
+        return (isset($openingPcMatches[0]) && count($openingPcMatches[0]) > 0);
186 186
     }
187 187
 
188 188
     /**
@@ -193,20 +193,20 @@  discard block
 block discarded – undo
193 193
      * @throws InvalidXmlException
194 194
      * @throws XmlParsingException
195 195
      */
196
-    private function replaceSelfClosedPcTags( $string ) {
196
+    private function replaceSelfClosedPcTags($string) {
197 197
 
198 198
         $regex = '|<pc[^>]+?/>|iu';
199
-        preg_match_all( $regex, $string, $selfClosedPcMatches );
199
+        preg_match_all($regex, $string, $selfClosedPcMatches);
200 200
 
201
-        foreach ( $selfClosedPcMatches[ 0 ] as $match ) {
201
+        foreach ($selfClosedPcMatches[0] as $match) {
202 202
 
203
-            $html       = XmlParser::parse( $match, true );
204
-            $node       = $html[ 0 ];
203
+            $html       = XmlParser::parse($match, true);
204
+            $node       = $html[0];
205 205
             $attributes = $node->attributes;
206 206
 
207
-            if ( isset( $attributes[ 'dataRefStart' ] ) && array_key_exists( $node->attributes[ 'dataRefStart' ], $this->map ) ) {
208
-                $replacement = '<ph id="' . $attributes[ 'id' ] . '" dataType="pcSelf" originalData="' . base64_encode( $match ) . '" dataRef="' . $attributes[ 'dataRefStart' ] . '" equiv-text="base64:' . base64_encode( $this->map[ $node->attributes[ 'dataRefStart' ] ] ) . '"/>';
209
-                $string      = str_replace( $match, $replacement, $string );
207
+            if (isset($attributes['dataRefStart']) && array_key_exists($node->attributes['dataRefStart'], $this->map)) {
208
+                $replacement = '<ph id="'.$attributes['id'].'" dataType="pcSelf" originalData="'.base64_encode($match).'" dataRef="'.$attributes['dataRefStart'].'" equiv-text="base64:'.base64_encode($this->map[$node->attributes['dataRefStart']]).'"/>';
209
+                $string      = str_replace($match, $replacement, $string);
210 210
             }
211 211
         }
212 212
 
@@ -221,12 +221,12 @@  discard block
 block discarded – undo
221 221
      *
222 222
      * @return array
223 223
      */
224
-    private function buildDataRefEndMap( $html ) {
224
+    private function buildDataRefEndMap($html) {
225 225
         $dataRefEndMap = [];
226 226
 
227
-        foreach ( $html as $index => $node ) {
228
-            if ( $node->tagName === 'pc' ) {
229
-                $this->extractDataRefMapRecursively( $node, $dataRefEndMap );
227
+        foreach ($html as $index => $node) {
228
+            if ($node->tagName === 'pc') {
229
+                $this->extractDataRefMapRecursively($node, $dataRefEndMap);
230 230
             }
231 231
         }
232 232
 
@@ -239,25 +239,25 @@  discard block
 block discarded – undo
239 239
      * @param object $node
240 240
      * @param        $dataRefEndMap
241 241
      */
242
-    private function extractDataRefMapRecursively( $node, &$dataRefEndMap ) {
243
-        if ( $this->nodeContainsNestedPcTags( $node ) ) {
244
-            foreach ( $node->inner_html as $nestedNode ) {
245
-                $this->extractDataRefMapRecursively( $nestedNode, $dataRefEndMap );
242
+    private function extractDataRefMapRecursively($node, &$dataRefEndMap) {
243
+        if ($this->nodeContainsNestedPcTags($node)) {
244
+            foreach ($node->inner_html as $nestedNode) {
245
+                $this->extractDataRefMapRecursively($nestedNode, $dataRefEndMap);
246 246
             }
247 247
         }
248 248
 
249 249
         // EXCLUDE self closed <pc/>
250
-        if ( $node->tagName === 'pc' && $node->self_closed === false ) {
251
-            if ( isset( $node->attributes[ 'dataRefEnd' ] ) ) {
252
-                $dataRefEnd = $node->attributes[ 'dataRefEnd' ];
253
-            } elseif ( isset( $node->attributes[ 'dataRefStart' ] ) ) {
254
-                $dataRefEnd = $node->attributes[ 'dataRefStart' ];
250
+        if ($node->tagName === 'pc' && $node->self_closed === false) {
251
+            if (isset($node->attributes['dataRefEnd'])) {
252
+                $dataRefEnd = $node->attributes['dataRefEnd'];
253
+            } elseif (isset($node->attributes['dataRefStart'])) {
254
+                $dataRefEnd = $node->attributes['dataRefStart'];
255 255
             } else {
256 256
                 $dataRefEnd = null;
257 257
             }
258 258
 
259 259
             $dataRefEndMap[] = [
260
-                    'id'         => isset( $node->attributes[ 'id' ] ) ? $node->attributes[ 'id' ] : null,
260
+                    'id'         => isset($node->attributes['id']) ? $node->attributes['id'] : null,
261 261
                     'dataRefEnd' => $dataRefEnd,
262 262
             ];
263 263
         }
@@ -269,20 +269,20 @@  discard block
 block discarded – undo
269 269
      *
270 270
      * @return string|string[]
271 271
      */
272
-    private function recursiveCleanFromEquivText( $node, $string ) {
272
+    private function recursiveCleanFromEquivText($node, $string) {
273 273
 
274
-        if ( $node->tagName == '#text' ) {
274
+        if ($node->tagName == '#text') {
275 275
             return $string;
276 276
         }
277 277
 
278
-        if ( $node->has_children ) {
279
-            foreach ( $node->inner_html as $childNode ) {
280
-                $string = $this->recursiveCleanFromEquivText( $childNode, $string );
278
+        if ($node->has_children) {
279
+            foreach ($node->inner_html as $childNode) {
280
+                $string = $this->recursiveCleanFromEquivText($childNode, $string);
281 281
             }
282 282
         } else {
283
-            if ( isset( $node->attributes[ 'dataRef' ] ) && array_key_exists( $node->attributes[ 'dataRef' ], $this->map ) ) {
284
-                $cleaned = preg_replace( '/ equiv-text="(.*?)"/', '', $node->node );
285
-                $string  = str_replace( $node->node, $cleaned, $string );
283
+            if (isset($node->attributes['dataRef']) && array_key_exists($node->attributes['dataRef'], $this->map)) {
284
+                $cleaned = preg_replace('/ equiv-text="(.*?)"/', '', $node->node);
285
+                $string  = str_replace($node->node, $cleaned, $string);
286 286
             }
287 287
         }
288 288
 
@@ -296,41 +296,41 @@  discard block
 block discarded – undo
296 296
      *
297 297
      * @return string
298 298
      */
299
-    private function replaceOpeningPcTags( $string ) {
299
+    private function replaceOpeningPcTags($string) {
300 300
 
301
-        preg_match_all( '|<pc ([^>/]+?)>|iu', $string, $openingPcMatches );
301
+        preg_match_all('|<pc ([^>/]+?)>|iu', $string, $openingPcMatches);
302 302
 
303
-        foreach ( $openingPcMatches[ 0 ] as $index => $match ) {
303
+        foreach ($openingPcMatches[0] as $index => $match) {
304 304
 
305
-            preg_match_all( '|([a-zA-Z]+?)\s*=\s*[\'"](.+?)[\'"]|', $openingPcMatches[ 1 ][ $index ], $_attr, PREG_SET_ORDER );
305
+            preg_match_all('|([a-zA-Z]+?)\s*=\s*[\'"](.+?)[\'"]|', $openingPcMatches[1][$index], $_attr, PREG_SET_ORDER);
306 306
 
307 307
             $attr = [];
308
-            foreach ( $_attr as $attrGroup ) {
309
-                $attr[ $attrGroup[ 1 ] ] = $attrGroup[ 2 ];
308
+            foreach ($_attr as $attrGroup) {
309
+                $attr[$attrGroup[1]] = $attrGroup[2];
310 310
             }
311 311
 
312 312
             // CASE 1 - Missing `dataRefStart`
313
-            if ( isset( $attr[ 'dataRefEnd' ] ) && !isset( $attr[ 'dataRefStart' ] ) ) {
314
-                $attr[ 'dataRefStart' ] = $attr[ 'dataRefEnd' ];
313
+            if (isset($attr['dataRefEnd']) && !isset($attr['dataRefStart'])) {
314
+                $attr['dataRefStart'] = $attr['dataRefEnd'];
315 315
             }
316 316
 
317 317
             // CASE 2 - Missing `dataRefEnd`
318
-            if ( isset( $attr[ 'dataRefStart' ] ) && !isset( $attr[ 'dataRefEnd' ] ) ) {
319
-                $attr[ 'dataRefEnd' ] = $attr[ 'dataRefStart' ];
318
+            if (isset($attr['dataRefStart']) && !isset($attr['dataRefEnd'])) {
319
+                $attr['dataRefEnd'] = $attr['dataRefStart'];
320 320
             }
321 321
 
322
-            if ( isset( $attr[ 'dataRefStart' ] ) ) {
322
+            if (isset($attr['dataRefStart'])) {
323 323
                 $startOriginalData       = $match; // opening <pc>
324
-                $startValue              = $this->map[ $attr[ 'dataRefStart' ] ] ?: 'NULL'; //handling null values in original data map
325
-                $base64EncodedStartValue = base64_encode( $startValue );
326
-                $base64StartOriginalData = base64_encode( $startOriginalData );
324
+                $startValue              = $this->map[$attr['dataRefStart']] ?: 'NULL'; //handling null values in original data map
325
+                $base64EncodedStartValue = base64_encode($startValue);
326
+                $base64StartOriginalData = base64_encode($startOriginalData);
327 327
 
328 328
                 // conversion for opening <pc> tag
329
-                $openingPcConverted = '<ph ' . ( ( isset( $attr[ 'id' ] ) ) ? 'id="' . $attr[ 'id' ] . '_1"' : '' ) . ' dataType="pcStart" originalData="' . $base64StartOriginalData . '" dataRef="'
330
-                        . $attr[ 'dataRefStart' ] . '" equiv-text="base64:'
331
-                        . $base64EncodedStartValue . '"/>';
329
+                $openingPcConverted = '<ph '.((isset($attr['id'])) ? 'id="'.$attr['id'].'_1"' : '').' dataType="pcStart" originalData="'.$base64StartOriginalData.'" dataRef="'
330
+                        . $attr['dataRefStart'].'" equiv-text="base64:'
331
+                        . $base64EncodedStartValue.'"/>';
332 332
 
333
-                $string = str_replace( $startOriginalData, $openingPcConverted, $string );
333
+                $string = str_replace($startOriginalData, $openingPcConverted, $string);
334 334
             }
335 335
         }
336 336
 
@@ -346,33 +346,33 @@  discard block
 block discarded – undo
346 346
      *
347 347
      * @return string
348 348
      */
349
-    private function replaceClosingPcTags( $string, $dataRefEndMap = [] ) {
350
-        preg_match_all( '|</pc>|iu', $string, $closingPcMatches, PREG_OFFSET_CAPTURE );
349
+    private function replaceClosingPcTags($string, $dataRefEndMap = []) {
350
+        preg_match_all('|</pc>|iu', $string, $closingPcMatches, PREG_OFFSET_CAPTURE);
351 351
         $delta = 0;
352 352
 
353
-        foreach ( $closingPcMatches[ 0 ] as $index => $match ) {
354
-            $offset = $match[ 1 ];
355
-            $length = strlen( $match[ 0 ] );
356
-            $attr   = $dataRefEndMap[ $index ];
353
+        foreach ($closingPcMatches[0] as $index => $match) {
354
+            $offset = $match[1];
355
+            $length = strlen($match[0]);
356
+            $attr   = $dataRefEndMap[$index];
357 357
 
358
-            if ( !empty( $attr ) && isset( $attr[ 'dataRefEnd' ] ) ) {
359
-                $endOriginalData       = $match[ 0 ]; // </pc>
360
-                $endValue              = $this->map[ $attr[ 'dataRefEnd' ] ] ?: 'NULL';
361
-                $base64EncodedEndValue = base64_encode( $endValue );
362
-                $base64EndOriginalData = base64_encode( $endOriginalData );
358
+            if (!empty($attr) && isset($attr['dataRefEnd'])) {
359
+                $endOriginalData       = $match[0]; // </pc>
360
+                $endValue              = $this->map[$attr['dataRefEnd']] ?: 'NULL';
361
+                $base64EncodedEndValue = base64_encode($endValue);
362
+                $base64EndOriginalData = base64_encode($endOriginalData);
363 363
 
364 364
                 // conversion for closing <pc> tag
365
-                $closingPcConverted = '<ph ' . ( ( isset( $attr[ 'id' ] ) ) ? 'id="' . $attr[ 'id' ] . '_2"' : '' ) . ' dataType="pcEnd" originalData="' . $base64EndOriginalData . '" dataRef="'
366
-                        . $attr[ 'dataRefEnd' ] . '" equiv-text="base64:' . $base64EncodedEndValue . '"/>';
365
+                $closingPcConverted = '<ph '.((isset($attr['id'])) ? 'id="'.$attr['id'].'_2"' : '').' dataType="pcEnd" originalData="'.$base64EndOriginalData.'" dataRef="'
366
+                        . $attr['dataRefEnd'].'" equiv-text="base64:'.$base64EncodedEndValue.'"/>';
367 367
 
368
-                $realOffset = ( $delta === 0 ) ? $offset : ( $offset + $delta );
368
+                $realOffset = ($delta === 0) ? $offset : ($offset + $delta);
369 369
 
370
-                $string = substr_replace( $string, $closingPcConverted, $realOffset, $length );
371
-                $delta  = $delta + strlen( $closingPcConverted ) - $length;
370
+                $string = substr_replace($string, $closingPcConverted, $realOffset, $length);
371
+                $delta  = $delta + strlen($closingPcConverted) - $length;
372 372
             }
373 373
         }
374 374
 
375
-        return !is_array( $string ) ? $string : implode( $string );
375
+        return !is_array($string) ? $string : implode($string);
376 376
     }
377 377
 
378 378
     /**
@@ -380,13 +380,13 @@  discard block
 block discarded – undo
380 380
      *
381 381
      * @return bool
382 382
      */
383
-    private function nodeContainsNestedPcTags( $node ) {
384
-        if ( !$node->has_children ) {
383
+    private function nodeContainsNestedPcTags($node) {
384
+        if (!$node->has_children) {
385 385
             return false;
386 386
         }
387 387
 
388
-        foreach ( $node->inner_html as $nestedNode ) {
389
-            if ( $nestedNode->tagName === 'pc' && ( isset( $node->attributes[ 'dataRefEnd' ] ) || isset( $node->attributes[ 'dataRefStart' ] ) ) ) {
388
+        foreach ($node->inner_html as $nestedNode) {
389
+            if ($nestedNode->tagName === 'pc' && (isset($node->attributes['dataRefEnd']) || isset($node->attributes['dataRefStart']))) {
390 390
                 return true;
391 391
             }
392 392
         }
@@ -399,18 +399,18 @@  discard block
 block discarded – undo
399 399
      *
400 400
      * @return string
401 401
      */
402
-    public function restore( $string ) {
402
+    public function restore($string) {
403 403
         // if map is empty return string as is
404
-        if ( empty( $this->map ) ) {
404
+        if (empty($this->map)) {
405 405
             return $string;
406 406
         }
407 407
 
408 408
         // replace eventual empty equiv-text=""
409
-        $string = str_replace( ' equiv-text=""', '', $string );
410
-        $html   = XmlParser::parse( $string, true );
409
+        $string = str_replace(' equiv-text=""', '', $string);
410
+        $html   = XmlParser::parse($string, true);
411 411
 
412
-        foreach ( $html as $node ) {
413
-            $string = $this->recursiveRemoveOriginalData( $node, $string );
412
+        foreach ($html as $node) {
413
+            $string = $this->recursiveRemoveOriginalData($node, $string);
414 414
         }
415 415
 
416 416
         return $string;
@@ -422,75 +422,75 @@  discard block
 block discarded – undo
422 422
      *
423 423
      * @return string|string[]
424 424
      */
425
-    private function recursiveRemoveOriginalData( $node, $string ) {
426
-        if ( $node->has_children ) {
427
-            foreach ( $node->inner_html as $childNode ) {
428
-                $string = $this->recursiveRemoveOriginalData( $childNode, $string );
425
+    private function recursiveRemoveOriginalData($node, $string) {
426
+        if ($node->has_children) {
427
+            foreach ($node->inner_html as $childNode) {
428
+                $string = $this->recursiveRemoveOriginalData($childNode, $string);
429 429
             }
430 430
         } else {
431 431
 
432
-            if ( !isset( $node->attributes[ 'dataRef' ] ) ) {
432
+            if (!isset($node->attributes['dataRef'])) {
433 433
                 return $string;
434 434
             }
435 435
 
436
-            $a = $node->node;                  // complete match. Eg:  <ph id="source1" dataRef="source1"/>
437
-            $b = $node->attributes[ 'dataRef' ]; // map identifier. Eg: source1
436
+            $a = $node->node; // complete match. Eg:  <ph id="source1" dataRef="source1"/>
437
+            $b = $node->attributes['dataRef']; // map identifier. Eg: source1
438 438
 
439 439
             // if isset a value in the map calculate base64 encoded value
440 440
             // or it is an empty string
441 441
             // otherwise skip
442
-            if ( !in_array( $b, array_keys( $this->map ) ) ) {
442
+            if (!in_array($b, array_keys($this->map))) {
443 443
                 return $string;
444 444
             }
445 445
 
446 446
             // check if is null, in this case convert it to NULL string
447
-            if ( is_null( $this->map[ $b ] ) ) {
448
-                $this->map[ $b ] = 'NULL';
447
+            if (is_null($this->map[$b])) {
448
+                $this->map[$b] = 'NULL';
449 449
             }
450 450
 
451 451
             // remove id?
452
-            $removeId = ( isset( $node->attributes[ 'removeId' ] ) && $node->attributes[ 'removeId' ] === "true" ) ? ' id="' . $b . '" removeId="true"' : '';
452
+            $removeId = (isset($node->attributes['removeId']) && $node->attributes['removeId'] === "true") ? ' id="'.$b.'" removeId="true"' : '';
453 453
 
454 454
             // grab dataType attribute for <ec>/<sc> tag handling
455
-            $dataType = ( $this->wasAEcOrScTag( $node ) ) ? ' dataType="' . $node->attributes[ 'dataType' ] . '"' : '';
455
+            $dataType = ($this->wasAEcOrScTag($node)) ? ' dataType="'.$node->attributes['dataType'].'"' : '';
456 456
 
457
-            $d = str_replace( $removeId . $dataType . ' equiv-text="base64:' . base64_encode( $this->map[ $b ] ) . '"/>', '/>', $a );
457
+            $d = str_replace($removeId.$dataType.' equiv-text="base64:'.base64_encode($this->map[$b]).'"/>', '/>', $a);
458 458
 
459 459
             // replace original <ec>/<sc> tag
460
-            if ( $this->wasAEcOrScTag( $node ) ) {
461
-                $d = $node->attributes[ 'dataType' ] . substr( $d, 3 );
462
-                $d = trim( $d );
460
+            if ($this->wasAEcOrScTag($node)) {
461
+                $d = $node->attributes['dataType'].substr($d, 3);
462
+                $d = trim($d);
463 463
             }
464 464
 
465 465
             // replace only content tag, no matter if the string is encoded or not
466 466
             // in this way we can handle string with mixed tags (encoded and not-encoded)
467 467
             // in the same string
468
-            $a = $this->removeAngleBrackets( $a );
469
-            $d = $this->removeAngleBrackets( $d );
468
+            $a = $this->removeAngleBrackets($a);
469
+            $d = $this->removeAngleBrackets($d);
470 470
 
471
-            $string = str_replace( $a, $d, $string );
471
+            $string = str_replace($a, $d, $string);
472 472
 
473 473
             // restoring <pc/> self-closed here
474
-            if ( CatUtils::contains( 'dataType="pcSelf"', $d ) ) {
475
-                preg_match( '/\s?originalData="(.*?)"\s?/', $d, $originalDataMatches );
474
+            if (CatUtils::contains('dataType="pcSelf"', $d)) {
475
+                preg_match('/\s?originalData="(.*?)"\s?/', $d, $originalDataMatches);
476 476
 
477
-                if ( isset( $originalDataMatches[ 1 ] ) ) {
478
-                    $originalData = base64_decode( $originalDataMatches[ 1 ] );
479
-                    $originalData = $this->removeAngleBrackets( $originalData );
480
-                    $string       = str_replace( $d, $originalData, $string );
477
+                if (isset($originalDataMatches[1])) {
478
+                    $originalData = base64_decode($originalDataMatches[1]);
479
+                    $originalData = $this->removeAngleBrackets($originalData);
480
+                    $string       = str_replace($d, $originalData, $string);
481 481
                 }
482 482
             }
483 483
 
484 484
             // restoring <pc> tags here
485 485
             // if <ph> tag has originalData and originalType is pcStart or pcEnd,
486 486
             // replace with original data
487
-            if ( CatUtils::contains( 'dataType="pcStart"', $d ) || CatUtils::contains( 'dataType="pcEnd"', $d ) ) {
488
-                preg_match( '/\s?originalData="(.*?)"\s?/', $d, $originalDataMatches );
487
+            if (CatUtils::contains('dataType="pcStart"', $d) || CatUtils::contains('dataType="pcEnd"', $d)) {
488
+                preg_match('/\s?originalData="(.*?)"\s?/', $d, $originalDataMatches);
489 489
 
490
-                if ( isset( $originalDataMatches[ 1 ] ) ) {
491
-                    $originalData = base64_decode( $originalDataMatches[ 1 ] );
492
-                    $originalData = $this->removeAngleBrackets( $originalData );
493
-                    $string       = str_replace( $d, $originalData, $string );
490
+                if (isset($originalDataMatches[1])) {
491
+                    $originalData = base64_decode($originalDataMatches[1]);
492
+                    $originalData = $this->removeAngleBrackets($originalData);
493
+                    $string       = str_replace($d, $originalData, $string);
494 494
                 }
495 495
             }
496 496
         }
@@ -503,8 +503,8 @@  discard block
 block discarded – undo
503 503
      *
504 504
      * @return string
505 505
      */
506
-    private function removeAngleBrackets( $string ) {
507
-        return str_replace( [ '<', '>', '&lt;', '&gt;' ], '', $string );
506
+    private function removeAngleBrackets($string) {
507
+        return str_replace(['<', '>', '&lt;', '&gt;'], '', $string);
508 508
     }
509 509
 
510 510
     /**
@@ -514,8 +514,8 @@  discard block
 block discarded – undo
514 514
      *
515 515
      * @return bool
516 516
      */
517
-    private function isAEcOrScTag( $node ) {
518
-        return ( $node->tagName === 'ec' || $node->tagName === 'sc' );
517
+    private function isAEcOrScTag($node) {
518
+        return ($node->tagName === 'ec' || $node->tagName === 'sc');
519 519
     }
520 520
 
521 521
     /**
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
      *
527 527
      * @return bool
528 528
      */
529
-    private function wasAEcOrScTag( $node ) {
530
-        return ( isset( $node->attributes[ 'dataType' ] ) && ( $node->attributes[ 'dataType' ] === 'ec' || $node->attributes[ 'dataType' ] === 'sc' ) );
529
+    private function wasAEcOrScTag($node) {
530
+        return (isset($node->attributes['dataType']) && ($node->attributes['dataType'] === 'ec' || $node->attributes['dataType'] === 'sc'));
531 531
     }
532 532
 }
533 533
\ No newline at end of file
Please login to merge, or discard this patch.
src/Commons/AbstractHandler.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -28,13 +28,13 @@  discard block
 block discarded – undo
28 28
      *
29 29
      * @throws Exception
30 30
      */
31
-    public abstract function transform( $segment );
31
+    public abstract function transform($segment);
32 32
 
33 33
     /**
34 34
      * AbstractHandler constructor.
35 35
      */
36 36
     public function __construct() {
37
-        $this->name = get_class( $this );
37
+        $this->name = get_class($this);
38 38
     }
39 39
 
40 40
     /**
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
     /**
48 48
      * @param Pipeline $pipeline
49 49
      */
50
-    public function setPipeline( Pipeline $pipeline ) {
50
+    public function setPipeline(Pipeline $pipeline) {
51 51
         $this->pipeline = $pipeline;
52 52
     }
53 53
 
Please login to merge, or discard this patch.
src/Commons/Pipeline.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      */
33 33
     private $segmentContainsHtml = false;
34 34
 
35
-    public function __construct( $source = null, $target = null, $dataRefMap = [] ) {
35
+    public function __construct($source = null, $target = null, $dataRefMap = []) {
36 36
         $this->source     = $source;
37 37
         $this->target     = $target;
38 38
         $this->dataRefMap = $dataRefMap;
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     public function getNextId() {
42 42
         $this->id_number++;
43 43
 
44
-        return ConstantEnum::INTERNAL_ATTR_ID_PREFIX . $this->id_number;
44
+        return ConstantEnum::INTERNAL_ATTR_ID_PREFIX.$this->id_number;
45 45
     }
46 46
 
47 47
     public function resetId() {
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
      *
87 87
      * @return Pipeline
88 88
      */
89
-    public function addFirst( AbstractHandler $handler ) {
90
-        $this->_register( $handler );
91
-        array_unshift( $this->handlers, $handler );
89
+    public function addFirst(AbstractHandler $handler) {
90
+        $this->_register($handler);
91
+        array_unshift($this->handlers, $handler);
92 92
 
93 93
         return $this;
94 94
     }
@@ -99,11 +99,11 @@  discard block
 block discarded – undo
99 99
      *
100 100
      * @return Pipeline
101 101
      */
102
-    public function addBefore( AbstractHandler $before, AbstractHandler $newPipeline ) {
103
-        $this->_register( $newPipeline );
104
-        foreach ( $this->handlers as $pos => $handler ) {
105
-            if ( $handler->getName() == $before->getName() ) {
106
-                array_splice( $this->handlers, $pos, 0, [ $newPipeline ] );
102
+    public function addBefore(AbstractHandler $before, AbstractHandler $newPipeline) {
103
+        $this->_register($newPipeline);
104
+        foreach ($this->handlers as $pos => $handler) {
105
+            if ($handler->getName() == $before->getName()) {
106
+                array_splice($this->handlers, $pos, 0, [$newPipeline]);
107 107
                 break;
108 108
             }
109 109
         }
@@ -118,11 +118,11 @@  discard block
 block discarded – undo
118 118
      *
119 119
      * @return Pipeline
120 120
      */
121
-    public function addAfter( AbstractHandler $after, AbstractHandler $newPipeline ) {
122
-        $this->_register( $newPipeline );
123
-        foreach ( $this->handlers as $pos => $handler ) {
124
-            if ( $handler->getName() == $after->getName() ) {
125
-                array_splice( $this->handlers, $pos + 1, 0, [ $newPipeline ] );
121
+    public function addAfter(AbstractHandler $after, AbstractHandler $newPipeline) {
122
+        $this->_register($newPipeline);
123
+        foreach ($this->handlers as $pos => $handler) {
124
+            if ($handler->getName() == $after->getName()) {
125
+                array_splice($this->handlers, $pos + 1, 0, [$newPipeline]);
126 126
                 break;
127 127
             }
128 128
         }
@@ -138,10 +138,10 @@  discard block
 block discarded – undo
138 138
      *
139 139
      * @return $this
140 140
      */
141
-    public function remove( AbstractHandler $handlerToDelete ) {
142
-        foreach ( $this->handlers as $pos => $handler ) {
143
-            if ( $handler->getName() == $handlerToDelete->getName() ) {
144
-                unset( $this->handlers[ $pos ] );
141
+    public function remove(AbstractHandler $handlerToDelete) {
142
+        foreach ($this->handlers as $pos => $handler) {
143
+            if ($handler->getName() == $handlerToDelete->getName()) {
144
+                unset($this->handlers[$pos]);
145 145
                 break;
146 146
             }
147 147
         }
@@ -154,8 +154,8 @@  discard block
 block discarded – undo
154 154
      *
155 155
      * @return Pipeline
156 156
      */
157
-    public function addLast( AbstractHandler $handler ) {
158
-        $this->_register( $handler );
157
+    public function addLast(AbstractHandler $handler) {
158
+        $this->_register($handler);
159 159
         $this->handlers[] = $handler;
160 160
 
161 161
         return $this;
@@ -166,21 +166,21 @@  discard block
 block discarded – undo
166 166
      *
167 167
      * @return mixed
168 168
      */
169
-    public function transform( $segment ) {
169
+    public function transform($segment) {
170 170
         $this->id_number = -1;
171
-        foreach ( $this->handlers as $handler ) {
172
-            $segment = $handler->transform( $segment );
171
+        foreach ($this->handlers as $handler) {
172
+            $segment = $handler->transform($segment);
173 173
         }
174 174
 
175
-        return $this->realignIDs( $segment );
175
+        return $this->realignIDs($segment);
176 176
     }
177 177
 
178
-    protected function realignIDs( $segment ) {
179
-        if ( $this->id_number > -1 ) {
180
-            preg_match_all( '/"__mtc_[0-9]+"/', $segment, $html, PREG_SET_ORDER );
181
-            foreach ( $html as $pos => $tag_id ) {
178
+    protected function realignIDs($segment) {
179
+        if ($this->id_number > -1) {
180
+            preg_match_all('/"__mtc_[0-9]+"/', $segment, $html, PREG_SET_ORDER);
181
+            foreach ($html as $pos => $tag_id) {
182 182
                 //replace subsequent elements excluding already encoded
183
-                $segment = preg_replace( '/' . $tag_id[ 0 ] . '/', '"mtc_' . ( $pos + 1 ) . '"', $segment, 1 );
183
+                $segment = preg_replace('/'.$tag_id[0].'/', '"mtc_'.($pos + 1).'"', $segment, 1);
184 184
             }
185 185
         }
186 186
 
@@ -192,8 +192,8 @@  discard block
 block discarded – undo
192 192
      *
193 193
      * @return $this
194 194
      */
195
-    protected function _register( AbstractHandler $handler ) {
196
-        $handler->setPipeline( $this );
195
+    protected function _register(AbstractHandler $handler) {
196
+        $handler->setPipeline($this);
197 197
 
198 198
         return $this;
199 199
     }
Please login to merge, or discard this patch.
src/Filters/SmartCounts.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -11,17 +11,17 @@
 block discarded – undo
11 11
      *
12 12
      * @return string
13 13
      */
14
-    public function transform( $segment ) {
14
+    public function transform($segment) {
15 15
         /*
16 16
          * Examples:
17 17
          * - [AIRBNB] Reminder: Reply to %{guest}’s inquiry. |||| [AIRBNB] Reminder: Reply to %{guest}’s inquiry.
18 18
          */
19
-        preg_match_all( '/(\|\|\|\|)/', $segment, $html, PREG_SET_ORDER );
20
-        foreach ( $html as $pos => $variable ) {
19
+        preg_match_all('/(\|\|\|\|)/', $segment, $html, PREG_SET_ORDER);
20
+        foreach ($html as $pos => $variable) {
21 21
             //replace subsequent elements excluding already encoded
22 22
             $segment = preg_replace(
23
-                    '/' . preg_quote( $variable[ 0 ], '/' ) . '/',
24
-                    '<ph id="' . $this->getPipeline()->getNextId() . '" ctype="' . CTypeEnum::SMART_COUNT . '" equiv-text="base64:' . base64_encode( $variable[ 0 ] ) . "\"/>",
23
+                    '/'.preg_quote($variable[0], '/').'/',
24
+                    '<ph id="'.$this->getPipeline()->getNextId().'" ctype="'.CTypeEnum::SMART_COUNT.'" equiv-text="base64:'.base64_encode($variable[0])."\"/>",
25 25
                     $segment,
26 26
                     1
27 27
             );
Please login to merge, or discard this patch.
src/Filters/TwigToPh.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -32,15 +32,15 @@
 block discarded – undo
32 32
      *
33 33
      * @return string
34 34
      */
35
-    public function transform( $segment ) {
36
-        preg_match_all( '/{{[^<>]+?}}|{%[^<>]+?%}|{#[^<>]+?#}/', $segment, $html, PREG_SET_ORDER );
37
-        foreach ( $html as $pos => $twig_variable ) {
35
+    public function transform($segment) {
36
+        preg_match_all('/{{[^<>]+?}}|{%[^<>]+?%}|{#[^<>]+?#}/', $segment, $html, PREG_SET_ORDER);
37
+        foreach ($html as $pos => $twig_variable) {
38 38
             //check if inside twig variable there is a tag because in this case shouldn't replace the content with PH tag
39
-            if ( !strstr( $twig_variable[ 0 ], ConstantEnum::GTPLACEHOLDER ) ) {
39
+            if (!strstr($twig_variable[0], ConstantEnum::GTPLACEHOLDER)) {
40 40
                 //replace subsequent elements excluding already encoded
41 41
                 $segment = preg_replace(
42
-                        '/' . preg_quote( $twig_variable[ 0 ], '/' ) . '/',
43
-                        '<ph id="' . $this->getPipeline()->getNextId() . '" ctype="' . CTypeEnum::TWIG . '" equiv-text="base64:' . base64_encode( $twig_variable[ 0 ] ) . '"/>',
42
+                        '/'.preg_quote($twig_variable[0], '/').'/',
43
+                        '<ph id="'.$this->getPipeline()->getNextId().'" ctype="'.CTypeEnum::TWIG.'" equiv-text="base64:'.base64_encode($twig_variable[0]).'"/>',
44 44
                         $segment,
45 45
                         1
46 46
                 );
Please login to merge, or discard this patch.
src/Filters/DataRefRestore.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -23,23 +23,23 @@  discard block
 block discarded – undo
23 23
     /**
24 24
      * @inheritDoc
25 25
      */
26
-    public function transform( $segment ) {
26
+    public function transform($segment) {
27 27
 
28
-        if ( empty( $this->dataRefMap ) ) {
28
+        if (empty($this->dataRefMap)) {
29 29
             $this->dataRefMap = $this->pipeline->getDataRefMap();
30 30
         }
31 31
 
32
-        if ( empty( $this->dataRefMap ) ) {
33
-            $segment = $this->restoreXliffPhTagsFromMatecatPhTags( $segment );
32
+        if (empty($this->dataRefMap)) {
33
+            $segment = $this->restoreXliffPhTagsFromMatecatPhTags($segment);
34 34
 
35
-            return $this->restoreXliffPcTagsFromMatecatPhTags( $segment );
35
+            return $this->restoreXliffPcTagsFromMatecatPhTags($segment);
36 36
         }
37 37
 
38
-        $dataRefReplacer = new DataRefReplacer( $this->dataRefMap );
39
-        $segment         = $dataRefReplacer->restore( $segment );
40
-        $segment         = $this->restoreXliffPhTagsFromMatecatPhTags( $segment );
38
+        $dataRefReplacer = new DataRefReplacer($this->dataRefMap);
39
+        $segment         = $dataRefReplacer->restore($segment);
40
+        $segment         = $this->restoreXliffPhTagsFromMatecatPhTags($segment);
41 41
 
42
-        return $this->restoreXliffPcTagsFromMatecatPhTags( $segment );
42
+        return $this->restoreXliffPcTagsFromMatecatPhTags($segment);
43 43
     }
44 44
 
45 45
     /**
@@ -58,15 +58,15 @@  discard block
 block discarded – undo
58 58
      *
59 59
      * @return string
60 60
      */
61
-    private function restoreXliffPhTagsFromMatecatPhTags( $segment ) {
62
-        preg_match_all( '|<ph id="mtc_[0-9]+" ctype="' . CTypeEnum::ORIGINAL_PH . '" x-layer="data-ref" equiv-text="base64:(.*?)"/>|iu', $segment, $matches );
61
+    private function restoreXliffPhTagsFromMatecatPhTags($segment) {
62
+        preg_match_all('|<ph id="mtc_[0-9]+" ctype="'.CTypeEnum::ORIGINAL_PH.'" x-layer="data-ref" equiv-text="base64:(.*?)"/>|iu', $segment, $matches);
63 63
 
64
-        if ( empty( $matches[ 0 ] ) ) {
64
+        if (empty($matches[0])) {
65 65
             return $segment;
66 66
         }
67 67
 
68
-        foreach ( $matches[ 0 ] as $index => $match ) {
69
-            $segment = str_replace( $match, base64_decode( $matches[ 1 ][ $index ] ), $segment );
68
+        foreach ($matches[0] as $index => $match) {
69
+            $segment = str_replace($match, base64_decode($matches[1][$index]), $segment);
70 70
         }
71 71
 
72 72
         return $segment;
@@ -88,16 +88,16 @@  discard block
 block discarded – undo
88 88
      *
89 89
      * @return string
90 90
      */
91
-    private function restoreXliffPcTagsFromMatecatPhTags( $segment ) {
92
-        preg_match_all( '|<ph id="mtc_[0-9]+" ctype="' . CTypeEnum::ORIGINAL_PC_OPEN . '" x-layer="data-ref" equiv-text="base64:(.*?)"/>|iu', $segment, $matches );
93
-        preg_match_all( '|<ph id="mtc_[0-9]+" ctype="' . CTypeEnum::ORIGINAL_PC_CLOSE . '" x-layer="data-ref" equiv-text="base64:(.*?)"/>|iu', $segment, $matches );
91
+    private function restoreXliffPcTagsFromMatecatPhTags($segment) {
92
+        preg_match_all('|<ph id="mtc_[0-9]+" ctype="'.CTypeEnum::ORIGINAL_PC_OPEN.'" x-layer="data-ref" equiv-text="base64:(.*?)"/>|iu', $segment, $matches);
93
+        preg_match_all('|<ph id="mtc_[0-9]+" ctype="'.CTypeEnum::ORIGINAL_PC_CLOSE.'" x-layer="data-ref" equiv-text="base64:(.*?)"/>|iu', $segment, $matches);
94 94
 
95
-        if ( empty( $matches[ 0 ] ) ) {
95
+        if (empty($matches[0])) {
96 96
             return $segment;
97 97
         }
98 98
 
99
-        foreach ( $matches[ 0 ] as $index => $match ) {
100
-            $segment = str_replace( $match, base64_decode( $matches[ 1 ][ $index ] ), $segment );
99
+        foreach ($matches[0] as $index => $match) {
100
+            $segment = str_replace($match, base64_decode($matches[1][$index]), $segment);
101 101
         }
102 102
 
103 103
         return $segment;
Please login to merge, or discard this patch.
src/Filters/Variables.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
      *
13 13
      * @return string
14 14
      */
15
-    public function transform( $segment ) {
15
+    public function transform($segment) {
16 16
         /*
17 17
          * Examples:
18 18
          * - %{# }
@@ -22,12 +22,12 @@  discard block
 block discarded – undo
22 22
          * - [AIRBNB] Reminder: Reply to %{guest}’s inquiry. |||| [AIRBNB] Reminder: Reply to %{guest}’s inquiry.
23 23
          */
24 24
 //        preg_match_all( '/%{{[^}]*?}}|(%{[^}]*?})[^\|]+?\1|(%{[^}]*?})/', $segment, $html, PREG_SET_ORDER );
25
-        preg_match_all( '/%{{(?!<ph )[^}]*?}}|(%{(?!<ph )[^}]*?})/', $segment, $html, PREG_SET_ORDER );
26
-        foreach ( $html as $pos => $variable ) {
25
+        preg_match_all('/%{{(?!<ph )[^}]*?}}|(%{(?!<ph )[^}]*?})/', $segment, $html, PREG_SET_ORDER);
26
+        foreach ($html as $pos => $variable) {
27 27
             //replace subsequent elements excluding already encoded
28 28
             $segment = preg_replace(
29
-                    '/' . preg_quote( $variable[ 0 ], '/' ) . '/',
30
-                    '<ph id="' . $this->getPipeline()->getNextId() . '" ctype="' . CTypeEnum::PERCENT_VARIABLE . '" equiv-text="base64:' . base64_encode( $variable[ 0 ] ) . "\"/>",
29
+                    '/'.preg_quote($variable[0], '/').'/',
30
+                    '<ph id="'.$this->getPipeline()->getNextId().'" ctype="'.CTypeEnum::PERCENT_VARIABLE.'" equiv-text="base64:'.base64_encode($variable[0])."\"/>",
31 31
                     $segment,
32 32
                     1
33 33
             );
Please login to merge, or discard this patch.
src/Filters/StandardPHToMateCatCustomPH.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -14,10 +14,10 @@  discard block
 block discarded – undo
14 14
 
15 15
 class StandardPHToMateCatCustomPH extends AbstractHandler {
16 16
 
17
-    public function transform( $segment ) {
17
+    public function transform($segment) {
18 18
 
19
-        $segment = $this->filterPhTagContent( $segment );
20
-        $segment = $this->filterOriginalPhTagsWithEquivText( $segment );
19
+        $segment = $this->filterPhTagContent($segment);
20
+        $segment = $this->filterOriginalPhTagsWithEquivText($segment);
21 21
 
22 22
         return $segment;
23 23
 
@@ -28,15 +28,15 @@  discard block
 block discarded – undo
28 28
      *
29 29
      * @return string
30 30
      */
31
-    private function filterPhTagContent( $segment ) {
31
+    private function filterPhTagContent($segment) {
32 32
 
33
-        if ( preg_match( '|</ph>|s', $segment ) ) {
34
-            preg_match_all( '|<ph id=["\']([^\'"]+?)["\'].*?>(.*?)</ph>|', $segment, $phTags, PREG_SET_ORDER );
35
-            foreach ( $phTags as $group ) {
33
+        if (preg_match('|</ph>|s', $segment)) {
34
+            preg_match_all('|<ph id=["\']([^\'"]+?)["\'].*?>(.*?)</ph>|', $segment, $phTags, PREG_SET_ORDER);
35
+            foreach ($phTags as $group) {
36 36
                 $segment = preg_replace(
37
-                        '/' . preg_quote( $group[ 0 ], '/' ) . '/',
38
-                        '<ph id="' . $this->getPipeline()->getNextId() . '" ctype="' . CTypeEnum::ORIGINAL_PH_CONTENT . '" x-orig="' . base64_encode( $group[ 0 ] ) . '" equiv-text="base64:' .
39
-                        base64_encode( htmlentities( $group[ 2 ], ENT_NOQUOTES | 16 /* ENT_XML1 */, 'UTF-8' ) ) .
37
+                        '/'.preg_quote($group[0], '/').'/',
38
+                        '<ph id="'.$this->getPipeline()->getNextId().'" ctype="'.CTypeEnum::ORIGINAL_PH_CONTENT.'" x-orig="'.base64_encode($group[0]).'" equiv-text="base64:'.
39
+                        base64_encode(htmlentities($group[2], ENT_NOQUOTES | 16 /* ENT_XML1 */, 'UTF-8')).
40 40
                         '"/>',
41 41
                         $segment,
42 42
                         1
@@ -55,16 +55,16 @@  discard block
 block discarded – undo
55 55
      *
56 56
      * @return string
57 57
      */
58
-    private function filterOriginalPhTagsWithEquivText( $segment ) {
58
+    private function filterOriginalPhTagsWithEquivText($segment) {
59 59
 
60
-        preg_match_all( '|<ph id\s*=\s*[\'"]((?!__mtc_)[^\'"]+)[\'"] equiv-text\s*?=\s*?(["\'])(?!base64:)([^\'"]+?)\2\s*/>|', $segment, $html, PREG_SET_ORDER );
61
-        foreach ( $html as $tag_attribute ) {
60
+        preg_match_all('|<ph id\s*=\s*[\'"]((?!__mtc_)[^\'"]+)[\'"] equiv-text\s*?=\s*?(["\'])(?!base64:)([^\'"]+?)\2\s*/>|', $segment, $html, PREG_SET_ORDER);
61
+        foreach ($html as $tag_attribute) {
62 62
 
63 63
             //replace subsequent elements excluding already encoded
64 64
             $segment = preg_replace(
65
-                    '/' . preg_quote( $tag_attribute[ 0 ], '/' ) . '/',
66
-                    '<ph id="' . $this->getPipeline()->getNextId() . '" ctype="' . CTypeEnum::ORIGINAL_PH . '" x-orig="' . base64_encode( $tag_attribute[ 0 ] ) . '" equiv-text="base64:' .
67
-                    base64_encode( $tag_attribute[ 3 ] ) .
65
+                    '/'.preg_quote($tag_attribute[0], '/').'/',
66
+                    '<ph id="'.$this->getPipeline()->getNextId().'" ctype="'.CTypeEnum::ORIGINAL_PH.'" x-orig="'.base64_encode($tag_attribute[0]).'" equiv-text="base64:'.
67
+                    base64_encode($tag_attribute[3]).
68 68
                     '"/>',
69 69
                     $segment,
70 70
                     1
Please login to merge, or discard this patch.