Completed
Pull Request — master (#73)
by Witold
07:32
created
classes/PHPTAL/Php/TalesChainExecutor.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -79,10 +79,12 @@
 block discarded – undo
79 79
                 $this->_reader->talesChainPart($this, $exp, $lastkey === $key);
80 80
             }
81 81
 
82
-            if ($this->_state == self::CHAIN_BREAK)
83
-                break;
84
-            if ($this->_state == self::CHAIN_CONT)
85
-                continue;
82
+            if ($this->_state == self::CHAIN_BREAK) {
83
+                            break;
84
+            }
85
+            if ($this->_state == self::CHAIN_CONT) {
86
+                            continue;
87
+            }
86 88
         }
87 89
 
88 90
         $this->codewriter->doEnd('if');
Please login to merge, or discard this patch.
classes/PHPTAL/Php/CodeWriter.php 1 patch
Braces   +45 added lines, -20 removed lines patch added patch discarded remove patch
@@ -43,13 +43,17 @@  discard block
 block discarded – undo
43 43
 
44 44
     public function createTempVariable()
45 45
     {
46
-        if (count($this->temp_recycling)) return array_shift($this->temp_recycling);
46
+        if (count($this->temp_recycling)) {
47
+            return array_shift($this->temp_recycling);
48
+        }
47 49
         return '$_tmp_'.(++$this->temp_var_counter);
48 50
     }
49 51
 
50 52
     public function recycleTempVariable($var)
51 53
     {
52
-        if (substr($var, 0, 6)!=='$_tmp_') throw new PHPTAL_Exception("Invalid variable recycled");
54
+        if (substr($var, 0, 6)!=='$_tmp_') {
55
+            throw new PHPTAL_Exception("Invalid variable recycled");
56
+        }
53 57
         $this->temp_recycling[] = $var;
54 58
     }
55 59
 
@@ -129,7 +133,9 @@  discard block
 block discarded – undo
129 133
     {
130 134
         preg_match_all('/(?:[^;]+|;;)+/sm', $src, $array);
131 135
         $array = $array[0];
132
-        foreach ($array as &$a) $a = str_replace(';;', ';', $a);
136
+        foreach ($array as &$a) {
137
+            $a = str_replace(';;', ';', $a);
138
+        }
133 139
         return $array;
134 140
     }
135 141
 
@@ -165,16 +171,22 @@  discard block
 block discarded – undo
165 171
 
166 172
     public function flushCode()
167 173
     {
168
-        if (count($this->_codeBuffer) == 0) return;
174
+        if (count($this->_codeBuffer) == 0) {
175
+            return;
176
+        }
169 177
 
170 178
         // special treatment for one code line
171 179
         if (count($this->_codeBuffer) == 1) {
172 180
             $codeLine = $this->_codeBuffer[0];
173 181
             // avoid adding ; after } and {
174
-            if (!preg_match('/\}\s*$|\{\s*$/', $codeLine))
175
-                $this->_result .= '<?php '.$codeLine."; ?>\n"; // PHP consumes newline
176
-            else
177
-                $this->_result .= '<?php '.$codeLine." ?>\n"; // PHP consumes newline
182
+            if (!preg_match('/\}\s*$|\{\s*$/', $codeLine)) {
183
+                            $this->_result .= '<?php '.$codeLine."; ?>\n";
184
+            }
185
+            // PHP consumes newline
186
+            else {
187
+                            $this->_result .= '<?php '.$codeLine." ?>\n";
188
+            }
189
+            // PHP consumes newline
178 190
             $this->_codeBuffer = array();
179 191
             return;
180 192
         }
@@ -193,7 +205,9 @@  discard block
 block discarded – undo
193 205
 
194 206
     public function flushHtml()
195 207
     {
196
-        if (count($this->_htmlBuffer) == 0) return;
208
+        if (count($this->_htmlBuffer) == 0) {
209
+            return;
210
+        }
197 211
 
198 212
         $this->_result .= implode('', $this->_htmlBuffer);
199 213
         $this->_htmlBuffer = array();
@@ -289,7 +303,9 @@  discard block
 block discarded – undo
289 303
     public function doEnd($expects = null)
290 304
     {
291 305
         if (!count($this->_segments)) {
292
-            if (!$expects) $expects = 'anything';
306
+            if (!$expects) {
307
+                $expects = 'anything';
308
+            }
293 309
             throw new PHPTAL_Exception("Bug: CodeWriter generated end of block without $expects open");
294 310
         }
295 311
 
@@ -305,12 +321,13 @@  discard block
 block discarded – undo
305 321
             $functionCode = $this->_result;
306 322
             $this->popCodeWriterContext();
307 323
             $this->_result = $functionCode . $this->_result;
308
-        } elseif ($segment == 'try')
309
-            $this->pushCode('}');
310
-        elseif ($segment == 'catch')
311
-            $this->pushCode('}');
312
-        else
313
-            $this->pushCode("end$segment");
324
+        } elseif ($segment == 'try') {
325
+                    $this->pushCode('}');
326
+        } elseif ($segment == 'catch') {
327
+                    $this->pushCode('}');
328
+        } else {
329
+                    $this->pushCode("end$segment");
330
+        }
314 331
     }
