Completed
Push — master ( 49203d...7671d2 )
by Filippo
02:23
created
src/Converter/HTMLConverter.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 
64 64
     $this->text = preg_replace_callback('%<a[^>]+>(.+?)</a>%iu',
65 65
 
66
-      function ($matches) {
66
+      function($matches) {
67 67
 
68 68
         // Extracts the url.
69 69
         if (preg_match('/\s*href\s*=\s*("([^"]*")|\'[^\']*\'|([^\'">\s]+))/iu', $matches[0], $others) === 1) {
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
   protected function replaceImages() {
95 95
     $this->text = preg_replace_callback('/<img[^>]+>/iu',
96 96
 
97
-      function ($matches) {
97
+      function($matches) {
98 98
 
99 99
         // Extracts the src.
100 100
         if (preg_match('/\s*src\s*=\s*("([^"]*")|\'[^\']*\'|([^\'">\s]+))/iu', $matches[0], $others) === 1)
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
   protected function replaceOtherTags() {
119 119
     $this->text = preg_replace_callback('%</?[a-z][a-z0-9]*[^<>]*>%iu',
120 120
 
121
-      function ($matches) {
121
+      function($matches) {
122 122
         $tag = strtolower($matches[0]);
123 123
 
124 124
         switch ($tag) {
Please login to merge, or discard this 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 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 
24 24
     $this->text = preg_replace_callback('%\[size=\d*\]([\W\D\w\s]*?)\[/size\]%iu',
25 25
 
26
-      function ($matches) {
26
+      function($matches) {
27 27
         return $matches[1];
28 28
       },
29 29
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 
41 41
     $this->text = preg_replace_callback('%\[center\]([\W\D\w\s]*?)\[/center\]%iu',
42 42
 
43
-      function ($matches) {
43
+      function($matches) {
44 44
         return $matches[1];
45 45
       },
46 46
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 
58 58
     $this->text = preg_replace_callback('%\[b\]([\W\D\w\s]*?)\[/b\]%iu',
59 59
 
60
-      function ($matches) {
60
+      function($matches) {
61 61
         return "**".trim($matches[1], " ")."**";
62 62
       },
63 63
 
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 
75 75
     $this->text = preg_replace_callback('%\[i\]([\W\D\w\s]*?)\[/i\]%iu',
76 76
 
77
-      function ($matches) {
77
+      function($matches) {
78 78
         return "*".trim($matches[1], " ")."*";
79 79
       },
80 80
 
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 
92 92
     $this->text = preg_replace_callback('%\[u\]([\W\D\w\s]*?)\[/u\]%iu',
93 93
 
94
-      function ($matches) {
94
+      function($matches) {
95 95
         return "_".trim($matches[1], " ")."_";
96 96
       },
97 97
 
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 
109 109
     $this->text = preg_replace_callback('%\[s\]([\W\D\w\s]*?)\[/s\]%iu',
110 110
 
111
-      function ($matches) {
111
+      function($matches) {
112 112
         return "~~".trim($matches[1], " ")."~~";
113 113
       },
114 114
 
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 
126 126
     $this->text = preg_replace_callback('%\[list(?P<type>=1)?\](?P<items>[\W\D\w\s]*?)\[/list\]%iu',
127 127
 
128
-      function ($matches) {
128
+      function($matches) {
129 129
         $buffer = "";
130 130
 
131 131
         $list = preg_replace('/\s*$|^\s*/mu', '', $matches['items']);
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
     
170 170
     $this->text = preg_replace_callback('%\[url\s*=\s*("(?:[^"]*")|\A[^\']*\Z|(?:[^\'">\]\s]+))\s*(?:[^]\s]*)\]([\W\D\w\s]*?)\[/url\]%iu',
171 171
 
172
-      function ($matches) {
172
+      function($matches) {
173 173
         if (isset($matches[1]) && isset($matches[2]))
174 174
           return "[".$matches[2]."](".$matches[1].")";
175 175
         else
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 
190 190
     $this->text = preg_replace_callback('%\[img\s*\]\s*("(?:[^"]*")|\A[^\']*\Z|(?:[^\'">\]\s]+))\s*(?:[^]\s]*)\[/img\]%iu',
191 191
 
192
-      function ($matches) {
192
+      function($matches) {
193 193
         if (isset($matches[1]))
194 194
           return PHP_EOL."![]"."(".$matches[1].")".PHP_EOL;
195 195
         else
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 
231 231
     $this->text = preg_replace_callback('%\[code\s*=?(?P<language>\w*)\](?P<snippet>[\W\D\w\s]*?)\[\/code\]%iu',
232 232
 
233
-      function ($matches) {
233
+      function($matches) {
234 234
         if (isset($matches['snippet'])) {
235 235
           $language = strtolower($matches['language']);
236 236
 
Please login to merge, or discard this 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.