Passed
Push — master ( f2f1e3...8e7d9e )
by Luca
02:31
created
src/EntityDecoder.php 3 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
24 24
     private $entities = false;
25 25
     private $style;
26 26
 
27
-     /**
28
-     * @param string $style       Either 'HTML', 'Markdown' or 'MarkdownV2'.
29
-     */
27
+      /**
28
+       * @param string $style       Either 'HTML', 'Markdown' or 'MarkdownV2'.
29
+       */
30 30
     public function __construct(string $style = 'HTML')
31 31
     {
32 32
         $this->style = $style;
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
             {
395 395
                 if (in_array($entity->type, array('bold', 'italic', 'code', 'pre', 'text_mention', 'text_link', 'strikethrough', 'underline', 'spoiler')))
396 396
                 {
397
-                   $entities[] = $entity;
397
+                    $entities[] = $entity;
398 398
                 }
399 399
             }
400 400
         }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
         if (count($openedEntities) > 0)
119 119
         {
120 120
             $openedEntities = array_reverse($openedEntities);
121
-            foreach($openedEntities as $oe)
121
+            foreach ($openedEntities as $oe)
122 122
             {
123 123
                 $finalText .= $this->getEntityStopString($oe);
124 124
             }
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
         $str_split_unicode = preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY);
141 141
         $new_string_split = [];
142 142
         $joiner = false;
143
-        for ($i = 0, $c = count($str_split_unicode); $i<$c; $i++) //loop the array
143
+        for ($i = 0, $c = count($str_split_unicode); $i < $c; $i++) //loop the array
144 144
         {
145
-            $codepoint = bin2hex(mb_convert_encoding($str_split_unicode[$i], 'UTF-16'));    //Get the string rappresentation of the unicode char
145
+            $codepoint = bin2hex(mb_convert_encoding($str_split_unicode[$i], 'UTF-16')); //Get the string rappresentation of the unicode char
146 146
             if ($codepoint == "fe0f" || $codepoint == "1f3fb" || $codepoint == "1f3fc" || $codepoint == "1f3fd" || $codepoint == "1f3fe" || $codepoint == "1f3ff")   //Manage the modifiers
147 147
             {
148
-                $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i];  //Apppend the modifier to the previous char
148
+                $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i]; //Apppend the modifier to the previous char
149 149
             }
150 150
             else
151 151
             {
@@ -158,12 +158,12 @@  discard block
 block discarded – undo
158 158
                 {
159 159
                     if ($joiner) //If previous one was a ZWJ
160 160
                     {
161
-                        $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i];  //Apppend to the previous char
161
+                        $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i]; //Apppend to the previous char
162 162
                         $joiner = false;
163 163
                     }
164 164
                     else
165 165
                     {
166
-                        $new_string_split[] = $str_split_unicode[$i];   //New char
166
+                        $new_string_split[] = $str_split_unicode[$i]; //New char
167 167
                     }
168 168
                 }
169 169
             }
Please login to merge, or discard this patch.
Braces   +45 added lines, -47 removed lines patch added patch discarded remove patch
@@ -140,28 +140,37 @@  discard block
 block discarded – undo
140 140
         $str_split_unicode = preg_split('//u', $string, -1, PREG_SPLIT_NO_EMPTY);
141 141
         $new_string_split = [];
142 142
         $joiner = false;
143
-        for ($i = 0, $c = count($str_split_unicode); $i<$c; $i++) //loop the array
143
+        for ($i = 0, $c = count($str_split_unicode); $i<$c; $i++) {
144
+          //loop the array
144 145
         {
145
-            $codepoint = bin2hex(mb_convert_encoding($str_split_unicode[$i], 'UTF-16'));    //Get the string rappresentation of the unicode char
146
-            if ($codepoint == "fe0f" || $codepoint == "1f3fb" || $codepoint == "1f3fc" || $codepoint == "1f3fd" || $codepoint == "1f3fe" || $codepoint == "1f3ff")   //Manage the modifiers
146
+            $codepoint = bin2hex(mb_convert_encoding($str_split_unicode[$i], 'UTF-16'));
147
+        }
148
+        //Get the string rappresentation of the unicode char
149
+            if ($codepoint == "fe0f" || $codepoint == "1f3fb" || $codepoint == "1f3fc" || $codepoint == "1f3fd" || $codepoint == "1f3fe" || $codepoint == "1f3ff") {
150
+              //Manage the modifiers
147 151
             {
148
-                $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i];  //Apppend the modifier to the previous char
152
+                $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i];
149 153
             }
150
-            else
154
+            //Apppend the modifier to the previous char
155
+            } else
151 156
             {
152
-                if ($codepoint == "200d")    //Manage the Zero Width Joiner
157
+                if ($codepoint == "200d") {
158
+                  //Manage the Zero Width Joiner
153 159
                 {
154
-                    $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i]; //Apppend the ZWJ to the previous char
155
-                    $joiner = true;
160
+                    $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i];
156 161
                 }
