Completed
Push — master ( 49203d...7671d2 )
by Filippo
02:23
created
src/Converter/HTMLConverter.php 1 patch
Braces   +19 added lines, -16 removed lines patch added patch discarded remove patch
@@ -44,12 +44,13 @@  discard block
 block discarded – undo
44 44
 
45 45
     for ($i = 0; $i < $snippetsCount; $i++) {
46 46
       // We try to determine which tags the code is inside: <pre></pre>, <code></code>, [code][/code]
47
-      if (!empty($this->snippets['openpre'][$i]))
48
-        $snippet = "[code]".PHP_EOL.trim($this->snippets['contentpre'][$i]).PHP_EOL."[/code]";
49
-      elseif (!empty($this->snippets['opencode'][$i]))
50
-        $snippet = "[code]".PHP_EOL.trim($this->snippets['contentcode'][$i]).PHP_EOL."[/code]";
51
-      else
52
-        $snippet = $this->snippets['openbbcode'][$i].PHP_EOL.trim($this->snippets['contentbbcode'][$i]).PHP_EOL.$this->snippets['closebbcode'][$i];
47
+      if (!empty($this->snippets['openpre'][$i])) {
48
+              $snippet = "[code]".PHP_EOL.trim($this->snippets['contentpre'][$i]).PHP_EOL."[/code]";
49
+      } elseif (!empty($this->snippets['opencode'][$i])) {
50
+              $snippet = "[code]".PHP_EOL.trim($this->snippets['contentcode'][$i]).PHP_EOL."[/code]";
51
+      } else {
52
+              $snippet = $this->snippets['openbbcode'][$i].PHP_EOL.trim($this->snippets['contentbbcode'][$i]).PHP_EOL.$this->snippets['closebbcode'][$i];
53
+      }
53 54
 
54 55
       $this->text = preg_replace('/___SNIPPET___/', PHP_EOL.trim($snippet).PHP_EOL, $this->text, 1);
55 56
     }
@@ -70,13 +71,14 @@  discard block
 block discarded – undo
70 71
           $href = trim($others[1], '"');
71 72
 
72 73
           // Extracts the target.
73
-          if (preg_match('/\s*target\s*=\s*("([^"]*")|\'[^\']*\'|([^\'">\s]+))/iu', $matches[0], $others) === 1)
74
-            $target = strtolower(trim($others[1], '"'));
75
-          else
76
-            $target = "_self";
74
+          if (preg_match('/\s*target\s*=\s*("([^"]*")|\'[^\']*\'|([^\'">\s]+))/iu', $matches[0], $others) === 1) {
75
+                      $target = strtolower(trim($others[1], '"'));
76
+          } else {
77
+                      $target = "_self";
78
+          }
79
+        } else {
80
+                  throw new \RuntimeException(sprintf("Text identified by '%d' has malformed links", $this->id));
77 81
         }
78
-        else
79
-          throw new \RuntimeException(sprintf("Text identified by '%d' has malformed links", $this->id));
80 82
 
81 83
         return "[url=".$href." t=".$target."]".$matches[1]."[/url]";
82 84
 
@@ -97,10 +99,11 @@  discard block
 block discarded – undo
97 99
       function ($matches) {
98 100
 
99 101
         // Extracts the src.
100
-        if (preg_match('/\s*src\s*=\s*("([^"]*")|\'[^\']*\'|([^\'">\s]+))/iu', $matches[0], $others) === 1)
101
-          $src = trim($others[1], '"');
102
-        else
103
-          throw new \RuntimeException(sprintf("Text identified by '%d' has malformed images", $this->id));
102
+        if (preg_match('/\s*src\s*=\s*("([^"]*")|\'[^\']*\'|([^\'">\s]+))/iu', $matches[0], $others) === 1) {
103
+                  $src = trim($others[1], '"');
104
+        } else {
105
+                  throw new \RuntimeException(sprintf("Text identified by '%d' has malformed images", $this->id));
106
+        }
104 107
 
105 108
         return "[img]".$src."[/img]";
106 109
 
Please login to merge, or discard this patch.
src/Converter/BBCodeConverter.php 1 patch
Braces   +50 added lines, -44 removed lines patch added patch discarded remove patch
@@ -129,8 +129,9 @@  discard block
 block discarded – undo
129 129
         $buffer = "";
130 130
 
131 131
         $list = preg_replace('/\s*$|^\s*/mu', '', $matches['items']);
132
-        if (is_null($list))
133
-          throw new \RuntimeException(sprintf("Text identified by '%d' has malformed BBCode lists", $this->id));
132
+        if (is_null($list)) {
133
+                  throw new \RuntimeException(sprintf("Text identified by '%d' has malformed BBCode lists", $this->id));
134
+        }
134 135
 
135 136
         $items = preg_split('/\[\*\]/u', $list);
136 137
 
@@ -138,20 +139,22 @@  discard block
 block discarded – undo
138 139
 
139 140
         if (isset($matches['type']) && $matches['type'] == '=1') { // ordered list
140 141
           // We start from 1 to discard the first string, in fact, it's empty.
141
-          for ($i = 1; $i < $counter; $i++)
142
-            if (!empty($items[$i]))
142
+          for ($i = 1; $i < $counter; $i++) {
143
+                      if (!empty($items[$i]))
143 144
               $buffer .= (string)($i).'. '.trim($items[$i]).PHP_EOL;
144
-        }
145
-        else { // unordered list
145
+          }
146
+        } else { // unordered list
146 147
           // We start from 1 to discard the first string, in fact, it's empty.
147
-          for ($i = 1; $i < $counter; $i++)
148
-            if (!empty($items[$i]))
148
+          for ($i = 1; $i < $counter; $i++) {
149
+                      if (!empty($items[$i]))
149 150
               $buffer .= '- '.trim($items[$i]).PHP_EOL;
151
+          }
150 152
         }
151 153
 
152 154
         // We need a like break above the list and another one below.
153
-        if (!empty($buffer))
154
-          $buffer = PHP_EOL.$buffer.PHP_EOL;
155
+        if (!empty($buffer)) {
156
+                  $buffer = PHP_EOL.$buffer.PHP_EOL;
157
+        }
155 158
 
156 159
         return $buffer;
157 160
       },
