Passed
Branch master (522b1b)
by MOHAMMAD
02:11
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 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
             $text = $this->text;
53 53
         }
54 54
 
55
-        if ( ! $text) {
55
+        if (!$text) {
56 56
             return $text;
57 57
         }
58 58
 
@@ -74,9 +74,9 @@  discard block
 block discarded – undo
74 74
      */
75 75
     protected function removeColor()
76 76
     {
77
-        $this->cleaners['removeColor'] = function ($text) {
77
+        $this->cleaners['removeColor'] = function($text) {
78 78
             return preg_replace_callback('%\[color=\#?\w+\]([\W\D\w\s]*?)\[/color\]%iu',
79
-                function ($matches) {
79
+                function($matches) {
80 80
                     return $matches[1];
81 81
                 },
82 82
 
@@ -90,9 +90,9 @@  discard block
 block discarded – undo
90 90
      */
91 91
     protected function removeSize()
92 92
     {
93
-        $this->cleaners['removeSize'] = function ($text) {
93
+        $this->cleaners['removeSize'] = function($text) {
94 94
             return preg_replace_callback('%\[size=\d*\]([\W\D\w\s]*?)\[/size\]%iu',
95
-                function ($matches) {
95
+                function($matches) {
96 96
                     return $matches[1];
97 97
                 },
98 98
 
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
      */
107 107
     protected function removeCenter()
108 108
     {
109
-        $this->cleaners['removeCenter'] = function ($text) {
109
+        $this->cleaners['removeCenter'] = function($text) {
110 110
             return preg_replace_callback('%\[center\]([\W\D\w\s]*?)\[/center\]%iu',
111
-                function ($matches) {
111
+                function($matches) {
112 112
                     return $matches[1];
113 113
                 },
114 114
 
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
      */
123 123
     protected function replaceBold()
124 124
     {
125
-        $this->cleaners['replaceBold'] = function ($text) {
125
+        $this->cleaners['replaceBold'] = function($text) {
126 126
             return preg_replace_callback('%\[b\]([\W\D\w\s]*?)\[/b\]%iu',
127
-                function ($matches) {
127
+                function($matches) {
128 128
                     return '**'.trim($matches[1], ' ').'**';
129 129
                 },
130 130
 
@@ -138,9 +138,9 @@  discard block
 block discarded – undo
138 138
      */
139 139
     protected function replaceItalic()
140 140
     {
141
-        $this->cleaners['replaceItalic'] = function ($text) {
141
+        $this->cleaners['replaceItalic'] = function($text) {
142 142
             return preg_replace_callback('%\[i\]([\W\D\w\s]*?)\[/i\]%iu',
143
-                function ($matches) {
143
+                function($matches) {
144 144
                     return '*'.trim($matches[1], ' ').'*';
145 145
                 },
146 146
 
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
      */
155 155
     protected function replaceUnderline()
156 156
     {
157
-        $this->cleaners['replaceUnderline'] = function ($text) {
157
+        $this->cleaners['replaceUnderline'] = function($text) {
158 158
             return preg_replace_callback('%\[u\]([\W\D\w\s]*?)\[/u\]%iu',
159
-                function ($matches) {
159
+                function($matches) {
160 160
                     return '_'.trim($matches[1], ' ').'_';
161 161
                 },
162 162
 
@@ -170,9 +170,9 @@  discard block
 block discarded – undo
170 170
      */
171 171
     protected function replaceStrikethrough()
172 172
     {
173
-        $this->cleaners['replaceStrikethrough'] = function ($text) {
173
+        $this->cleaners['replaceStrikethrough'] = function($text) {
174 174
             return preg_replace_callback('%\[s\]([\W\D\w\s]*?)\[/s\]%iu',
175
-                function ($matches) {
175
+                function($matches) {
176 176
                     return '~~'.trim($matches[1], ' ').'~~';
177 177
                 },
178 178
 
@@ -186,9 +186,9 @@  discard block
 block discarded – undo
186 186
      */
187 187
     protected function replaceLists()
188 188
     {
189
-        $this->cleaners['replaceLists'] = function ($text, $id = null) {
189
+        $this->cleaners['replaceLists'] = function($text, $id = null) {
190 190
             return preg_replace_callback('%\[list(?P<type>=1)?\](?P<items>[\W\D\w\s]*?)\[/list\]%iu',
191
-                function ($matches) use ($id) {
191
+                function($matches) use ($id) {
192 192
                     $buffer = '';
193 193
 
194 194
                     $list = preg_replace('/\s*$|^\s*/mu', '', $matches['items']);
@@ -202,21 +202,21 @@  discard block
 block discarded – undo
202 202
                     if (isset($matches['type']) && '=1' == $matches['type']) { // ordered list
203 203
                         // We start from 1 to discard the first string, in fact, it's empty.
204 204
                         for ($i = 1; $i < $counter; ++$i) {
205
-                            if ( ! empty($items[$i])) {
205
+                            if (!empty($items[$i])) {
206 206
                                 $buffer .= (string) ($i).'. '.trim($items[$i]).PHP_EOL;
207 207
                             }
208 208
                         }
209 209
                     } else { // unordered list
210 210
                         // We start from 1 to discard the first string, in fact, it's empty.
211 211
                         for ($i = 1; $i < $counter; ++$i) {
212
-                            if ( ! empty($items[$i])) {
212
+                            if (!empty($items[$i])) {
213 213
                                 $buffer .= '- '.trim($items[$i]).PHP_EOL;
214 214
                             }
215 215
                         }
216 216
                     }
217 217
 
218 218
                     // We need a like break above the list and another one below.
219
-                    if ( ! empty($buffer)) {
219
+                    if (!empty($buffer)) {
220 220
                         $buffer = PHP_EOL.$buffer.PHP_EOL;
221 221
                     }
222 222
 
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
      */
234 234
     protected function replaceUrls()
235 235
     {
236
-        $this->cleaners['replaceUrls'] = function ($text, $id = null) {
236
+        $this->cleaners['replaceUrls'] = function($text, $id = null) {
237 237
             return preg_replace_callback('%\[url\s*=\s*("(?:[^"]*")|\A[^\']*\Z|(?:[^\'">\]\s]+))\s*(?:[^]\s]*)\]([\W\D\w\s]*?)\[/url\]%iu',
238
-                function ($matches) use ($id) {
238
+                function($matches) use ($id) {
239 239
                     if (isset($matches[1]) && isset($matches[2])) {
240 240
                         return '['.$matches[2].']('.$matches[1].')';
241 241
                     }
@@ -253,9 +253,9 @@  discard block
 block discarded – undo
253 253
      */
254 254
     protected function replaceImages()
255 255
     {
256
-        $this->cleaners['replaceImages'] = function ($text, $id = null) {
256
+        $this->cleaners['replaceImages'] = function($text, $id = null) {
257 257
             return preg_replace_callback('%\[img\s*\]\s*("(?:[^"]*")|\A[^\']*\Z|(?:[^\'">\]\s]+))\s*(?:[^]\s]*)\[/img\]%iu',
258
-                function ($matches) use ($id) {
258
+                function($matches) use ($id) {
259 259
                     if (isset($matches[1])) {
260 260
                         return PHP_EOL.'![]'.'('.$matches[1].')'.PHP_EOL;
261 261
                     }
@@ -274,13 +274,13 @@  discard block
 block discarded – undo
274 274
      */
275 275
     protected function replaceQuotes()
276 276
     {
277
-        $this->cleaners['replaceQuotes'] = function ($text, $id = null) {
277
+        $this->cleaners['replaceQuotes'] = function($text, $id = null) {
278 278
             // Removes the inner quotes, leaving just one level.
279 279
             $text = preg_replace('~\G(?<!^)(?>(\[quote\b[^]]*](?>[^[]++|\[(?!/?quote)|(?1))*\[/quote])|(?<!\[)(?>[^[]++|\[(?!/?quote))+\K)|\[quote\b[^]]*]\K~i', '', $text);
280 280
 
281 281
             // Replaces all the remaining quotes with '> ' characters.
282 282
             $text = preg_replace_callback('%\[quote\b[^]]*\]((?>[^[]++|\[(?!/?quote))*)\[/quote\]%i',
283
-                function ($matches) {
283
+                function($matches) {
284 284
                     $quote = preg_replace('/^\s*/mu', '', trim($matches[1]));
285 285
 
286 286
                     return '> '.$quote.PHP_EOL.PHP_EOL;
@@ -298,9 +298,9 @@  discard block
 block discarded – undo
298 298
      */
299 299
     protected function replaceSnippets()
300 300
     {
301
-        $this->cleaners['replaceSnippets'] = function ($text, $id = null) {
301
+        $this->cleaners['replaceSnippets'] = function($text, $id = null) {
302 302
             return preg_replace_callback('%\[code\s*=?(?P<language>\w*)\](?P<snippet>[\W\D\w\s]*?)\[\/code\]%iu',
303
-                function ($matches) use ($id) {
303
+                function($matches) use ($id) {
304 304
                     if (isset($matches['snippet'])) {
305 305
                         $language = strtolower($matches['language']);
306 306
 
Please login to merge, or discard this patch.