Completed
Branch 1.11.x (83359d)
by Ben
18s
created
classes/PHPTAL/Tokenizer.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,9 @@
 block discarded – undo
42 42
 
43 43
     function skipSpace()
44 44
     {
45
-        while ($this->current_token === 'SPACE') $this->nextToken();
45
+        while ($this->current_token === 'SPACE') {
46
+            $this->nextToken();
47
+        }
46 48
     }
47 49
 
48 50
     function nextToken()
Please login to merge, or discard this patch.
classes/PHPTAL/Dom/SaxXmlParser.php 3 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -60,23 +60,23 @@  discard block
 block discarded – undo
60 60
 
61 61
 
62 62
     static $state_names = array(
63
-      self::ST_ROOT => 'root node',
64
-      self::ST_TEXT => 'text',
65
-      self::ST_LT   => 'start of tag',
66
-      self::ST_TAG_NAME => 'tag name',
67
-      self::ST_TAG_CLOSE => 'closing tag',
68
-      self::ST_TAG_SINGLE => 'self-closing tag',
69
-      self::ST_TAG_ATTRIBUTES => 'tag',
70
-      self::ST_TAG_BETWEEN_ATTRIBUTE => 'tag attributes',
71
-      self::ST_CDATA => 'CDATA',
72
-      self::ST_COMMENT => 'comment',
73
-      self::ST_DOCTYPE => 'doctype',
74
-      self::ST_XMLDEC => 'XML declaration',
75
-      self::ST_PREPROC => 'preprocessor directive',
76
-      self::ST_ATTR_KEY => 'attribute name',
77
-      self::ST_ATTR_EQ => 'attribute value',
78
-      self::ST_ATTR_QUOTE => 'quoted attribute value',
79
-      self::ST_ATTR_VALUE => 'unquoted attribute value',
63
+        self::ST_ROOT => 'root node',
64
+        self::ST_TEXT => 'text',
65
+        self::ST_LT   => 'start of tag',
66
+        self::ST_TAG_NAME => 'tag name',
67
+        self::ST_TAG_CLOSE => 'closing tag',
68
+        self::ST_TAG_SINGLE => 'self-closing tag',
69
+        self::ST_TAG_ATTRIBUTES => 'tag',
70
+        self::ST_TAG_BETWEEN_ATTRIBUTE => 'tag attributes',
71
+        self::ST_CDATA => 'CDATA',
72
+        self::ST_COMMENT => 'comment',
73
+        self::ST_DOCTYPE => 'doctype',
74
+        self::ST_XMLDEC => 'XML declaration',
75
+        self::ST_PREPROC => 'preprocessor directive',
76
+        self::ST_ATTR_KEY => 'attribute name',
77
+        self::ST_ATTR_EQ => 'attribute value',
78
+        self::ST_ATTR_QUOTE => 'quoted attribute value',
79
+        self::ST_ATTR_VALUE => 'unquoted attribute value',
80 80
     );
81 81
 
82 82
     private $input_encoding;
@@ -381,15 +381,15 @@  discard block
 block discarded – undo
381 381
 
382 382
             // http://www.w3.org/International/questions/qa-forms-utf-8
383 383
             $match = '[\x09\x0A\x0D\x20-\x7F]'        // ASCII
384
-               . '|[\xC2-\xDF][\x80-\xBF]'            // non-overlong 2-byte
385
-               . '|\xE0[\xA0-\xBF][\x80-\xBF]'        // excluding overlongs
386
-               . '|[\xE1-\xEC\xEE\xEE][\x80-\xBF]{2}' // straight 3-byte (exclude FFFE and FFFF)
387
-               . '|\xEF[\x80-\xBE][\x80-\xBF]'        // straight 3-byte
388
-               . '|\xEF\xBF[\x80-\xBD]'               // straight 3-byte
389
-               . '|\xED[\x80-\x9F][\x80-\xBF]'        // excluding surrogates
390
-               . '|\xF0[\x90-\xBF][\x80-\xBF]{2}'     // planes 1-3
391
-               . '|[\xF1-\xF3][\x80-\xBF]{3}'         // planes 4-15
392
-               . '|\xF4[\x80-\x8F][\x80-\xBF]{2}';    // plane 16
384
+                . '|[\xC2-\xDF][\x80-\xBF]'            // non-overlong 2-byte
385
+                . '|\xE0[\xA0-\xBF][\x80-\xBF]'        // excluding overlongs
386
+                . '|[\xE1-\xEC\xEE\xEE][\x80-\xBF]{2}' // straight 3-byte (exclude FFFE and FFFF)
387
+                . '|\xEF[\x80-\xBE][\x80-\xBF]'        // straight 3-byte
388
+                . '|\xEF\xBF[\x80-\xBD]'               // straight 3-byte
389
+                . '|\xED[\x80-\x9F][\x80-\xBF]'        // excluding surrogates
390
+                . '|\xF0[\x90-\xBF][\x80-\xBF]{2}'     // planes 1-3
391
+                . '|[\xF1-\xF3][\x80-\xBF]{3}'         // planes 4-15
392
+                . '|\xF4[\x80-\x8F][\x80-\xBF]{2}';    // plane 16
393 393
 
