Completed
Push — master ( d1c421...1f5165 )
by Filippo
21s queued 13s
created
src/Converter/BBCodeConverter.php 1 patch
Braces   +55 added lines, -46 removed lines patch added patch discarded remove patch
@@ -172,8 +172,9 @@  discard block
 block discarded – undo
172 172
                 $buffer = "";
173 173
                 
174 174
                 $list = preg_replace('/\s*$|^\s*/mu', '', $matches['items']);
175
-                if ( is_null($list) )
176
-                    throw new \RuntimeException(sprintf("Text identified by '%d' has malformed BBCode lists", $this->id));
175
+                if ( is_null($list) ) {
176
+                                    throw new \RuntimeException(sprintf("Text identified by '%d' has malformed BBCode lists", $this->id));
177
+                }
177 178
                 
178 179
                 $items = preg_split('/\[\*\]/u', $list);
179 180
                 
@@ -181,19 +182,22 @@  discard block
 block discarded – undo
181 182
                 
182 183
                 if ( isset($matches['type']) && $matches['type'] == '=1' ) { // ordered list
183 184
                     // We start from 1 to discard the first string, in fact, it's empty.
184
-                    for ( $i = 1; $i < $counter; $i++ )
185
-                        if ( !empty($items[ $i ]) )
185
+                    for ( $i = 1; $i < $counter; $i++ ) {
186
+                                            if ( !empty($items[ $i ]) )
186 187
                             $buffer .= (string) ( $i ) . '. ' . trim($items[ $i ]) . PHP_EOL;
188
+                    }
187 189
                 } else { // unordered list
188 190
                     // We start from 1 to discard the first string, in fact, it's empty.
189
-                    for ( $i = 1; $i < $counter; $i++ )
190
-                        if ( !empty($items[ $i ]) )
191
+                    for ( $i = 1; $i < $counter; $i++ ) {
192
+                                            if ( !empty($items[ $i ]) )
191 193
                             $buffer .= '- ' . trim($items[ $i ]) . PHP_EOL;
194
+                    }
192 195
                 }
193 196
                 
194 197
                 // We need a like break above the list and another one below.
195
-                if ( !empty($buffer) )
196
-                    $buffer = PHP_EOL . $buffer . PHP_EOL;
198
+                if ( !empty($buffer) ) {
199
+                                    $buffer = PHP_EOL . $buffer . PHP_EOL;
200
+                }
197 201
                 
198 202
                 return $buffer;
199 203
             },
@@ -213,10 +217,11 @@  discard block
 block discarded – undo
