Passed
Branch master (41e2a6)
by Domenico
02:28
created
src/Utils/Map.php 1 patch
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
      */
26 26
     private $map;
27 27
 
28
-    public function __construct( array $map ) {
28
+    public function __construct(array $map) {
29 29
         $this->map = $map;
30 30
     }
31 31
 
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      * @return ArrayIterator
34 34
      */
35 35
     public function getIterator() {
36
-        return new ArrayIterator( $this->map );
36
+        return new ArrayIterator($this->map);
37 37
     }
38 38
 
39 39
     /**
@@ -41,8 +41,8 @@  discard block
 block discarded – undo
41 41
      *
42 42
      * @return bool
43 43
      */
44
-    public function offsetExists( $offset ) {
45
-        return array_key_exists( $offset, $this->map );
44
+    public function offsetExists($offset) {
45
+        return array_key_exists($offset, $this->map);
46 46
     }
47 47
 
48 48
     /**
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
      *
51 51
      * @return mixed|null
52 52
      */
53
-    public function offsetGet( $offset ) {
54
-        return $this->get( $offset );
53
+    public function offsetGet($offset) {
54
+        return $this->get($offset);
55 55
     }
56 56
 
57 57
     /**
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
      *
61 61
      * @return void
62 62
      */
63
-    public function offsetSet( $offset, $value ) {
64
-        $this->put( $offset, $value );
63
+    public function offsetSet($offset, $value) {
64
+        $this->put($offset, $value);
65 65
     }
66 66
 
67 67
     /**
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
      *
70 70
      * @return void
71 71
      */
72
-    public function offsetUnset( $offset ) {
73
-        $this->remove( $offset );
72
+    public function offsetUnset($offset) {
73
+        $this->remove($offset);
74 74
     }
75 75
 
76 76
 
@@ -78,13 +78,13 @@  discard block
 block discarded – undo
78 78
      * @return Generator
79 79
      */
80 80
     public function entrySet() {
81
-        foreach ( $this->map as $k => $v ) {
82
-            yield [ $k, $v ];
81
+        foreach ($this->map as $k => $v) {
82
+            yield [$k, $v];
83 83
         }
84 84
     }
85 85
 
86
-    public static function instance( array $map = [] ) {
87
-        return new static( $map );
86
+    public static function instance(array $map = []) {
87
+        return new static($map);
88 88
     }
89 89
 
90 90
     /**
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
      *
95 95
      * @return mixed|null
96 96
      */
97
-    public function get( $needle ) {
98
-        return $this->getOrDefault( $needle, null );
97
+    public function get($needle) {
98
+        return $this->getOrDefault($needle, null);
99 99
     }
100 100
 
101 101
     /**
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
      *
105 105
      * @return mixed
106 106
      */
107
-    public function getOrDefault( $needle, $default ) {
108
-        return array_key_exists( $needle, $this->map ) ? $this->map [ $needle ] : $default;
107
+    public function getOrDefault($needle, $default) {
108
+        return array_key_exists($needle, $this->map) ? $this->map [$needle] : $default;
109 109
     }
110 110
 
111 111
     /**
@@ -121,11 +121,11 @@  discard block
 block discarded – undo
121 121
      * @return $this
122 122
      */
123 123
     public function __clone() {
124
-        return new static( $this->map );
124
+        return new static($this->map);
125 125
     }
126 126
 
127
-    public function containsKey( $key ) {
128
-        return array_key_exists( $key, $this->map );
127
+    public function containsKey($key) {
128
+        return array_key_exists($key, $this->map);
129 129
     }
130 130
 
131 131
     /**
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
      *
137 137
      * @return false|string
138 138
      */
139
-    public function containsValue( $value ) {
140
-        return array_search( $value, $this->map, true );
139
+    public function containsValue($value) {
140
+        return array_search($value, $this->map, true);
141 141
     }
142 142
 
143 143
     /**
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
      *
149 149
      * @return Generator
150 150
      */
151
-    public function foreEach( callable $callable ) {
152
-        foreach ( $this->map as $k => $v ) {
153
-            yield $callable( $k, $v );
151
+    public function foreEach(callable $callable) {
152
+        foreach ($this->map as $k => $v) {
153
+            yield $callable($k, $v);
154 154
         }
155 155
     }
156 156
 
@@ -160,14 +160,14 @@  discard block
 block discarded – undo
160 160
      * @return bool
161 161
      */
162 162
     public function isEmpty() {
163
-        return empty( $this->map );
163
+        return empty($this->map);
164 164
     }
165 165
 
166 166
     /**
167 167
      * @return Map
168 168
      */
169 169
     public function keySet() {
170
-        return static::instance( array_keys( $this->map ) );
170
+        return static::instance(array_keys($this->map));
171 171
     }
172 172
 
173 173
     /**
@@ -178,9 +178,9 @@  discard block
 block discarded – undo
178 178
      *
179 179
      * @return mixed|null the previous value associated with `key`, or null if there was no mapping for `key`.
180 180
      */
181
-    public function put( $key, $value ) {
182
-        $previousValue     = $this->get( $key );
183
-        $this->map[ $key ] = $value;
181
+    public function put($key, $value) {
182
+        $previousValue     = $this->get($key);
183
+        $this->map[$key] = $value;
184 184
 
185 185
         return $previousValue;
186 186
     }
@@ -190,9 +190,9 @@  discard block
 block discarded – undo
190 190
      *
191 191
      * @return void
192 192
      */
193
-    public function putAll( $map ) {
194
-        foreach ( $map as $k => $v ) {
195
-            $this->map[ $k ] = $v;
193
+    public function putAll($map) {
194
+        foreach ($map as $k => $v) {
195
+            $this->map[$k] = $v;
196 196
         }
197 197
     }
198 198
 
@@ -205,10 +205,10 @@  discard block
 block discarded – undo
205 205
      * @return mixed|null the previous value associated with the specified key, or null if there was no mapping for the key.
206 206
      *               A null return can also indicate that the map previously associated null with the `key`
207 207
      */
208
-    public function putIfAbsent( $key, $value ) {
209
-        $previousValue = $this->get( $key );
210
-        if ( $previousValue === null ) {
211
-            $this->map[ $key ] = $value;
208
+    public function putIfAbsent($key, $value) {
209
+        $previousValue = $this->get($key);
210
+        if ($previousValue === null) {
211
+            $this->map[$key] = $value;
212 212
         }
213 213
 
214 214
         return $previousValue;
@@ -221,10 +221,10 @@  discard block
 block discarded – undo
221 221
      *
222 222
      * @return bool true if the value was removed
223 223
      */
224
-    public function remove( $key ) {
225
-        $exists = array_key_exists( $key, $this->map );
226
-        if ( $exists ) {
227
-            unset( $this->map[ $key ] );
224
+    public function remove($key) {
225
+        $exists = array_key_exists($key, $this->map);
226
+        if ($exists) {
227
+            unset($this->map[$key]);
228 228
         }
229 229
 
230 230
         return $exists;
@@ -236,11 +236,11 @@  discard block
 block discarded – undo
236 236
      * @return mixed|null the previous value associated with the specified key, or null if there was no mapping for the key.
237 237
      *                      A null return can also indicate that the map previously associated null with the key.
238 238
      */
239
-    public function replace( $key, $value ) {
240
-        $exists        = array_key_exists( $key, $this->map );
241
-        $previousValue = $this->get( $key );
242
-        if ( $exists ) {
243
-            $this->map[ $key ] = $value;
239
+    public function replace($key, $value) {
240
+        $exists        = array_key_exists($key, $this->map);
241
+        $previousValue = $this->get($key);
242
+        if ($exists) {
243
+            $this->map[$key] = $value;
244 244
         }
245 245
 
246 246
         return $previousValue;
@@ -255,11 +255,11 @@  discard block
 block discarded – undo
255 255
      *
256 256
      * @return boolean true if the value was replaced
257 257
      */
258
-    public function replaceIfEquals( $key, $newValue, $oldValue ) {
259
-        $exists        = array_key_exists( $key, $this->map );
260
-        $previousValue = $this->get( $key );
261
-        if ( $exists && $previousValue === $oldValue ) {
262
-            $this->map[ $key ] = $newValue;
258
+    public function replaceIfEquals($key, $newValue, $oldValue) {
259
+        $exists        = array_key_exists($key, $this->map);
260
+        $previousValue = $this->get($key);
261
+        if ($exists && $previousValue === $oldValue) {
262
+            $this->map[$key] = $newValue;
263 263
 
264 264
             return true;
265 265
         }
@@ -276,9 +276,9 @@  discard block
 block discarded – undo
276 276
      *
277 277
      * @return void
278 278
      */
279
-    public function replaceAll( callable $callable ) {
280
-        foreach ( $this->map as $key => $value ) {
281
-            $this->map[ $key ] = $callable( $key, $value );
279
+    public function replaceAll(callable $callable) {
280
+        foreach ($this->map as $key => $value) {
281
+            $this->map[$key] = $callable($key, $value);
282 282
         }
283 283
     }
284 284
 
@@ -286,14 +286,14 @@  discard block
 block discarded – undo
286 286
      * @return int
287 287
      */
288 288
     public function size() {
289
-        return sizeof( $this->map );
289
+        return sizeof($this->map);
290 290
     }
291 291
 
292 292
     /**
293 293
      * @return Map
294 294
      */
295 295
     public function values() {
296
-        return new static( array_values( $this->map ) );
296
+        return new static(array_values($this->map));
297 297
     }
298 298
 
299 299
     /**
@@ -312,14 +312,14 @@  discard block
 block discarded – undo
312 312
      *
313 313
      * @return mixed|null the new value associated with the specified key, or null if none
314 314
      */
315
-    public function compute( $key, callable $callable ) {
316
-        $exists = array_key_exists( $key, $this->map );
317
-        if ( $exists ) {
318
-            $res = $callable( $key, $this->get( $key ) );
319
-            if ( $res == null ) {
320
-                unset( $this->map[ $key ] );
315
+    public function compute($key, callable $callable) {
316
+        $exists = array_key_exists($key, $this->map);
317
+        if ($exists) {
318
+            $res = $callable($key, $this->get($key));
319
+            if ($res == null) {
320
+                unset($this->map[$key]);
321 321
             } else {
322
-                $this->map[ $key ] = $callable( $key, $this->get( $key ) );
322
+                $this->map[$key] = $callable($key, $this->get($key));
323 323
             }
324 324
         }
325 325
 
@@ -340,14 +340,14 @@  discard block
 block discarded – undo
340 340
      *
341 341
      * @return mixed|null the current (existing or computed) value associated with the specified key, or null if the computed value is null
342 342
      */
343
-    public function computeIfAbsent( $key, callable $callable ) {
344
-        $exists        = array_key_exists( $key, $this->map );
345
-        $previousValue = $this->get( $key );
343
+    public function computeIfAbsent($key, callable $callable) {
344
+        $exists        = array_key_exists($key, $this->map);
345
+        $previousValue = $this->get($key);
346 346
         $res           = null;
347
-        if ( !$exists || $previousValue !== null ) {
348
-            $res = $callable( $key, $this->get( $key ) );
349
-            if ( $res != null ) {
350
-                $this->map[ $key ] = $res;
347
+        if (!$exists || $previousValue !== null) {
348
+            $res = $callable($key, $this->get($key));
349
+            if ($res != null) {
350
+                $this->map[$key] = $res;
351 351
             }
352 352
 
353 353
         }
@@ -367,16 +367,16 @@  discard block
 block discarded – undo
367 367
      *
368 368
      * @return mixed|null the new value associated with the specified key, or null if none
369 369
      */
370
-    public function computeIfPresent( $key, callable $callable ) {
371
-        $exists        = array_key_exists( $key, $this->map );
372
-        $previousValue = $this->get( $key );
370
+    public function computeIfPresent($key, callable $callable) {
371
+        $exists        = array_key_exists($key, $this->map);
372
+        $previousValue = $this->get($key);
373 373
         $res           = null;
374
-        if ( $exists && $previousValue !== null ) {
375
-            $res = $callable( $key, $this->map[ $key ] );
376
-            if ( $res == null ) {
377
-                unset( $this->map[ $key ] );
374
+        if ($exists && $previousValue !== null) {
375
+            $res = $callable($key, $this->map[$key]);
376
+            if ($res == null) {
377
+                unset($this->map[$key]);
378 378
             } else {
379
-                $this->map[ $key ] = $res;
379
+                $this->map[$key] = $res;
380 380
             }
381 381
         }
382 382
 
Please login to merge, or discard this patch.
src/Utils/DataRefReplacer.php 1 patch
Spacing   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -27,8 +27,8 @@  discard block
 block discarded – undo
27 27
      *
28 28
      * @param array $map
29 29
      */
30
-    public function __construct( array $map = [] ) {
31
-        $this->map = Map::instance( $this->sanitizeMap( $map ) );
30
+    public function __construct(array $map = []) {
31
+        $this->map = Map::instance($this->sanitizeMap($map));
32 32
     }
33 33
 
34 34
     /**
@@ -42,42 +42,42 @@  discard block
 block discarded – undo
42 42
      *
43 43
      * @return string
44 44
      */
45
-    public function replace( $string ) {
45
+    public function replace($string) {
46 46
 
47 47
         // if the map is empty
48 48
         // or the string has not a dataRef attribute
49 49
         // return string as is
50
-        if ( $this->map->isEmpty() || !$this->hasAnyDataRefAttribute( $string ) ) {
50
+        if ($this->map->isEmpty() || !$this->hasAnyDataRefAttribute($string)) {
51 51
             return $string;
52 52
         }
53 53
 
54 54
         // try not to throw exception for wrong segments with opening tags and no closing
55 55
         try {
56 56
 
57
-            $html = XmlParser::parse( $string, true );
57
+            $html = XmlParser::parse($string, true);
58 58
 
59 59
             $dataRefEndMap = new ArrayList();
60 60
 
61
-            foreach ( $html as $node ) {
61
+            foreach ($html as $node) {
62 62
 
63 63
                 // 1. Replace <ph>|<sc>|<ec> tags
64
-                $string = $this->recursiveTransformDataRefToPhTag( $node, $string );
64
+                $string = $this->recursiveTransformDataRefToPhTag($node, $string);
65 65
 
66 66
                 // 2. Replace self-closed <pc dataRefStart="xyz" /> tags
67
-                $string = $this->recursiveReplaceSelfClosedPcTags( $node, $string );
67
+                $string = $this->recursiveReplaceSelfClosedPcTags($node, $string);
68 68
 
69 69
                 // 3. Build the DataRefEndMap needed by replaceClosingPcTags function
70 70
                 // (needed for correct handling of </pc> closing tags)
71 71
                 // make this inline with one foreach cycle
72
-                $this->extractDataRefMapRecursively( $node, $dataRefEndMap );
72
+                $this->extractDataRefMapRecursively($node, $dataRefEndMap);
73 73
 
74 74
             }
75 75
 
76 76
             // 4. replace pc tags
77
-            $string = $this->replaceOpeningPcTags( $string );
78
-            $string = $this->replaceClosingPcTags( $string, $dataRefEndMap );
77
+            $string = $this->replaceOpeningPcTags($string);
78
+            $string = $this->replaceClosingPcTags($string, $dataRefEndMap);
79 79
 
80
-        } catch ( Exception $ignore ) {
80
+        } catch (Exception $ignore) {
81 81
             // if something fails here, do not throw exception and return the original string instead
82 82
 //            var_dump( $ignore );
83 83
         } finally {
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
      *
92 92
      * @return bool
93 93
      */
94
-    private function hasAnyDataRefAttribute( $string ) {
95
-        return (bool)preg_match( '/(dataRef|dataRefStart|dataRefEnd)=[\'"].*?[\'"]/', $string );
94
+    private function hasAnyDataRefAttribute($string) {
95
+        return (bool) preg_match('/(dataRef|dataRefStart|dataRefEnd)=[\'"].*?[\'"]/', $string);
96 96
     }
97 97
 
98 98
     /**
@@ -108,18 +108,18 @@  discard block
 block discarded – undo
108 108
      *
109 109
      * @return string
110 110
      */
111
-    private function recursiveTransformDataRefToPhTag( $node, $string ) {
111
+    private function recursiveTransformDataRefToPhTag($node, $string) {
112 112
 
113
-        if ( $node->has_children ) {
113
+        if ($node->has_children) {
114 114
 
115
-            foreach ( $node->inner_html as $childNode ) {
116
-                $string = $this->recursiveTransformDataRefToPhTag( $childNode, $string );
115
+            foreach ($node->inner_html as $childNode) {
116
+                $string = $this->recursiveTransformDataRefToPhTag($childNode, $string);
117 117
             }
118 118
 
119 119
         } else {
120 120
 
121 121
             // accept only those tags
122
-            switch ( $node->tagName ) {
122
+            switch ($node->tagName) {
123 123
                 case 'ph':
124 124
                     $ctype = CTypeEnum::PH_DATA_REF;
125 125
                     break;
@@ -134,17 +134,17 @@  discard block
 block discarded – undo
134 134
             }
135 135
 
136 136
             // if isset a value in the map proceed with conversion otherwise skip
137
-            $attributesMap = Map::instance( $node->attributes );
138
-            if ( !$this->map->get( $attributesMap->get( 'dataRef' ) ) ) {
137
+            $attributesMap = Map::instance($node->attributes);
138
+            if (!$this->map->get($attributesMap->get('dataRef'))) {
139 139
                 return $string;
140 140
             }
141 141
 
142
-            $dataRefName = $node->attributes[ 'dataRef' ];   // map identifier. Eg: source1
142
+            $dataRefName = $node->attributes['dataRef']; // map identifier. Eg: source1
143 143
 
144 144
             return $this->replaceNewTagString(
145 145
                     $node->node,
146
-                    $attributesMap->getOrDefault( 'id', $dataRefName ),
147
-                    $this->map->getOrDefault( $node->attributes[ 'dataRef' ], 'NULL' ),
146
+                    $attributesMap->getOrDefault('id', $dataRefName),
147
+                    $this->map->getOrDefault($node->attributes['dataRef'], 'NULL'),
148 148
                     $ctype,
149 149
                     $string,
150 150
                     null
@@ -162,11 +162,11 @@  discard block
 block discarded – undo
162 162
      *
163 163
      * @return array
164 164
      */
165
-    private function sanitizeMap( $map ) {
165
+    private function sanitizeMap($map) {
166 166
 
167
-        foreach ( $map as $name => $value ) {
168
-            if ( is_null( $value ) || $value === '' ) {
169
-                $map[ $name ] = 'NULL';
167
+        foreach ($map as $name => $value) {
168
+            if (is_null($value) || $value === '') {
169
+                $map[$name] = 'NULL';
170 170
             }
171 171
         }
172 172
 
@@ -182,23 +182,23 @@  discard block
 block discarded – undo
182 182
      * @throws InvalidXmlException
183 183
      * @throws XmlParsingException
184 184
      */
185
-    private function recursiveReplaceSelfClosedPcTags( $node, $string ) {
185
+    private function recursiveReplaceSelfClosedPcTags($node, $string) {
186 186
 
187
-        if ( $node->has_children ) {
187
+        if ($node->has_children) {
188 188
 
189
-            foreach ( $node->inner_html as $childNode ) {
190
-                $string = $this->recursiveReplaceSelfClosedPcTags( $childNode, $string );
189
+            foreach ($node->inner_html as $childNode) {
190
+                $string = $this->recursiveReplaceSelfClosedPcTags($childNode, $string);
191 191
             }
192 192
 
193
-        } elseif ( $node->tagName == 'pc' && $node->self_closed === true ) {
193
+        } elseif ($node->tagName == 'pc' && $node->self_closed === true) {
194 194
 
195
-            $attributesMap = Map::instance( $node->attributes );
195
+            $attributesMap = Map::instance($node->attributes);
196 196
 
197
-            if ( $dataRefStartValue = $this->map->get( $node->attributes[ 'dataRefStart' ] ) ) {
197
+            if ($dataRefStartValue = $this->map->get($node->attributes['dataRefStart'])) {
198 198
 
199 199
                 $string = $this->replaceNewTagString(
200 200
                         $node->node,
201
-                        $attributesMap->get( 'id' ),
201
+                        $attributesMap->get('id'),
202 202
                         $dataRefStartValue,
203 203
                         CTypeEnum::PC_SELF_CLOSE_DATA_REF,
204 204
                         $string
@@ -218,23 +218,23 @@  discard block
 block discarded – undo
218 218
      * @param object    $node
219 219
      * @param ArrayList $dataRefEndMap
220 220
      */
221
-    private function extractDataRefMapRecursively( $node, ArrayList $dataRefEndMap ) {
221
+    private function extractDataRefMapRecursively($node, ArrayList $dataRefEndMap) {
222 222
 
223 223
         // we have to build the map for the closing pc tag, so get the children first
224
-        if ( $node->has_children ) {
225
-            foreach ( $node->inner_html as $nestedNode ) {
226
-                $this->extractDataRefMapRecursively( $nestedNode, $dataRefEndMap );
224
+        if ($node->has_children) {
225
+            foreach ($node->inner_html as $nestedNode) {
226
+                $this->extractDataRefMapRecursively($nestedNode, $dataRefEndMap);
227 227
             }
228 228
         }
229 229
 
230 230
         // EXCLUDE self closed <pc/>
231
-        if ( $node->tagName === 'pc' && $node->self_closed === false ) {
231
+        if ($node->tagName === 'pc' && $node->self_closed === false) {
232 232
 
233
-            $attributesMap = Map::instance( $node->attributes );
234
-            $dataRefEnd    = $attributesMap->getOrDefault( 'dataRefEnd', $attributesMap->get( 'dataRefStart' ) );
233
+            $attributesMap = Map::instance($node->attributes);
234
+            $dataRefEnd    = $attributesMap->getOrDefault('dataRefEnd', $attributesMap->get('dataRefStart'));
235 235
 
236 236
             $dataRefEndMap[] = [
237
-                    'id'         => $attributesMap->get( 'id' ),
237
+                    'id'         => $attributesMap->get('id'),
238 238
                     'dataRefEnd' => $dataRefEnd,
239 239
             ];
240 240
 
@@ -252,31 +252,31 @@  discard block
 block discarded – undo
252 252
      * @throws InvalidXmlException
253 253
      * @throws XmlParsingException
254 254
      */
255
-    private function replaceOpeningPcTags( $string ) {
255
+    private function replaceOpeningPcTags($string) {
256 256
 
257
-        preg_match_all( '|<pc ([^>/]+?)>|iu', $string, $openingPcMatches );
257
+        preg_match_all('|<pc ([^>/]+?)>|iu', $string, $openingPcMatches);
258 258
 
259
-        foreach ( $openingPcMatches[ 0 ] as $match ) {
259
+        foreach ($openingPcMatches[0] as $match) {
260 260
 
261
-            $node = XmlParser::parse( $match . '</pc>', true )[ 0 ]; // add a closing tag to not break xml integrity
261
+            $node = XmlParser::parse($match.'</pc>', true)[0]; // add a closing tag to not break xml integrity
262 262
 
263 263
             // CASE 1 - Missing `dataRefStart`
264
-            if ( isset( $node->attributes[ 'dataRefEnd' ] ) && !isset( $node->attributes[ 'dataRefStart' ] ) ) {
265
-                $node->attributes[ 'dataRefStart' ] = $node->attributes[ 'dataRefEnd' ];
264
+            if (isset($node->attributes['dataRefEnd']) && !isset($node->attributes['dataRefStart'])) {
265
+                $node->attributes['dataRefStart'] = $node->attributes['dataRefEnd'];
266 266
             }
267 267
 
268 268
             // CASE 2 - Missing `dataRefEnd`
269
-            if ( isset( $node->attributes[ 'dataRefStart' ] ) && !isset( $node->attributes[ 'dataRefEnd' ] ) ) {
270
-                $node->attributes[ 'dataRefEnd' ] = $node->attributes[ 'dataRefStart' ];
269
+            if (isset($node->attributes['dataRefStart']) && !isset($node->attributes['dataRefEnd'])) {
270
+                $node->attributes['dataRefEnd'] = $node->attributes['dataRefStart'];
271 271
             }
272 272
 
273
-            if ( isset( $node->attributes[ 'dataRefStart' ] ) ) {
273
+            if (isset($node->attributes['dataRefStart'])) {
274 274
 
275
-                $attributesMap = Map::instance( $node->attributes );
275
+                $attributesMap = Map::instance($node->attributes);
276 276
                 $string        = $this->replaceNewTagString(
277 277
                         $match,
278
-                        $attributesMap->get( 'id' ),
279
-                        $this->map->getOrDefault( $node->attributes[ 'dataRefStart' ], 'NULL' ),
278
+                        $attributesMap->get('id'),
279
+                        $this->map->getOrDefault($node->attributes['dataRefStart'], 'NULL'),
280 280
                         CTypeEnum::PC_OPEN_DATA_REF,
281 281
                         $string
282 282
                 );
@@ -296,31 +296,31 @@  discard block
 block discarded – undo
296 296
      *
297 297
      * @return string
298 298
      */
299
-    private function replaceClosingPcTags( $string, ArrayList $dataRefEndMap ) {
299
+    private function replaceClosingPcTags($string, ArrayList $dataRefEndMap) {
300 300
 
301
-        preg_match_all( '|</pc>|iu', $string, $closingPcMatches, PREG_OFFSET_CAPTURE );
301
+        preg_match_all('|</pc>|iu', $string, $closingPcMatches, PREG_OFFSET_CAPTURE);
302 302
         $delta = 0;
303 303
 
304
-        foreach ( $closingPcMatches[ 0 ] as $index => $match ) {
304
+        foreach ($closingPcMatches[0] as $index => $match) {
305 305
 
306
-            $offset = $match[ 1 ];
306
+            $offset = $match[1];
307 307
             $length = 5; // strlen of '</pc>'
308 308
 
309
-            $attr = $dataRefEndMap->get( $index );
310
-            if ( !empty( $attr ) && isset( $attr[ 'dataRefEnd' ] ) ) {
309
+            $attr = $dataRefEndMap->get($index);
310
+            if (!empty($attr) && isset($attr['dataRefEnd'])) {
311 311
 
312 312
                 // conversion for opening <pc> tag
313 313
                 $completeTag = $this->getNewTagString(
314 314
                         '</pc>',
315
-                        $attr[ 'id' ],
316
-                        $this->map->getOrDefault( $attr[ 'dataRefEnd' ], 'NULL' ),
315
+                        $attr['id'],
316
+                        $this->map->getOrDefault($attr['dataRefEnd'], 'NULL'),
317 317
                         CTypeEnum::PC_CLOSE_DATA_REF,
318 318
                         '_2'
319 319
                 );
320 320
 
321
-                $realOffset = ( $delta === 0 ) ? $offset : ( $offset + $delta );
322
-                $string     = substr_replace( $string, $completeTag, $realOffset, $length );
323
-                $delta      = $delta + strlen( $completeTag ) - $length;
321
+                $realOffset = ($delta === 0) ? $offset : ($offset + $delta);
322
+                $string     = substr_replace($string, $completeTag, $realOffset, $length);
323
+                $delta      = $delta + strlen($completeTag) - $length;
324 324
 
325 325
             }
326 326
 
@@ -338,17 +338,17 @@  discard block
 block discarded – undo
338 338
      * @throws InvalidXmlException
339 339
      * @throws XmlParsingException
340 340
      */
341
-    public function restore( $string ) {
341
+    public function restore($string) {
342 342
 
343 343
         // if the map is empty return string as is
344
-        if ( empty( $this->map ) ) {
344
+        if (empty($this->map)) {
345 345
             return $string;
346 346
         }
347 347
 
348
-        $html = XmlParser::parse( $string, true );
348
+        $html = XmlParser::parse($string, true);
349 349
 
350
-        foreach ( $html as $node ) {
351
-            $string = $this->recursiveRestoreOriginalTags( $node, $string );
350
+        foreach ($html as $node) {
351
+            $string = $this->recursiveRestoreOriginalTags($node, $string);
352 352
         }
353 353
 
354 354
         return $string;
@@ -360,21 +360,21 @@  discard block
 block discarded – undo
360 360
      *
361 361
      * @return string
362 362
      */
363
-    private function recursiveRestoreOriginalTags( $node, $string ) {
363
+    private function recursiveRestoreOriginalTags($node, $string) {
364 364
 
365
-        if ( $node->has_children ) {
365
+        if ($node->has_children) {
366 366
 
367
-            foreach ( $node->inner_html as $childNode ) {
368
-                $string = $this->recursiveRestoreOriginalTags( $childNode, $string );
367
+            foreach ($node->inner_html as $childNode) {
368
+                $string = $this->recursiveRestoreOriginalTags($childNode, $string);
369 369
             }
370 370
 
371 371
         } else {
372 372
 
373
-            $nodeAttributesMap = Map::instance( $node->attributes );
374
-            $cType             = $nodeAttributesMap->get( 'ctype' );
373
+            $nodeAttributesMap = Map::instance($node->attributes);
374
+            $cType             = $nodeAttributesMap->get('ctype');
375 375
 
376
-            if ( CTypeEnum::isLayer2Constant( $cType ) ) {
377
-                return preg_replace( '/' . preg_quote( $node->node, '/' ) . '/', base64_decode( $node->attributes[ 'x-orig' ] ), $string, 1 );
376
+            if (CTypeEnum::isLayer2Constant($cType)) {
377
+                return preg_replace('/'.preg_quote($node->node, '/').'/', base64_decode($node->attributes['x-orig']), $string, 1);
378 378
             }
379 379
 
380 380
         }
@@ -392,24 +392,24 @@  discard block
 block discarded – undo
392 392
      *
393 393
      * @return string
394 394
      */
395
-    private function getNewTagString( $actualNodeString, $id, $dataRefValue, $ctype, $upCountIdValue = null ) {
395
+    private function getNewTagString($actualNodeString, $id, $dataRefValue, $ctype, $upCountIdValue = null) {
396 396
 
397
-        $newTag = [ '<ph' ];
397
+        $newTag = ['<ph'];
398 398
 
399
-        if ( isset( $id ) ) {
400
-            $newTag[] = 'id="' . $id . $upCountIdValue . '"';
399
+        if (isset($id)) {
400
+            $newTag[] = 'id="'.$id.$upCountIdValue.'"';
401 401
         }
402 402
 
403
-        $newTag[] = 'ctype="' . $ctype . '"';
404
-        $newTag[] = 'equiv-text="base64:' . base64_encode( $dataRefValue ) . '"';
405
-        $newTag[] = 'x-orig="' . base64_encode( $actualNodeString ) . '"';
403
+        $newTag[] = 'ctype="'.$ctype.'"';
404
+        $newTag[] = 'equiv-text="base64:'.base64_encode($dataRefValue).'"';
405
+        $newTag[] = 'x-orig="'.base64_encode($actualNodeString).'"';
406 406
 
407
-        return implode( " ", $newTag ) . '/>';
407
+        return implode(" ", $newTag).'/>';
408 408
 
409 409
     }
410 410
 
411
-    private function replaceNewTagString( $actualNodeString, $id, $dataRefValue, $ctype, $originalString, $upCountIdValue = '_1' ) {
412
-        return str_replace( $actualNodeString, $this->getNewTagString( $actualNodeString, $id, $dataRefValue, $ctype, $upCountIdValue ), $originalString );
411
+    private function replaceNewTagString($actualNodeString, $id, $dataRefValue, $ctype, $originalString, $upCountIdValue = '_1') {
412
+        return str_replace($actualNodeString, $this->getNewTagString($actualNodeString, $id, $dataRefValue, $ctype, $upCountIdValue), $originalString);
413 413
     }
414 414
 
415 415
 }
416 416
\ No newline at end of file
Please login to merge, or discard this patch.
src/Utils/ArrayList.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -16,12 +16,12 @@  discard block
 block discarded – undo
16 16
     /**
17 17
      * @param array $list
18 18
      */
19
-    public function __construct( array $list = [] ) {
20
-        parent::__construct( $list );
19
+    public function __construct(array $list = []) {
20
+        parent::__construct($list);
21 21
     }
22 22
 
23
-    public static function instance( array $list = [] ) {
24
-        return new static( $list );
23
+    public static function instance(array $list = []) {
24
+        return new static($list);
25 25
     }
26 26
 
27 27
     /**
@@ -29,9 +29,9 @@  discard block
 block discarded – undo
29 29
      *
30 30
      * @return false|mixed|null
31 31
      */
32
-    public function offsetGet( $key ) {
33
-        if ( $this->offsetExists( $key ) ) {
34
-            return parent::offsetGet( $key );
32
+    public function offsetGet($key) {
33
+        if ($this->offsetExists($key)) {
34
+            return parent::offsetGet($key);
35 35
         }
36 36
 
37 37
         return null;
@@ -44,8 +44,8 @@  discard block
 block discarded – undo
44 44
      *
45 45
      * @return false|mixed|null the element at the specified position in this list
46 46
      */
47
-    public function get( $key ) {
48
-        return $this->offsetGet( $key );
47
+    public function get($key) {
48
+        return $this->offsetGet($key);
49 49
     }
50 50
 
51 51
 
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_OR_NOT_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_OR_NOT_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.+? ctype="' . CTypeEnum::ORIGINAL_PC_OPEN_NO_DATA_REF . '" equiv-text="base64:(.*?)"/>|iu', $segment, $matches );
93
-        preg_match_all( '|<ph.+? ctype="' . CTypeEnum::ORIGINAL_PC_CLOSE_NO_DATA_REF . '" equiv-text="base64:(.*?)"/>|iu', $segment, $matches );
91
+    private function restoreXliffPcTagsFromMatecatPhTags($segment) {
92
+        preg_match_all('|<ph.+? ctype="'.CTypeEnum::ORIGINAL_PC_OPEN_NO_DATA_REF.'" equiv-text="base64:(.*?)"/>|iu', $segment, $matches);
93
+        preg_match_all('|<ph.+? ctype="'.CTypeEnum::ORIGINAL_PC_CLOSE_NO_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/FromLayer2ToRawXML.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -23,11 +23,11 @@  discard block
 block discarded – undo
23 23
 
24 24
     private $brokenHTML = false;
25 25
 
26
-    public function transform( $segment ) {
26
+    public function transform($segment) {
27 27
 
28 28
         //normal control characters must be converted to entities
29 29
         $segment = str_replace(
30
-                [ "\r\n", "\r", "\n", "\t", "", ],
30
+                ["\r\n", "\r", "\n", "\t", "", ],
31 31
                 [
32 32
                         '&#13;&#10;',
33 33
                         '&#13;',
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
                 ], $segment );
38 38
 
39 39
         // now convert the real &nbsp;
40
-        return str_replace( ConstantEnum::nbspPlaceholder, Utils::unicode2chr( 0Xa0 ), $segment );
40
+        return str_replace(ConstantEnum::nbspPlaceholder, Utils::unicode2chr(0Xa0), $segment);
41 41
 
42 42
     }
43 43
 
Please login to merge, or discard this patch.
src/Filters/EncodeToRawXML.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -6,42 +6,42 @@
 block discarded – undo
6 6
 use Matecat\SubFiltering\Utils\Utils;
7 7
 
8 8
 class EncodeToRawXML extends AbstractHandler {
9
-    public function transform( $segment ) {
9
+    public function transform($segment) {
10 10
 
11 11
         // handling &#10; (line feed)
12 12
         // prevent to convert it to \n
13
-        $segment = preg_replace( '/&(#10;|#x0A;)|\n/', '##_ent_0A_##', $segment );
13
+        $segment = preg_replace('/&(#10;|#x0A;)|\n/', '##_ent_0A_##', $segment);
14 14
 
15 15
         // handling &#13; (carriage return)
16 16
         // prevent to convert it to \r
17
-        $segment = preg_replace( '/&(#13;|#x0D;)|\r/', '##_ent_0D_##', $segment );
17
+        $segment = preg_replace('/&(#13;|#x0D;)|\r/', '##_ent_0D_##', $segment);
18 18
 
19 19
         // handling &#09; (tab)
20 20
         // prevent to convert it to \t
21
-        $segment = preg_replace( '/&#09;|\t/', '##_ent_09_##', $segment );
21
+        $segment = preg_replace('/&#09;|\t/', '##_ent_09_##', $segment);
22 22
 
23 23
         //Substitute 4(+)-byte characters from a UTF-8 string to htmlentities
24
-        $segment = preg_replace_callback( '/([\xF0-\xF7]...)/s', [ Utils::class, 'htmlentitiesFromUnicode' ], $segment );
24
+        $segment = preg_replace_callback('/([\xF0-\xF7]...)/s', [Utils::class, 'htmlentitiesFromUnicode'], $segment);
25 25
 
26 26
         // handling &#10;
27
-        if ( strpos( $segment, '##_ent_0D_##' ) !== false ) {
28
-            $segment = str_replace( '##_ent_0D_##', '&#13;', $segment );
27
+        if (strpos($segment, '##_ent_0D_##') !== false) {
28
+            $segment = str_replace('##_ent_0D_##', '&#13;', $segment);
29 29
         }
30 30
 
31 31
         // handling &#13;
32
-        if ( strpos( $segment, '##_ent_0A_##' ) !== false ) {
33
-            $segment = str_replace( '##_ent_0A_##', '&#10;', $segment );
32
+        if (strpos($segment, '##_ent_0A_##') !== false) {
33
+            $segment = str_replace('##_ent_0A_##', '&#10;', $segment);
34 34
         }
35 35
 
36 36
         // handling &#09; (tab)
37 37
         // prevent to convert it to \t
38
-        if ( strpos( $segment, '##_ent_09_##' ) !== false ) {
39
-            $segment = str_replace( '##_ent_09_##', '&#09;', $segment );
38
+        if (strpos($segment, '##_ent_09_##') !== false) {
39
+            $segment = str_replace('##_ent_09_##', '&#09;', $segment);
40 40
         }
41 41
 
42 42
 
43 43
         //encode all not valid XML entities
44
-        $segment = preg_replace( '/&(?!lt;|gt;|amp;|quot;|apos;|#[x]{0,1}[0-9A-F]{1,7};)/', '&amp;', $segment );
44
+        $segment = preg_replace('/&(?!lt;|gt;|amp;|quot;|apos;|#[x]{0,1}[0-9A-F]{1,7};)/', '&amp;', $segment);
45 45
 
46 46
         return $segment;
47 47
     }
Please login to merge, or discard this patch.
src/Filters/DataRefReplace.php 1 patch
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -25,24 +25,24 @@  discard block
 block discarded – undo
25 25
     /**
26 26
      * @inheritDoc
27 27
      */
28
-    public function transform( $segment ) {
28
+    public function transform($segment) {
29 29
 
30
-        if ( empty( $this->dataRefMap ) ) {
30
+        if (empty($this->dataRefMap)) {
31 31
             $this->dataRefMap = $this->pipeline->getDataRefMap();
32 32
         }
33 33
 
34 34
         // dataRefMap is present only in xliff 2.0 files
35
-        if ( empty( $this->dataRefMap ) ) {
36
-            $segment = $this->replace_Ph_TagsWithoutDataRefCorrespondenceToMatecatPhTags( $segment );
35
+        if (empty($this->dataRefMap)) {
36
+            $segment = $this->replace_Ph_TagsWithoutDataRefCorrespondenceToMatecatPhTags($segment);
37 37
 
38
-            return $this->replace_Pc_TagsWithoutDataRefCorrespondenceToMatecatPhTags( $segment );
38
+            return $this->replace_Pc_TagsWithoutDataRefCorrespondenceToMatecatPhTags($segment);
39 39
         }
40 40
 
41
-        $dataRefReplacer = new DataRefReplacer( $this->dataRefMap );
42
-        $segment         = $dataRefReplacer->replace( $segment );
43
-        $segment         = $this->replace_Ph_TagsWithoutDataRefCorrespondenceToMatecatPhTags( $segment );
41
+        $dataRefReplacer = new DataRefReplacer($this->dataRefMap);
42
+        $segment         = $dataRefReplacer->replace($segment);
43
+        $segment         = $this->replace_Ph_TagsWithoutDataRefCorrespondenceToMatecatPhTags($segment);
44 44
 
45
-        return $this->replace_Pc_TagsWithoutDataRefCorrespondenceToMatecatPhTags( $segment );
45
+        return $this->replace_Pc_TagsWithoutDataRefCorrespondenceToMatecatPhTags($segment);
46 46
     }
47 47
 
48 48
     /**
@@ -61,23 +61,23 @@  discard block
 block discarded – undo
61 61
      *
62 62
      * @return string
63 63
      */
64
-    private function replace_Ph_TagsWithoutDataRefCorrespondenceToMatecatPhTags( $segment ) {
64
+    private function replace_Ph_TagsWithoutDataRefCorrespondenceToMatecatPhTags($segment) {
65 65
 
66
-        preg_match_all( '/<(ph .*?)>/iu', $segment, $phTags );
66
+        preg_match_all('/<(ph .*?)>/iu', $segment, $phTags);
67 67
 
68
-        if ( count( $phTags[ 0 ] ) === 0 ) {
68
+        if (count($phTags[0]) === 0) {
69 69
             return $segment;
70 70
         }
71 71
 
72
-        foreach ( $phTags[ 0 ] as $phTag ) {
72
+        foreach ($phTags[0] as $phTag) {
73 73
 
74 74
             // check if phTag has not any correspondence on dataRef map
75
-            if ( $this->isAValidPhTag( $phTag ) ) {
75
+            if ($this->isAValidPhTag($phTag)) {
76 76
                 $segment = preg_replace(
77
-                        '/' . preg_quote( $phTag, '/' ) . '/',
78
-                        '<ph id="' . $this->getPipeline()->getNextId() .
79
-                        '" ctype="' . CTypeEnum::ORIGINAL_PH_OR_NOT_DATA_REF .
80
-                        '" equiv-text="base64:' . base64_encode( $phTag ) .
77
+                        '/'.preg_quote($phTag, '/').'/',
78
+                        '<ph id="'.$this->getPipeline()->getNextId().
79
+                        '" ctype="'.CTypeEnum::ORIGINAL_PH_OR_NOT_DATA_REF.
80
+                        '" equiv-text="base64:'.base64_encode($phTag).
81 81
                         '"/>',
82 82
                         $segment,
83 83
                         1 // replace ONLY ONE occurrence
@@ -97,28 +97,28 @@  discard block
 block discarded – undo
97 97
      *
98 98
      * @return bool
99 99
      */
100
-    private function isAValidPhTag( $phTag ) {
100
+    private function isAValidPhTag($phTag) {
101 101
 
102 102
         // try not to throw exception for wrong segments with opening tags and no closing
103 103
         try {
104
-            $parsed = XmlParser::parse( $phTag, true );
105
-        } catch ( Exception $e ){
104
+            $parsed = XmlParser::parse($phTag, true);
105
+        } catch (Exception $e) {
106 106
             return false;
107 107
         }
108 108
 
109 109
         // check for matecat ctype
110
-        $cType = isset( $parsed[ 0 ]->attributes[ 'ctype' ] ) ? $parsed[ 0 ]->attributes[ 'ctype' ] : null;
111
-        if ( CTypeEnum::isMatecatCType( $cType ) ) {
110
+        $cType = isset($parsed[0]->attributes['ctype']) ? $parsed[0]->attributes['ctype'] : null;
111
+        if (CTypeEnum::isMatecatCType($cType)) {
112 112
             return false;
113 113
         }
114 114
 
115 115
         // if has equiv-text don't touch
116
-        if ( isset( $parsed[ 0 ]->attributes[ 'equiv-text' ] ) ) {
116
+        if (isset($parsed[0]->attributes['equiv-text'])) {
117 117
             return false;
118 118
         }
119 119
 
120
-        if ( isset( $parsed[ 0 ]->attributes[ 'dataRef' ] ) ) {
121
-            return !array_key_exists( $parsed[ 0 ]->attributes[ 'dataRef' ], $this->dataRefMap );
120
+        if (isset($parsed[0]->attributes['dataRef'])) {
121
+            return !array_key_exists($parsed[0]->attributes['dataRef'], $this->dataRefMap);
122 122
         }
123 123
 
124 124
         return true;
@@ -141,33 +141,33 @@  discard block
 block discarded – undo
141 141
      *
142 142
      * @return string
143 143
      */
144
-    private function replace_Pc_TagsWithoutDataRefCorrespondenceToMatecatPhTags( $segment ) {
144
+    private function replace_Pc_TagsWithoutDataRefCorrespondenceToMatecatPhTags($segment) {
145 145
 
146
-        preg_match_all( '/<(pc .*?)>/iu', $segment, $openingPcTags );
147
-        preg_match_all( '|<(/pc)>|iu', $segment, $closingPcTags );
146
+        preg_match_all('/<(pc .*?)>/iu', $segment, $openingPcTags);
147
+        preg_match_all('|<(/pc)>|iu', $segment, $closingPcTags);
148 148
 
149
-        if ( count( $openingPcTags[ 0 ] ) === 0 ) {
149
+        if (count($openingPcTags[0]) === 0) {
150 150
             return $segment;
151 151
         }
152 152
 
153
-        foreach ( $openingPcTags[ 0 ] as $openingPcTag ) {
153
+        foreach ($openingPcTags[0] as $openingPcTag) {
154 154
             $segment = preg_replace(
155
-                    '/' . preg_quote( $openingPcTag, '/' ) . '/',
156
-                    '<ph id="' . $this->getPipeline()->getNextId() .
157
-                    '" ctype="' . CTypeEnum::ORIGINAL_PC_OPEN_NO_DATA_REF .
158
-                    '" equiv-text="base64:' . base64_encode( $openingPcTag ) .
155
+                    '/'.preg_quote($openingPcTag, '/').'/',
156
+                    '<ph id="'.$this->getPipeline()->getNextId().
157
+                    '" ctype="'.CTypeEnum::ORIGINAL_PC_OPEN_NO_DATA_REF.
158
+                    '" equiv-text="base64:'.base64_encode($openingPcTag).
159 159
                     '"/>',
160 160
                     $segment,
161 161
                     1
162 162
             );
163 163
         }
164 164
 
165
-        foreach ( $closingPcTags[ 0 ] as $closingPcTag ) {
165
+        foreach ($closingPcTags[0] as $closingPcTag) {
166 166
             $segment = preg_replace(
167
-                    '/' . preg_quote( $closingPcTag, '/' ) . '/',
168
-                    '<ph id="' . $this->getPipeline()->getNextId() .
169
-                    '" ctype="' . CTypeEnum::ORIGINAL_PC_CLOSE_NO_DATA_REF .
170
-                    '" equiv-text="base64:' . base64_encode( $closingPcTag ) .
167
+                    '/'.preg_quote($closingPcTag, '/').'/',
168
+                    '<ph id="'.$this->getPipeline()->getNextId().
169
+                    '" ctype="'.CTypeEnum::ORIGINAL_PC_CLOSE_NO_DATA_REF.
170
+                    '" equiv-text="base64:'.base64_encode($closingPcTag).
171 171
                     '"/>',
172 172
                     $segment,
173 173
                     1
Please login to merge, or discard this patch.
src/Enum/CTypeEnum.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -44,17 +44,17 @@  discard block
 block discarded – undo
44 44
      * @return array
45 45
      */
46 46
     protected static function getAllConstantValuesMap() {
47
-        if ( empty( static::$allConstantValues ) ) {
48
-            $reflectedProperty            = ( new ReflectionClass( static::class ) )->getConstants();
49
-            static::$allConstantValues    = array_flip( $reflectedProperty );
47
+        if (empty(static::$allConstantValues)) {
48
+            $reflectedProperty            = (new ReflectionClass(static::class))->getConstants();
49
+            static::$allConstantValues    = array_flip($reflectedProperty);
50 50
             static::$layer2ConstantValues = array_flip(
51
-                    array_filter( $reflectedProperty, function ( $key ) {
52
-                        return Utils::contains( 'DATA_REF', $key );
53
-                    }, ARRAY_FILTER_USE_KEY )
51
+                    array_filter($reflectedProperty, function($key) {
52
+                        return Utils::contains('DATA_REF', $key);
53
+                    }, ARRAY_FILTER_USE_KEY)
54 54
             );
55 55
         }
56 56
 
57
-        return [ 'all' => static::$allConstantValues, 'layer2' => static::$layer2ConstantValues ];
57
+        return ['all' => static::$allConstantValues, 'layer2' => static::$layer2ConstantValues];
58 58
     }
59 59
 
60 60
     /**
@@ -62,8 +62,8 @@  discard block
 block discarded – undo
62 62
      *
63 63
      * @return bool
64 64
      */
65
-    public static function isMatecatCType( $ctype ) {
66
-        return array_key_exists( $ctype, static::getAllConstantValuesMap()[ 'all' ] );
65
+    public static function isMatecatCType($ctype) {
66
+        return array_key_exists($ctype, static::getAllConstantValuesMap()['all']);
67 67
     }
68 68
 
69 69
     /**
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
      *
72 72
      * @return bool
73 73
      */
74
-    public static function isLayer2Constant( $ctype ) {
75
-        return array_key_exists( $ctype, static::getAllConstantValuesMap()[ 'layer2' ] );
74
+    public static function isLayer2Constant($ctype) {
75
+        return array_key_exists($ctype, static::getAllConstantValuesMap()['layer2']);
76 76
     }
77 77
 
78 78
 }
79 79
\ No newline at end of file
Please login to merge, or discard this patch.