@@ -170,10 +173,11 @@  discard block
 block discarded – undo
170 173
     $this->text = preg_replace_callback('%\[url\s*=\s*("(?:[^"]*")|\A[^\']*\Z|(?:[^\'">\]\s]+))\s*(?:[^]\s]*)\]([\W\D\w\s]*?)\[/url\]%iu',
171 174
 
172 175
       function ($matches) {
173
-        if (isset($matches[1]) && isset($matches[2]))
174
-          return "[".$matches[2]."](".$matches[1].")";
175
-        else
176
-          throw new \RuntimeException(sprintf("Text identified by '%d' has malformed BBCode urls", $this->id));
176
+        if (isset($matches[1]) && isset($matches[2])) {
177
+                  return "[".$matches[2]."](".$matches[1].")";
178
+        } else {
179
+                  throw new \RuntimeException(sprintf("Text identified by '%d' has malformed BBCode urls", $this->id));
180
+        }
177 181
       },
178 182
 
179 183
       $this->text
@@ -190,10 +194,11 @@  discard block
 block discarded – undo
190 194
     $this->text = preg_replace_callback('%\[img\s*\]\s*("(?:[^"]*")|\A[^\']*\Z|(?:[^\'">\]\s]+))\s*(?:[^]\s]*)\[/img\]%iu',
191 195
 
192 196
       function ($matches) {
193
-        if (isset($matches[1]))
194
-          return PHP_EOL."![]"."(".$matches[1].")".PHP_EOL;
195
-        else
196
-          throw new \RuntimeException(sprintf("Text identified by '%d' have malformed BBCode images", $this->id));
197
+        if (isset($matches[1])) {
198
+                  return PHP_EOL."![]"."(".$matches[1].")".PHP_EOL;
199
+        } else {
200
+                  throw new \RuntimeException(sprintf("Text identified by '%d' have malformed BBCode images", $this->id));
201
+        }
197 202
       },
198 203
 
199 204
       $this->text
@@ -234,35 +239,36 @@  discard block
 block discarded – undo
234 239
         if (isset($matches['snippet'])) {
235 240
           $language = strtolower($matches['language']);
236 241
 
237
-          if ($language == 'html4strict' or $language == 'div')
238
-            $language = 'html';
239
-          elseif ($language == 'shell' or $language == 'dos' or $language == 'batch')
240
-            $language = 'sh';
241
-          elseif ($language == 'xul' or $language == 'wpf')
242
-            $language = 'xml';
243
-          elseif ($language == 'asm')
244
-            $language = 'nasm';
245
-          elseif ($language == 'vb' or $language == 'visualbasic' or $language == 'vba')
246
-            $language = 'vb.net';
247
-          elseif ($language == 'asp')
248
-            $language = 'aspx-vb';
249
-          elseif ($language == 'xaml')
250
-            $language = 'xml';
251
-          elseif ($language == 'cplusplus')
252
-            $language = 'cpp';
253
-          elseif ($language == 'txt' or $language == 'gettext')
254
-            $language = 'text';
255
-          elseif ($language == 'basic')
256
-            $language = 'cbmbas';
257
-          elseif ($language == 'lisp')
258
-            $language = 'clojure';
259
-          elseif ($language == 'aspnet')
260
-            $language = 'aspx-vb';
242
+          if ($language == 'html4strict' or $language == 'div') {
243
+                      $language = 'html';
244
+          } elseif ($language == 'shell' or $language == 'dos' or $language == 'batch') {
245
+                      $language = 'sh';
246
+          } elseif ($language == 'xul' or $language == 'wpf') {
247
+                      $language = 'xml';
248
+          } elseif ($language == 'asm') {
249
+                      $language = 'nasm';
250
+          } elseif ($language == 'vb' or $language == 'visualbasic' or $language == 'vba') {
251
+                      $language = 'vb.net';
252
+          } elseif ($language == 'asp') {
253
+                      $language = 'aspx-vb';
254
+          } elseif ($language == 'xaml') {
255
+                      $language = 'xml';
256
+          } elseif ($language == 'cplusplus') {
257
+                      $language = 'cpp';
258
+          } elseif ($language == 'txt' or $language == 'gettext') {
259
+                      $language = 'text';
260
+          } elseif ($language == 'basic') {
261
+                      $language = 'cbmbas';
262
+          } elseif ($language == 'lisp') {
263
+                      $language = 'clojure';
264
+          } elseif ($language == 'aspnet') {
265
+                      $language = 'aspx-vb';
266
+          }
261 267
 
262 268
           return PHP_EOL."```".$language.PHP_EOL.trim($matches['snippet']).PHP_EOL."```".PHP_EOL;
269
+        } else {
270
+                  throw new \RuntimeException(sprintf("Text identified by '%d' has malformed BBCode snippet.", $this->id));
263 271
         }
264
-        else
265
-          throw new \RuntimeException(sprintf("Text identified by '%d' has malformed BBCode snippet.", $this->id));
266 272
       },
267 273
 
268 274
       $this->text
Please login to merge, or discard this patch.