157
-                else
162
+                //Apppend the ZWJ to the previous char
163
+                    $joiner = true;
164
+                } else
158 165
                 {
159
-                    if ($joiner) //If previous one was a ZWJ
166
+                    if ($joiner) {
167
+                      //If previous one was a ZWJ
160 168
                     {
161
-                        $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i];  //Apppend to the previous char
162
-                        $joiner = false;
169
+                        $new_string_split[count($new_string_split) - 1] .= $str_split_unicode[$i];
163 170
                     }
164
-                    else
171
+                    //Apppend to the previous char
172
+                        $joiner = false;
173
+                    } else
165 174
                     {
166 175
                         $new_string_split[] = $str_split_unicode[$i];   //New char
167 176
                     }
@@ -190,38 +199,31 @@  discard block
 block discarded – undo
190 199
                     if ($char == $this->getEntityStartString($entity))
191 200
                     {
192 201
                         return $char."\\".$char.$char;
193
-                    }
194
-                    else
202
+                    } else
195 203
                     {
196 204
                         return $char;
197 205
                     }
198
-                }
199
-                else
206
+                } else
200 207
                 {
201 208
                     return $char;
202 209
                 }
203
-            }
204
-            else
210
+            } else
205 211
             {
206 212
                 if ($char == '*' || $char == '_' || $char == '[' || $char == '`')
207 213
                 {
208 214
                     return "\\".$char;
209
-                }
210
-                else
215
+                } else
211 216
                 {
212 217
                     return $char;
213 218
                 }
214 219
             }
215
-        }
216
-        else if ($this->style == 'HTML')
220
+        } else if ($this->style == 'HTML')
217 221
         {
218 222
             return ($char == '<' ? '&lt;' : ($char == '>' ? '&gt;' : ($char == '&' ? '&amp;' : $char)));
219
-        }
220
-        else if ($this->style == 'MarkdownV2')
223
+        } else if ($this->style == 'MarkdownV2')
221 224
         {
222 225
             return (in_array($char, array('_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\')) ? '\\'.$char : $char);
223
-        }
224
-        else
226
+        } else
225 227
         {
226 228
             return $char;
227 229
         }
@@ -268,8 +270,7 @@  discard block
 block discarded – undo
268 270
                     break;
269 271
                 }
270 272
             }
271
-        }
272
-        else if ($this->style == 'HTML')
273
+        } else if ($this->style == 'HTML')
273 274
         {
274 275
             switch ($entity->type)
275 276
             {
@@ -323,8 +324,7 @@  discard block
 block discarded – undo
323 324
                     break;
324 325
                 }
325 326
             }
326
-        }
327
-        else if ($this->style == 'MarkdownV2')
327
+        } else if ($this->style == 'MarkdownV2')
328 328
         {
329 329
             switch ($entity->type)
330 330
             {
@@ -374,8 +374,7 @@  discard block
 block discarded – undo
374 374
                     break;
375 375
                 }
376 376
             }
377
-        }
378
-        else
377
+        } else
379 378
         {
380 379
             //Exception
381 380
         }
@@ -398,10 +397,11 @@  discard block
 block discarded – undo
398 397
                 }
399 398
             }
400 399
         }
401
-        if (count($entities) > 0)
402
-            return $entities;
403
-        else
404
-            return false;
400
+        if (count($entities) > 0) {
401
+                    return $entities;
402
+        } else {
403
+                    return false;
404
+        }
405 405
     }
406 406
 
407 407
     /**
@@ -445,8 +445,7 @@  discard block
 block discarded – undo
445 445
                     break;
446 446
                 }
447 447
             }
448
-        }
449
-        else if ($this->style == 'HTML')
448
+        } else if ($this->style == 'HTML')
450 449
         {
451 450
             switch ($entity->type)
452 451
             {
@@ -496,8 +495,7 @@  discard block
 block discarded – undo
496 495
                     break;
497 496
                 }
498 497
             }
499
-        }
500
-        else if ($this->style == 'MarkdownV2')
498
+        } else if ($this->style == 'MarkdownV2')
501 499
         {
502 500
             switch ($entity->type)
503 501
             {
@@ -547,8 +545,7 @@  discard block
 block discarded – undo
547 545
                     break;
548 546
                 }
549 547
             }
550
-        }
551
-        else
548
+        } else
552 549
         {
553 550
             //Exception
554 551
         }
@@ -571,10 +568,11 @@  discard block
 block discarded – undo
571 568
                 }
572 569
             }
573 570
         }
574
-        if (count($entities) > 0)
575
-            return array_reverse($entities);
576
-        else
577
-            return false;
571
+        if (count($entities) > 0) {
572
+                    return array_reverse($entities);
573
+        } else {
574
+                    return false;
575
+        }
578 576
     }
579 577
     
580 578
     /**
Please login to merge, or discard this patch.