213 217
         $this->text = preg_replace_callback('%\[url\s*=\s*("(?:[^"]*")|\A[^\']*\Z|(?:[^\'">\]\s]+))\s*(?:[^]\s]*)\]([\W\D\w\s]*?)\[/url\]%iu',
214 218
             
215 219
             function ($matches) {
216
-                if ( isset($matches[1]) && isset($matches[2]) )
217
-                    return "[" . $matches[2] . "](" . $matches[1] . ")";
218
-                else
219
-                    throw new \RuntimeException(sprintf("Text identified by '%d' has malformed BBCode urls", $this->id));
220
+                if ( isset($matches[1]) && isset($matches[2]) ) {
221
+                                    return "[" . $matches[2] . "](" . $matches[1] . ")";
222
+                } else {
223
+                                    throw new \RuntimeException(sprintf("Text identified by '%d' has malformed BBCode urls", $this->id));
224
+                }
220 225
             },
221 226
             
222 227
             $this->text
@@ -233,10 +238,11 @@  discard block
 block discarded – undo
233 238
         $this->text = preg_replace_callback('%\[url\]([\W\D\w\s]*?)\[/url\]%iu',
234 239
             
235 240
             function ($matches) {
236
-                if ( isset($matches[1]) )
237
-                    return "[" . $matches[1] . "](" . $matches[1] . ")";
238
-                else
239
-                    throw new \RuntimeException(sprintf("Text identified by '%d' has malformed BBCode urls", $this->id));
241
+                if ( isset($matches[1]) ) {
242
+                                    return "[" . $matches[1] . "](" . $matches[1] . ")";
243
+                } else {
244
+                                    throw new \RuntimeException(sprintf("Text identified by '%d' has malformed BBCode urls", $this->id));
245
+                }
240 246
             },
241 247
             
242 248
             $this->text
@@ -254,10 +260,11 @@  discard block
 block discarded – undo
254 260
         $this->text = preg_replace_callback('%\[img\s*\]\s*("(?:[^"]*")|\A[^\']*\Z|(?:[^\'">\]\s]+))\s*(?:[^]\s]*)\[/img\]%iu',
255 261
             
256 262
             function ($matches) {
257
-                if ( isset($matches[1]) )
258
-                    return PHP_EOL . "![]" . "(" . $matches[1] . ")" . PHP_EOL;
259
-                else
260
-                    throw new \RuntimeException(sprintf("Text identified by '%d' have malformed BBCode images", $this->id));
263
+                if ( isset($matches[1]) ) {
264
+                                    return PHP_EOL . "![]" . "(" . $matches[1] . ")" . PHP_EOL;
265
+                } else {
266
+                                    throw new \RuntimeException(sprintf("Text identified by '%d' have malformed BBCode images", $this->id));
267
+                }
261 268
             },
262 269
             
263 270
             $this->text
@@ -300,34 +307,36 @@  discard block
 block discarded – undo
300 307
                 if ( isset($matches['snippet']) ) {
301 308
                     $language = strtolower($matches['language']);
302 309
                     
303
-                    if ( $language == 'html4strict' or $language == 'div' )
304
-                        $language = 'html';
305
-                    elseif ( $language == 'shell' or $language == 'dos' or $language == 'batch' )
306
-                        $language = 'sh';
307
-                    elseif ( $language == 'xul' or $language == 'wpf' )
308
-                        $language = 'xml';
309
-                    elseif ( $language == 'asm' )
310
-                        $language = 'nasm';
311
-                    elseif ( $language == 'vb' or $language == 'visualbasic' or $language == 'vba' )
312
-                        $language = 'vb.net';
313
-                    elseif ( $language == 'asp' )
314
-                        $language = 'aspx-vb';
315
-                    elseif ( $language == 'xaml' )
316
-                        $language = 'xml';
317
-                    elseif ( $language == 'cplusplus' )
318
-                        $language = 'cpp';
319
-                    elseif ( $language == 'txt' or $language == 'gettext' )
320
-                        $language = 'text';
321
-                    elseif ( $language == 'basic' )
322
-                        $language = 'cbmbas';
323
-                    elseif ( $language == 'lisp' )
324
-                        $language = 'clojure';
325
-                    elseif ( $language == 'aspnet' )
326
-                        $language = 'aspx-vb';
310
+                    if ( $language == 'html4strict' or $language == 'div' ) {
311
+                                            $language = 'html';
312
+                    } elseif ( $language == 'shell' or $language == 'dos' or $language == 'batch' ) {
313
+                                            $language = 'sh';
314
+                    } elseif ( $language == 'xul' or $language == 'wpf' ) {
315
+                                            $language = 'xml';
316
+                    } elseif ( $language == 'asm' ) {
317
+                                            $language = 'nasm';
318
+                    } elseif ( $language == 'vb' or $language == 'visualbasic' or $language == 'vba' ) {
319
+                                            $language = 'vb.net';
320
+                    } elseif ( $language == 'asp' ) {
321
+                                            $language = 'aspx-vb';
322
+                    } elseif ( $language == 'xaml' ) {
323
+                                            $language = 'xml';
324
+                    } elseif ( $language == 'cplusplus' ) {
325
+                                            $language = 'cpp';
326
+                    } elseif ( $language == 'txt' or $language == 'gettext' ) {
327
+                                            $language = 'text';
328
+                    } elseif ( $language == 'basic' ) {
329
+                                            $language = 'cbmbas';
330
+                    } elseif ( $language == 'lisp' ) {
331
+                                            $language = 'clojure';
332
+                    } elseif ( $language == 'aspnet' ) {
333
+                                            $language = 'aspx-vb';
334
+                    }
327 335
                     
328 336
                     return PHP_EOL . "```" . $language . PHP_EOL . trim($matches['snippet']) . PHP_EOL . "```" . PHP_EOL;
329
-                } else
330
-                    throw new \RuntimeException(sprintf("Text identified by '%d' has malformed BBCode snippet.", $this->id));
337
+                } else {
338
+                                    throw new \RuntimeException(sprintf("Text identified by '%d' has malformed BBCode snippet.", $this->id));
339
+                }
331 340
             },
332 341
             
333 342
             $this->text
Please login to merge, or discard this patch.