394 394
             if (!preg_match('/^(?:(?>'.$match.'))+$/s',$str)) {
395 395
                 $res = preg_split('/((?>'.$match.')+)/s',$str,0,PREG_SPLIT_DELIM_CAPTURE);
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -116,12 +116,12 @@  discard block
 block discarded – undo
116 116
             $builder->setSource($this->_file, $this->_line);
117 117
             $builder->onDocumentStart();
118 118
 
119
-            $i=0;
119
+            $i = 0;
120 120
             // remove BOM (UTF-8 byte order mark)...
121 121
             if (substr($src, 0, 3) === self::BOM_STR) {
122
-                $i=3;
122
+                $i = 3;
123 123
             }
124
-            for (; $i<$len; $i++) {
124
+            for (; $i < $len; $i++) {
125 125
                 $c = $src[$i]; // Change to substr($src, $i, 1); if you want to use mb_string.func_overload
126 126
 
127 127
                 if ($c === "\n") $builder->setSource($this->_file, ++$this->_line);
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
                         if ($c !== '>') {
202 202
                             $this->raiseError("Expected '/>', but found '/$c' inside tag < $tagname >");
203 203
                         }
204
-                        $mark = $i+1;   // mark text start
204
+                        $mark = $i+1; // mark text start
205 205
                         $state = self::ST_TEXT;
206 206
                         $builder->onElementStart($tagname, $attributes);
207 207
                         $builder->onElementClose($tagname);
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
                     case self::ST_TAG_BETWEEN_ATTRIBUTE:
211 211
                     case self::ST_TAG_ATTRIBUTES:
212 212
                         if ($c === '>') {
213
-                            $mark = $i+1;   // mark text start
213
+                            $mark = $i+1; // mark text start
214 214
                             $state = self::ST_TEXT;
215 215
                             $builder->onElementStart($tagname, $attributes);
216 216
                         } elseif ($c === '/') {
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
                     case self::ST_COMMENT:
227 227
                         if ($c === '>' && $i > $mark+4 && substr($src, $i-2, 2) === '--') {
228 228
 
229
-                            if (preg_match('/^-|--|-$/', substr($src, $mark +4, $i-$mark+1 -7))) {
229
+                            if (preg_match('/^-|--|-$/', substr($src, $mark+4, $i-$mark+1-7))) {
230 230
                                 $this->raiseError("Ill-formed comment. XML comments are not allowed to contain '--' or start/end with '-': ".substr($src, $mark+4, $i-$mark+1-7));
231 231
                             }
232 232
 
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 
290 290
                             if ($c === '=') $state = self::ST_ATTR_VALUE;
291 291
                             else /* white char */ $state = self::ST_ATTR_EQ;
292
-                        } elseif ($c === '/' || $c==='>') {
292
+                        } elseif ($c === '/' || $c === '>') {
293 293
                             $attribute = substr($src, $mark, $i-$mark);
294 294
                             if (!$this->isValidQName($attribute)) {
295 295
                                 $this->raiseError("Invalid attribute name '$attribute'");
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
 
324 324
                             // PHPTAL's code generator assumes input is escaped for double-quoted strings. Single-quoted attributes need to be converted.
325 325
                             // FIXME: it should be escaped at later stage.
326
-                            $attributes[$attribute] = str_replace('"',"&quot;", $attributes[$attribute]);
326
+                            $attributes[$attribute] = str_replace('"', "&quot;", $attributes[$attribute]);
327 327
                             $state = self::ST_TAG_BETWEEN_ATTRIBUTE;
328 328
                         }
329 329
                         break;
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 
348 348
             $builder->onDocumentEnd();
349 349
         }
350
-        catch(PHPTAL_TemplateException $e)
350
+        catch (PHPTAL_TemplateException $e)
351 351
         {
352 352
             $e->hintSrcPosition($this->_file, $this->_line);
353 353
             throw $e;
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
             // $match expression below somehow triggers quite deep recurrency and stack overflow in preg
371 371
             // to avoid this, check string bit by bit, omitting ASCII fragments.
372 372
             if (strlen($str) > 200) {
373
-                $chunks = preg_split('/(?>[\x09\x0A\x0D\x20-\x7F]+)/',$str,0,PREG_SPLIT_NO_EMPTY);
373
+                $chunks = preg_split('/(?>[\x09\x0A\x0D\x20-\x7F]+)/', $str, 0, PREG_SPLIT_NO_EMPTY);
374 374
                 foreach ($chunks as $chunk) {
375 375
                     if (strlen($chunk) < 200) {
376 376
                         $this->checkEncoding($chunk);
@@ -389,11 +389,11 @@  discard block
 block discarded – undo
389 389
                . '|\xED[\x80-\x9F][\x80-\xBF]'        // excluding surrogates
390 390
                . '|\xF0[\x90-\xBF][\x80-\xBF]{2}'     // planes 1-3
391 391
                . '|[\xF1-\xF3][\x80-\xBF]{3}'         // planes 4-15
392
-               . '|\xF4[\x80-\x8F][\x80-\xBF]{2}';    // plane 16
392
+               . '|\xF4[\x80-\x8F][\x80-\xBF]{2}'; // plane 16
393 393
 
394
-            if (!preg_match('/^(?:(?>'.$match.'))+$/s',$str)) {
395
-                $res = preg_split('/((?>'.$match.')+)/s',$str,0,PREG_SPLIT_DELIM_CAPTURE);
396
-                for($i=0; $i < count($res); $i+=2)
394
+            if (!preg_match('/^(?:(?>'.$match.'))+$/s', $str)) {
395
+                $res = preg_split('/((?>'.$match.')+)/s', $str, 0, PREG_SPLIT_DELIM_CAPTURE);
396
+                for ($i = 0; $i < count($res); $i += 2)
397 397
                 {
398 398
                     $res[$i] = self::convertBytesToEntities(array(1=>$res[$i]));
399 399
                 }
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
             $forbid = '/((?>[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F]+))/s';
407 407
 
408 408
             if (preg_match($forbid, $str)) {
409
-                $str = preg_replace_callback($forbid, static function (array $m): string {
409
+                $str = preg_replace_callback($forbid, static function(array $m): string {
410 410
                     return self::convertBytesToEntities($m);
411 411
                 }, $str);
412 412
                 $this->raiseError("Invalid ISO-8859-1 characters: ".$str);
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
     {
427 427
         $m = $m[1];
428 428
         $out = "";
429
-        for($i=0; $i < strlen($m); $i++)
429
+        for ($i = 0; $i < strlen($m); $i++)
430 430
         {
431 431
             $out .= '&#X'.strtoupper(dechex(ord($m[$i]))).';';
432 432
         }
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
         /* <?php ?> blocks can't reliably work in attributes (due to escaping impossible in XML)
444 444
            so they have to be converted into special TALES expression
445 445
         */
446
-        $str = preg_replace_callback('/<\?(php|=)(.*?)\?>/', static function ($m) {
446
+        $str = preg_replace_callback('/<\?(php|=)(.*?)\?>/', static function($m) {
447 447
             list(, $type, $code) = $m;
448 448
             if ($type === '=') $code = 'echo '.$code;
449 449
             return '${structure phptal-internal-php-block:'.rawurlencode($code).'}';
Please login to merge, or discard this patch.
Braces   +27 added lines, -11 removed lines patch added patch discarded remove patch
@@ -124,7 +124,9 @@  discard block
 block discarded – undo
124 124
             for (; $i<$len; $i++) {
125 125
                 $c = $src[$i]; // Change to substr($src, $i, 1); if you want to use mb_string.func_overload
126 126
 
127
-                if ($c === "\n") $builder->setSource($this->_file, ++$this->_line);
127
+                if ($c === "\n") {
128
+                    $builder->setSource($this->_file, ++$this->_line);
129
+                }
128 130
 
129 131
                 switch ($state) {
130 132
                     case self::ST_ROOT:
@@ -174,7 +176,9 @@  discard block
 block discarded – undo
174 176
                     case self::ST_TAG_NAME:
175 177
                         if (self::isWhiteChar($c) || $c === '/' || $c === '>') {
176 178
                             $tagname = substr($src, $mark, $i-$mark);
177
-                            if (!$this->isValidQName($tagname)) $this->raiseError("Invalid tag name '$tagname'");
179
+                            if (!$this->isValidQName($tagname)) {
180
+                                $this->raiseError("Invalid tag name '$tagname'");
181
+                            }
178 182
 
179 183
                             if ($c === '/') {
180 184
                                 $state = self::ST_TAG_SINGLE;
@@ -220,7 +224,9 @@  discard block
 block discarded – undo
220 224
                         } elseif ($state === self::ST_TAG_ATTRIBUTES && $this->isValidQName($c)) {
221 225
                             $mark = $i; // mark attribute key start
222 226
                             $state = self::ST_ATTR_KEY;
223
-                        } else $this->raiseError("Unexpected character '$c' between attributes of < $tagname >");
227
+                        } else {
228
+                            $this->raiseError("Unexpected character '$c' between attributes of < $tagname >");
229
+                        }
224 230
                         break;
225 231
 
226 232
                     case self::ST_COMMENT:
@@ -287,8 +293,11 @@  discard block
 block discarded – undo
287 293
                                 $this->raiseError("Attribute $attribute in < $tagname > is defined more than once");
288 294
                             }
289 295
 
290
-                            if ($c === '=') $state = self::ST_ATTR_VALUE;
291
-                            else /* white char */ $state = self::ST_ATTR_EQ;
296
+                            if ($c === '=') {
297
+                                $state = self::ST_ATTR_VALUE;
298
+                            } else {
299
+                                /* white char */ $state = self::ST_ATTR_EQ;
300
+                            }
292 301
                         } elseif ($c === '/' || $c==='>') {
293 302
                             $attribute = substr($src, $mark, $i-$mark);
294 303
                             if (!$this->isValidQName($attribute)) {
@@ -330,11 +339,15 @@  discard block
 block discarded – undo
330 339
                 }
331 340
             }
332 341
 
333
-            if ($state === self::ST_TEXT) // allows text past root node, which is in violation of XML spec
342
+            if ($state === self::ST_TEXT) {
343
+                // allows text past root node, which is in violation of XML spec
334 344
             {
335 345
                 if ($i > $mark) {
336 346
                     $text = substr($src, $mark, $i-$mark);
337
-                    if (!ctype_space($text)) $this->raiseError("Characters found after end of the root element (wrap document in < tal:block > to avoid this error)");
347
+            }
348
+                    if (!ctype_space($text)) {
349
+                        $this->raiseError("Characters found after end of the root element (wrap document in < tal:block > to avoid this error)");
350
+                    }
338 351
                 }
339 352
             } else {
340 353
                 if ($state === self::ST_ROOT) {
@@ -346,8 +359,7 @@  discard block
 block discarded – undo
346 359
             }
347 360
 
348 361
             $builder->onDocumentEnd();
349
-        }
350
-        catch(PHPTAL_TemplateException $e)
362
+        } catch(PHPTAL_TemplateException $e)
351 363
         {
352 364
             $e->hintSrcPosition($this->_file, $this->_line);
353 365
             throw $e;
@@ -363,7 +375,9 @@  discard block
 block discarded – undo
363 375
 
364 376
     private function checkEncoding($str)
365 377
     {
366
-        if ($str === '') return '';
378
+        if ($str === '') {
379
+            return '';
380
+        }
367 381
 
368 382
         if ($this->input_encoding === 'UTF-8') {
369 383
 
@@ -445,7 +459,9 @@  discard block
 block discarded – undo
445 459
         */
446 460
         $str = preg_replace_callback('/<\?(php|=)(.*?)\?>/', static function ($m) {
447 461
             list(, $type, $code) = $m;
448
-            if ($type === '=') $code = 'echo '.$code;
462
+            if ($type === '=') {
463
+                $code = 'echo '.$code;
464
+            }
449 465
             return '${structure phptal-internal-php-block:'.rawurlencode($code).'}';
450 466
         }, $str);
451 467
 
Please login to merge, or discard this patch.