315 332
 
316 333
     public function doTry()
@@ -362,14 +379,18 @@  discard block
 block discarded – undo
362 379
 
363 380
     public function doEcho($code)
364 381
     {
365
-        if ($code === "''") return;
382
+        if ($code === "''") {
383
+            return;
384
+        }
366 385
         $this->flush();
367 386
         $this->pushCode('echo '.$this->escapeCode($code));
368 387
     }
369 388
 
370 389
     public function doEchoRaw($code)
371 390
     {
372
-        if ($code === "''") return;
391
+        if ($code === "''") {
392
+            return;
393
+        }
373 394
         $this->pushCode('echo '.$this->stringifyCode($code));
374 395
     }
375 396
 
@@ -385,7 +406,9 @@  discard block
 block discarded – undo
385 406
 
386 407
     public function pushHTML($html)
387 408
     {
388
-        if ($html === "") return;
409
+        if ($html === "") {
410
+            return;
411
+        }
389 412
         $this->flushCode();
390 413
         $this->_htmlBuffer[] =  $html;
391 414
     }
@@ -444,11 +467,13 @@  discard block
 block discarded – undo
444 467
     {
445 468
         // FIXME: interpolation is done _after_ that function, so ${} must be forbidden for now
446 469
 
447
-        if ($this->getEncoding() == 'UTF-8') // HTML 5: 8.1.2.3 Attributes ; http://code.google.com/p/html5lib/issues/detail?id=93
470
+        if ($this->getEncoding() == 'UTF-8') {
471
+            // HTML 5: 8.1.2.3 Attributes ; http://code.google.com/p/html5lib/issues/detail?id=93
448 472
         {
449 473
             // regex excludes unicode control characters, all kinds of whitespace and unsafe characters
450 474
             // and trailing / to avoid confusion with self-closing syntax
451 475
             $unsafe_attr_regex = '/^$|[&=\'"><\s`\pM\pC\pZ\p{Pc}\p{Sk}]|\/$|\${/u';
476
+        }
452 477
         } else {
453 478
             $unsafe_attr_regex = '/^$|[&=\'"><\s`\0177-\377]|\/$|\${/';
454 479
         }
Please login to merge, or discard this patch.
classes/PHPTAL/Php/TalesInternal.php 1 patch
Braces   +29 added lines, -14 removed lines patch added patch discarded remove patch
@@ -124,9 +124,15 @@  discard block
 block discarded – undo
124 124
     static public function path($expression, $nothrow=false)
125 125
     {
126 126
         $expression = trim($expression);
127
-        if ($expression == 'default') return self::DEFAULT_KEYWORD;
128
-        if ($expression == 'nothing') return self::NOTHING_KEYWORD;
129
-        if ($expression == '')        return self::NOTHING_KEYWORD;
127
+        if ($expression == 'default') {
128
+            return self::DEFAULT_KEYWORD;
129
+        }
130
+        if ($expression == 'nothing') {
131
+            return self::NOTHING_KEYWORD;
132
+        }
133
+        if ($expression == '') {
134
+            return self::NOTHING_KEYWORD;
135
+        }
130 136
 
131 137
         // split OR expressions terminated by a string
132 138
         if (preg_match('/^(.*?)\s*\|\s*?(string:.*)$/sm', $expression, $m)) {
@@ -148,8 +154,7 @@  discard block
 block discarded – undo
148 154
             foreach ($exps as $i=>$exp) {
149 155
                 if(isset($string) || $i < count($exps) - 1) {
150 156
                     $result[] = self::compileToPHPExpressions(trim($exp), true);
151
-                }
152
-                else {
157
+                } else {
153 158
                     // the last expression can thorw exception.
154 159
                     $result[] = self::compileToPHPExpressions(trim($exp), false);
155 160
                 }
@@ -183,7 +188,11 @@  discard block
 block discarded – undo
183 188
             return '$ctx->path($ctx, ' . $next . ($expression === null ? '' : '."/".'.$expression) . ', true)';
184 189
         }
185 190
 
186
-        if (preg_match('/^\'[a-z][a-z0-9_]*\'$/i', $next)) $next = substr($next, 1, -1); else $next = '{'.$next.'}';
191
+        if (preg_match('/^\'[a-z][a-z0-9_]*\'$/i', $next)) {
192
+            $next = substr($next, 1, -1);
193
+        } else {
194
+            $next = '{'.$next.'}';
195
+        }
187 196
 
188 197
         // if no sub part for this expression, just optimize the generated code
189 198
         // and access the $ctx->var
@@ -260,8 +269,7 @@  discard block
 block discarded – undo
260 269
                     if ($inAccoladePath) {
261 270
                         $subPath .= $c;
262 271
                         $c = '';
263
-                    }
264
-                    else {
272
+                    } else {
265 273
                         $c = '\\\\';
266 274
                     }
267 275
                     break;
@@ -270,8 +278,7 @@  discard block
 block discarded – undo
270 278
                     if ($inAccoladePath) {
271 279
                         $subPath .= $c;
272 280
                         $c = '';
273
-                    }
274
-                    else {
281
+                    } else {
275 282
                         $c = '\\\'';
276 283
                     }
277 284
                     break;
@@ -384,7 +391,9 @@  discard block
 block discarded – undo
384 391
     static public function exists($src, $nothrow)
385 392
     {
386 393
         $src = trim($src);
387
-        if (ctype_alnum($src)) return 'isset($ctx->'.$src.')';
394
+        if (ctype_alnum($src)) {
395
+            return 'isset($ctx->'.$src.')';
396
+        }
388 397
         return '(null !== ' . self::compileToPHPExpression($src, true) . ')';
389 398
     }
390 399
 
@@ -395,7 +404,9 @@  discard block
 block discarded – undo
395 404
      */
396 405
     static public function number($src, $nothrow)
397 406
     {
398
-        if (!is_numeric(trim($src))) throw new PHPTAL_ParserException("'$src' is not a number");
407
+        if (!is_numeric(trim($src))) {
408
+            throw new PHPTAL_ParserException("'$src' is not a number");
409
+        }
399 410
         return trim($src);
400 411
     }
401 412
 
@@ -425,7 +436,9 @@  discard block
 block discarded – undo
425 436
     public static function compileToPHPExpression($expression, $nothrow=false)
426 437
     {
427 438
         $r = self::compileToPHPExpressions($expression, $nothrow);
428
-        if (!is_array($r)) return $r;
439
+        if (!is_array($r)) {
440
+            return $r;
441
+        }
429 442
 
430 443
         // this weird ternary operator construct is to execute noThrow inside the expression
431 444
         return '($ctx->noThrow(true)||1?'.self::convertExpressionsToExpression($r, $nothrow).':"")';
@@ -437,9 +450,11 @@  discard block
 block discarded – undo
437 450
      */
438 451
     private static function convertExpressionsToExpression(array $array, $nothrow)
439 452
     {
440
-        if (count($array)==1) return '($ctx->noThrow('.($nothrow?'true':'false').')||1?('.
453
+        if (count($array)==1) {
454
+            return '($ctx->noThrow('.($nothrow?'true':'false').')||1?('.
441 455
             ($array[0]==self::NOTHING_KEYWORD?'null':$array[0]).
442 456
             '):"")';
457
+        }
443 458
 
444 459
         $expr = array_shift($array);
445 460
 
Please login to merge, or discard this patch.
classes/PHPTAL/RepeatController.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -131,10 +131,12 @@  discard block
 block discarded – undo
131 131
             $this->length = '_PHPTAL_LENGTH_UNKNOWN_';
132 132
         }
133 133
 
134
-        if ($this->length === '_PHPTAL_LENGTH_UNKNOWN_') // return length if end is discovered
134
+        if ($this->length === '_PHPTAL_LENGTH_UNKNOWN_') {
135
+            // return length if end is discovered
135 136
         {
136 137
             return $this->end ? $this->index + 1 : null;
137 138
         }
139
+        }
138 140
         return $this->length;
139 141
     }
140 142
 
@@ -173,7 +175,9 @@  discard block
 block discarded – undo
173 175
         $this->index++;
174 176
 
175 177
         // Prefetch the next element
176
-        if ($this->validOnNext) $this->prefetch();
178
+        if ($this->validOnNext) {
179
+            $this->prefetch();
180
+        }
177 181
 
178 182
         if ($this->uses_groups) {
179 183
             // Notify the grouping helper of the change
Please login to merge, or discard this patch.
classes/PHPTAL/FileSource.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,9 @@
 block discarded – undo
25 25
     public function __construct($path)
26 26
     {
27 27
         $this->_path = realpath($path);
28
-        if ($this->_path === false) throw new PHPTAL_IOException("Unable to find real path of file '$path' (in ".getcwd().')');
28
+        if ($this->_path === false) {
29
+            throw new PHPTAL_IOException("Unable to find real path of file '$path' (in ".getcwd().')');
30
+        }
29 31
     }
30 32
 
31 33
     public function getRealPath()
Please login to merge, or discard this patch.
classes/PHPTAL/PreFilter/Normalize.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -76,7 +76,9 @@  discard block
 block discarded – undo
76 76
     protected function findElementToFilter(PHPTAL_Dom_Element $root)
77 77
     {
78 78
         foreach ($root->childNodes as $node) {
79
-            if (!$node instanceof PHPTAL_Dom_Element) continue;
79
+            if (!$node instanceof PHPTAL_Dom_Element) {
80
+                continue;
81
+            }
80 82
 
81 83
             if ($node->getAttributeNS("http://www.w3.org/XML/1998/namespace", 'space') == 'default') {
82 84
                 $this->filterDOM($node);
@@ -99,7 +101,9 @@  discard block
 block discarded – undo
99 101
         foreach ($element->getAttributeNodes() as $attrnode) {
100 102
 
101 103
             // skip replaced attributes (because getValueEscaped on them is meaningless)
102
-            if ($attrnode->getReplacedState() !== PHPTAL_Dom_Attr::NOT_REPLACED) continue;
104
+            if ($attrnode->getReplacedState() !== PHPTAL_Dom_Attr::NOT_REPLACED) {
105
+                continue;
106
+            }
103 107
 
104 108
             $val = $this->normalizeSpace($attrnode->getValueEscaped(), $attrnode->getEncoding());
105 109
             $attrnode->setValueEscaped(trim($val, ' '));
Please login to merge, or discard this patch.
classes/PHPTAL/PreFilter/Compress.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -260,8 +260,7 @@
 block discarded – undo
260 260
 	            $element->removeAttributeNS('','http-equiv');
261 261
 	            $element->removeAttributeNS('','content');
262 262
 	            $element->setAttributeNS('','charset',strtolower($this->getPHPTAL()->getEncoding()));
263
-        }
264
-        elseif (('link' === $element->getLocalName() && $element->getAttributeNS('','rel') === 'stylesheet') ||
263
+        } elseif (('link' === $element->getLocalName() && $element->getAttributeNS('','rel') === 'stylesheet') ||
265 264
             ('style' === $element->getLocalName())) {
266 265
             // There's only one type of stylesheets that works.
267 266
             $element->removeAttributeNS('','type');
Please login to merge, or discard this patch.
classes/PHPTAL/Tokenizer.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,7 +36,9 @@  discard block
 block discarded – undo
36 36
 
37 37
     function skipSpace()
38 38
     {
39
-        while ($this->current_token === 'SPACE') $this->nextToken();
39
+        while ($this->current_token === 'SPACE') {
40
+            $this->nextToken();
41
+        }
40 42
     }
41 43
 
42 44
     function nextToken()
@@ -47,7 +49,9 @@  discard block
 block discarded – undo
47 49
         }
48 50
 
49 51
         //if (!preg_match_all($this->regex, $this->str, $m, PREG_SET_ORDER, $this->offset)) throw new Exception("FAIL {$this->regex} at {$this->offset}");
50
-        if (!preg_match($this->regex, $this->str, $m, null, $this->offset)) throw new Exception("FAIL {$this->regex} didn't match '{$this->str}' at {$this->offset}");
52
+        if (!preg_match($this->regex, $this->str, $m, null, $this->offset)) {
53
+            throw new Exception("FAIL {$this->regex} didn't match '{$this->str}' at {$this->offset}");
54
+        }
51 55
 
52 56
         $this->offset += strlen($m[0]); // in bytes
53 57
 
Please login to merge, or discard this patch.
classes/PHPTAL/Context.php 1 patch
Braces   +14 added lines, -10 removed lines patch added patch discarded remove patch
@@ -116,8 +116,7 @@  discard block
 block discarded – undo
116 116
             } else {
117 117
                 throw new PHPTAL_ConfigurationException("Executed macro in file with DOCTYPE when using echoExecute(). This is not supported yet. Remove DOCTYPE or use PHPTAL->execute().");
118 118
             }
119
-        }
120
-        else if (!$this->_docType) {
119
+        } else if (!$this->_docType) {
121 120
             $this->_docType = $doctype;
122 121
         }
123 122
     }
@@ -317,7 +316,9 @@  discard block
 block discarded – undo
317 316
     {
318 317
         if ($current !== $path) {
319 318
             $pathinfo = " (in path '.../$path')";
320
-        } else $pathinfo = '';
319
+        } else {
320
+            $pathinfo = '';
321
+        }
321 322
 
322 323
         if (!empty($basename)) {
323 324
             $basename = "'" . $basename . "' ";
@@ -353,7 +354,9 @@  discard block
 block discarded – undo
353 354
     public static function path($base, $path, $nothrow=false)
354 355
     {
355 356
         if ($base === null) {
356
-            if ($nothrow) return null;
357
+            if ($nothrow) {
358
+                return null;
359
+            }
357 360
             PHPTAL_Context::pathError($base, $path, $path, $path);
358 361
         }
359 362
 
@@ -413,8 +416,7 @@  discard block
 block discarded – undo
413 416
                     {
414 417
                         $base = $base->__call($current, array());
415 418
                         continue;
416
-                    }
417
-                    catch(BadMethodCallException $e) {}
419
+                    } catch(BadMethodCallException $e) {}
418 420
                 }
419 421
 
420 422
                 if (is_callable($base)) {
@@ -444,8 +446,9 @@  discard block
 block discarded – undo
444 446
                     continue;
445 447
                 }
446 448
 
447
-                if ($nothrow)
448
-                    return null;
449
+                if ($nothrow) {
450
+                                    return null;
451
+                }
449 452
 
450 453
                 PHPTAL_Context::pathError($base, $path, $current, $prev);
451 454
             }
@@ -467,8 +470,9 @@  discard block
 block discarded – undo
467 470
 
468 471
             // if this point is reached, then the part cannot be resolved
469 472
 
470
-            if ($nothrow)
471
-                return null;
473
+            if ($nothrow) {
474
+                            return null;
475
+            }
472 476
 
473 477
             PHPTAL_Context::pathError($base, $path, $current, $prev);
474 478
         }
Please login to merge, or discard this patch.