Completed
Branch 1.11.x (83359d)
by Ben
18s
created
classes/PHPTAL/Php/TalesInternal.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 
56 56
     static public function true($src, $nothrow)
57 57
     {
58
-        return 'phptal_true(' . self::compileToPHPExpression($src, true) . ')';
58
+        return 'phptal_true('.self::compileToPHPExpression($src, true).')';
59 59
     }
60 60
 
61 61
     /**
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      */
85 85
     static public function not($expression, $nothrow)
86 86
     {
87
-        return '!phptal_true(' . self::compileToPHPExpression($expression, $nothrow) . ')';
87
+        return '!phptal_true('.self::compileToPHPExpression($expression, $nothrow).')';
88 88
     }
89 89
 
90 90
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
      *
122 122
      * @returns string or array
123 123
      */
124
-    static public function path($expression, $nothrow=false)
124
+    static public function path($expression, $nothrow = false)
125 125
     {
126 126
         $expression = trim($expression);
127 127
         if ($expression == 'default') return self::DEFAULT_KEYWORD;
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
         if (count($exps) > 1 || isset($string)) {
147 147
             $result = array();
148 148
             foreach ($exps as $i=>$exp) {
149
-                if(isset($string) || $i < count($exps) - 1) {
149
+                if (isset($string) || $i < count($exps)-1) {
150 150
                     $result[] = self::compileToPHPExpressions(trim($exp), true);
151 151
                 }
152 152
                 else {
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
         }
181 181
 
182 182
         if ($nothrow) {
183
-            return '$ctx->path($ctx, ' . $next . ($expression === null ? '' : '."/".'.$expression) . ', true)';
183
+            return '$ctx->path($ctx, '.$next.($expression === null ? '' : '."/".'.$expression).', true)';
184 184
         }
185 185
 
186 186
         if (preg_match('/^\'[a-z][a-z0-9_]*\'$/i', $next)) $next = substr($next, 1, -1); else $next = '{'.$next.'}';
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
      *      string:hello, ${user/name}
222 222
      *      string:you have $$130 in your bank account
223 223
      */
224
-    static public function string($expression, $nothrow=false)
224
+    static public function string($expression, $nothrow = false)
225 225
     {
226 226
         return self::parseString($expression, $nothrow, '');
227 227
     }
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         $lastWasDollar = false;
242 242
         $result = '';
243 243
         $len = strlen($expression);
244
-        for ($i=0; $i<$len; $i++) {
244
+        for ($i = 0; $i < $len; $i++) {
245 245
             $c = $expression[$i];
246 246
             switch ($c) {
247 247
                 case '$':
@@ -291,8 +291,8 @@  discard block
 block discarded – undo
291 291
                 case '}':
292 292
                     if ($inAccoladePath) {
293 293
                         $inAccoladePath = false;
294
-                        $subEval = self::compileToPHPExpression($tales_prefix.$subPath,false);
295
-                        $result .= "'.(" . $subEval . ").'";
294
+                        $subEval = self::compileToPHPExpression($tales_prefix.$subPath, false);
295
+                        $result .= "'.(".$subEval.").'";
296 296
                         $subPath = '';
297 297
                         $lastWasDollar = false;
298 298
                         $c = '';
@@ -315,8 +315,8 @@  discard block
 block discarded – undo
315 315
                             $c = '';
316 316
                         } else {
317 317
                             $inPath = false;
318
-                            $subEval = self::compileToPHPExpression($tales_prefix.$subPath,false);
319
-                            $result .= "'.(" . $subEval . ").'";
318
+                            $subEval = self::compileToPHPExpression($tales_prefix.$subPath, false);
319
+                            $result .= "'.(".$subEval.").'";
320 320
                             }
321 321
                         }
322 322
                     break;
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
         }
326 326
         if ($inPath) {
327 327
             $subEval = self::compileToPHPExpression($tales_prefix.$subPath, false);
328
-            $result .= "'.(" . $subEval . ").'";
328
+            $result .= "'.(".$subEval.").'";
329 329
         }
330 330
 
331 331
         // optimize ''.foo.'' to foo
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
         $src = rawurldecode($src);
366 366
 
367 367
         // Simple echo can be supported via regular method
368
-        if (preg_match('/^\s*echo\s+((?:[^;]+|"[^"\\\\]*"|\'[^\'\\\\]*\'|\/\*.*?\*\/)+);*\s*$/s',$src,$m))
368
+        if (preg_match('/^\s*echo\s+((?:[^;]+|"[^"\\\\]*"|\'[^\'\\\\]*\'|\/\*.*?\*\/)+);*\s*$/s', $src, $m))
369 369
         {
370 370
             return $m[1];
371 371
         }
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
     {
386 386
         $src = trim($src);
387 387
         if (ctype_alnum($src)) return 'isset($ctx->'.$src.')';
388
-        return '(null !== ' . self::compileToPHPExpression($src, true) . ')';
388
+        return '(null !== '.self::compileToPHPExpression($src, true).')';
389 389
     }
390 390
 
391 391
     /**
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
      */
405 405
     static public function json($src, $nothrow)
406 406
     {
407
-        return 'json_encode('.phptal_tale($src,$nothrow).')';
407
+        return 'json_encode('.phptal_tale($src, $nothrow).')';
408 408
     }
409 409
 
410 410
     /**
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
      */
413 413
     static public function urlencode($src, $nothrow)
414 414
     {
415
-        return 'rawurlencode('.phptal_tale($src,$nothrow).')';
415
+        return 'rawurlencode('.phptal_tale($src, $nothrow).')';
416 416
     }
417 417
 
418 418
     /**
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
      * @see PHPTAL_Php_TalesInternal::compileToPHPExpressions()
423 423
      * @return string
424 424
      */
425
-    public static function compileToPHPExpression($expression, $nothrow=false)
425
+    public static function compileToPHPExpression($expression, $nothrow = false)
426 426
     {
427 427
         $r = self::compileToPHPExpressions($expression, $nothrow);
428 428
         if (!is_array($r)) return $r;
@@ -437,8 +437,8 @@  discard block
 block discarded – undo
437 437
      */
438 438
     private static function convertExpressionsToExpression(array $array, $nothrow)
439 439
     {
440
-        if (count($array)==1) return '($ctx->noThrow('.($nothrow?'true':'false').')||1?('.
441
-            ($array[0]==self::NOTHING_KEYWORD?'null':$array[0]).
440
+        if (count($array) == 1) return '($ctx->noThrow('.($nothrow ? 'true' : 'false').')||1?('.
441
+            ($array[0] == self::NOTHING_KEYWORD ? 'null' : $array[0]).
442 442
             '):"")';
443 443
 
444 444
         $expr = array_shift($array);
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
      *
458 458
      * @return string or array
459 459
      */
460
-    public static function compileToPHPExpressions($expression, $nothrow=false)
460
+    public static function compileToPHPExpressions($expression, $nothrow = false)
461 461
     {
462 462
         $expression = trim($expression ?? '');
463 463
 
@@ -488,13 +488,13 @@  discard block
 block discarded – undo
488 488
         throw new PHPTAL_UnknownModifierException("Unknown phptal modifier '$typePrefix'. Function '$func' does not exist", $typePrefix);
489 489
     }
490 490
 
491
-    private static function verifyPHPExpressions($typePrefix,$expressions)
491
+    private static function verifyPHPExpressions($typePrefix, $expressions)
492 492
     {
493 493
         if (!is_array($expressions)) {
494 494
             $expressions = array($expressions);
495 495
         }
496 496
 
497
-        foreach($expressions as $expr) {
497
+        foreach ($expressions as $expr) {
498 498
             if (preg_match('/;\s*$/', $expr)) {
499 499
                 throw new PHPTAL_ParserException("Modifier $typePrefix generated PHP statement rather than expression (don't add semicolons)");
500 500
             }
Please login to merge, or discard this patch.
classes/PHPTAL/Dom/Element.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 
189 189
             $this->generateSurroundFoot($codewriter);
190 190
         }
191
-        catch(PHPTAL_TemplateException $e) {
191
+        catch (PHPTAL_TemplateException $e) {
192 192
             $e->hintSrcPosition($this->getSourceFile(), $this->getSourceLine());
193 193
             throw $e;
194 194
         }
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
     /** Returns true if the element contains specified PHPTAL attribute. */
218 218
     public function hasAttribute($qname)
219 219
     {
220
-        foreach($this->attribute_nodes as $attr) if ($attr->getQualifiedName() == $qname) return true;
220
+        foreach ($this->attribute_nodes as $attr) if ($attr->getQualifiedName() == $qname) return true;
221 221
         return false;
222 222
     }
223 223
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 
247 247
     public function getAttributeNode($qname)
248 248
     {
249
-        foreach($this->attribute_nodes as $attr) if ($attr->getQualifiedName() === $qname) return $attr;
249
+        foreach ($this->attribute_nodes as $attr) if ($attr->getQualifiedName() === $qname) return $attr;
250 250
         return null;
251 251
     }
252 252
 
@@ -353,15 +353,15 @@  discard block
 block discarded – undo
353 353
         }
354 354
     }
355 355
 
356
-    public function generateContent(?PHPTAL_Php_CodeWriter $codewriter = null, $realContent=false)
356
+    public function generateContent(?PHPTAL_Php_CodeWriter $codewriter = null, $realContent = false)
357 357
     {
358 358
         if (!$this->isEmptyNode($codewriter->getOutputMode())) {
359 359
             if ($realContent || !count($this->contentAttributes)) {
360
-                foreach($this->childNodes as $child) {
360
+                foreach ($this->childNodes as $child) {
361 361
                     $child->generateCode($codewriter);
362 362
                 }
363 363
             }
364
-            else foreach($this->contentAttributes as $att) {
364
+            else foreach ($this->contentAttributes as $att) {
365 365
                 $att->before($codewriter);
366 366
                 $att->after($codewriter);
367 367
             }
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
     private function isEmptyNode($mode)
440 440
     {
441 441
         return (($mode === PHPTAL::XHTML || $mode === PHPTAL::HTML5) && PHPTAL_Dom_Defs::getInstance()->isEmptyTagNS($this->getNamespaceURI(), $this->getLocalName())) ||
442
-               ( $mode === PHPTAL::XML   && !$this->hasContent());
442
+               ($mode === PHPTAL::XML && !$this->hasContent());
443 443
     }
444 444
 
445 445
     private function hasContent()
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
                 throw new PHPTAL_TemplateException(sprintf("Attribute conflict in < %s > '%s' cannot appear with '%s'",
474 474
                                $this->qualifiedName,
475 475
                                $key,
476
-                               $temp[$nsattr->getPriority()][0]->getNamespace()->getPrefix() . ':' . $temp[$nsattr->getPriority()][0]->getLocalName()
476
+                               $temp[$nsattr->getPriority()][0]->getNamespace()->getPrefix().':'.$temp[$nsattr->getPriority()][0]->getLocalName()
477 477
                                ), $this->getSourceFile(), $this->getSourceLine());
478 478
             }
479 479
             $temp[$nsattr->getPriority()] = array($nsattr, $domattr);
Please login to merge, or discard this patch.
classes/PHPTAL/Dom/PHPTALDocumentBuilder.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
  */
23 23
 class PHPTAL_Dom_PHPTALDocumentBuilder extends PHPTAL_Dom_DocumentBuilder
24 24
 {
25
-    private $_xmlns;   /* PHPTAL_Dom_XmlnsState */
25
+    private $_xmlns; /* PHPTAL_Dom_XmlnsState */
26 26
     private $encoding;
27 27
     private ?PHPTAL_Dom_Element $documentElement = null;
28 28
 
@@ -53,8 +53,8 @@  discard block
 block discarded – undo
53 53
     public function onDocumentEnd()
54 54
     {
55 55
         if (count($this->_stack) > 0) {
56
-            $left='</'.$this->_current->getQualifiedName().'>';
57
-            for ($i = count($this->_stack)-1; $i>0; $i--) $left .= '</'.$this->_stack[$i]->getQualifiedName().'>';
56
+            $left = '</'.$this->_current->getQualifiedName().'>';
57
+            for ($i = count($this->_stack)-1; $i > 0; $i--) $left .= '</'.$this->_stack[$i]->getQualifiedName().'>';
58 58
             throw new PHPTAL_ParserException("Not all elements were closed before end of the document. Missing: ".$left,
59 59
                         $this->file, $this->line);
60 60
         }
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 
131 131
         $node = new PHPTAL_Dom_Element($element_qname, $namespace_uri, $attrnodes, $this->getXmlnsState());
132 132
         $this->pushNode($node);
133
-        $this->_stack[] =  $this->_current;
133
+        $this->_stack[] = $this->_current;
134 134
         $this->_current = $node;
135 135
     }
136 136
 
Please login to merge, or discard this patch.
classes/PHPTAL/Dom/SaxXmlParser.php 1 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.