Completed
Branch 1.11.x (83359d)
by Ben
18s
created
classes/PHPTAL/Php/Attribute/I18N/Source.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@
 block discarded – undo
35 35
         $codewriter->end();
36 36
 
37 37
         // push current source and use new one
38
-        $codewriter->pushCode('$_i18n_sources[] = ' . $codewriter->getTranslatorReference(). '->setSource('.$codewriter->str($this->expression).')');
38
+        $codewriter->pushCode('$_i18n_sources[] = '.$codewriter->getTranslatorReference().'->setSource('.$codewriter->str($this->expression).')');
39 39
     }
40 40
 
41 41
     public function after(PHPTAL_Php_CodeWriter $codewriter)
Please login to merge, or discard this patch.
classes/PHPTAL/Php/Attribute/METAL/UseMacro.php 3 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -52,14 +52,14 @@
 block discarded – undo
52 52
 
53 53
         $macroname = strtr($this->expression, '-', '_');
54 54
 
55
-	// throw error if attempting to define and use macro at same time
56
-	// [should perhaps be a TemplateException? but I don't know how to set that up...]
57
-	if ($defineAttr = $this->phpelement->getAttributeNodeNS(
58
-		'http://xml.zope.org/namespaces/metal', 'define-macro')) {
59
-		if ($defineAttr->getValue() == $macroname) 
60
-            		throw new PHPTAL_TemplateException("Cannot simultaneously define and use macro '$macroname'",
61
-                		$this->phpelement->getSourceFile(), $this->phpelement->getSourceLine());			
62
-	}
55
+    // throw error if attempting to define and use macro at same time
56
+    // [should perhaps be a TemplateException? but I don't know how to set that up...]
57
+    if ($defineAttr = $this->phpelement->getAttributeNodeNS(
58
+        'http://xml.zope.org/namespaces/metal', 'define-macro')) {
59
+        if ($defineAttr->getValue() == $macroname) 
60
+                    throw new PHPTAL_TemplateException("Cannot simultaneously define and use macro '$macroname'",
61
+                        $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine());			
62
+    }
63 63
 
64 64
         // local macro (no filename specified) and non dynamic macro name
65 65
         // can be called directly if it's a known function (just generated or seen in previous compilation)
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
         // local macro (no filename specified) and non dynamic macro name
65 65
         // can be called directly if it's a known function (just generated or seen in previous compilation)
66 66
         if (preg_match('/^[a-z0-9_]+$/i', $macroname) && $codewriter->functionExists($macroname)) {
67
-            $code = $codewriter->getFunctionPrefix() . $macroname . '($_thistpl, $tpl)';
67
+            $code = $codewriter->getFunctionPrefix().$macroname.'($_thistpl, $tpl)';
68 68
             $codewriter->pushCode($code);
69 69
         }
70 70
         // external macro or ${macroname}, use PHPTAL at runtime to resolve it
Please login to merge, or discard this patch.
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -56,9 +56,10 @@
 block discarded – undo
56 56
 	// [should perhaps be a TemplateException? but I don't know how to set that up...]
57 57
 	if ($defineAttr = $this->phpelement->getAttributeNodeNS(
58 58
 		'http://xml.zope.org/namespaces/metal', 'define-macro')) {
59
-		if ($defineAttr->getValue() == $macroname) 
60
-            		throw new PHPTAL_TemplateException("Cannot simultaneously define and use macro '$macroname'",
61
-                		$this->phpelement->getSourceFile(), $this->phpelement->getSourceLine());			
59
+		if ($defineAttr->getValue() == $macroname) {
60
+		            		throw new PHPTAL_TemplateException("Cannot simultaneously define and use macro '$macroname'",
61
+                		$this->phpelement->getSourceFile(), $this->phpelement->getSourceLine());
62
+		}
62 63
 	}
63 64
 
64 65
         // local macro (no filename specified) and non dynamic macro name
Please login to merge, or discard this patch.
classes/PHPTAL/Php/Attribute/METAL/FillSlot.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -105,7 +105,7 @@
 block discarded – undo
105 105
             return 0;
106 106
         }
107 107
 
108
-        $estimated_bytes = 2*(3+strlen($element->getQualifiedName()));
108
+        $estimated_bytes = 2 * (3+strlen($element->getQualifiedName()));
109 109
 
110 110
         foreach ($element->getAttributeNodes() as $attr) {
111 111
             $estimated_bytes += 4+strlen($attr->getQualifiedName());
Please login to merge, or discard this patch.
classes/PHPTAL/Php/Attribute/PHPTAL/Cache.php 3 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -67,12 +67,12 @@
 block discarded – undo
67 67
         } elseif ($cache_per_expression == 'nothing') {
68 68
             /* do nothing */
69 69
         } elseif ($cache_per_expression) {
70
-             $code = $codewriter->evaluateExpression($cache_per_expression);
70
+                $code = $codewriter->evaluateExpression($cache_per_expression);
71 71
 
72
-             if (is_array($code)) throw new PHPTAL_ParserException("Chained expressions in per-cache directive are not supported",
72
+                if (is_array($code)) throw new PHPTAL_ParserException("Chained expressions in per-cache directive are not supported",
73 73
                                                 $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine());
74 74
 
75
-             $cache_tag = '('.$code.')."@".' . $cache_tag;
75
+                $cache_tag = '('.$code.')."@".' . $cache_tag;
76 76
         }
77 77
 
78 78
         $this->cache_filename_var = $codewriter->createTempVariable();
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -50,8 +50,10 @@  discard block
 block discarded – undo
50 50
         if (!is_numeric($cache_len)) {
51 51
             $cache_len = $codewriter->evaluateExpression($cache_len);
52 52
 
53
-            if (is_array($cache_len)) throw new PHPTAL_ParserException("Chained expressions in cache length are not supported",
53
+            if (is_array($cache_len)) {
54
+                throw new PHPTAL_ParserException("Chained expressions in cache length are not supported",
54 55
                                         $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine());
56
+            }
55 57
         }
56 58
         switch ($matches[2]) {
57 59
             case 'd': $cache_len .= '*24'; /* no break */
@@ -69,8 +71,10 @@  discard block
 block discarded – undo
69 71
         } elseif ($cache_per_expression) {
70 72
              $code = $codewriter->evaluateExpression($cache_per_expression);
71 73
 
72
-             if (is_array($code)) throw new PHPTAL_ParserException("Chained expressions in per-cache directive are not supported",
74
+             if (is_array($code)) {
75
+                 throw new PHPTAL_ParserException("Chained expressions in per-cache directive are not supported",
73 76
                                                 $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine());
77
+             }
74 78
 
75 79
              $cache_tag = '('.$code.')."@".' . $cache_tag;
76 80
         }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -59,9 +59,9 @@  discard block
 block discarded – undo
59 59
             case 'm': $cache_len .= '*60'; /* no break */
60 60
         }
61 61
 
62
-        $cache_tag = '"'.addslashes( $this->phpelement->getQualifiedName() . ':' . $this->phpelement->getSourceLine()).'"';
62
+        $cache_tag = '"'.addslashes($this->phpelement->getQualifiedName().':'.$this->phpelement->getSourceLine()).'"';
63 63
 
64
-        $cache_per_expression = isset($matches[3])?trim($matches[3]):null;
64
+        $cache_per_expression = isset($matches[3]) ?trim($matches[3]) : null;
65 65
         if ($cache_per_expression == 'url') {
66 66
             $cache_tag .= '.$_SERVER["REQUEST_URI"]';
67 67
         } elseif ($cache_per_expression == 'nothing') {
@@ -72,11 +72,11 @@  discard block
 block discarded – undo
72 72
              if (is_array($code)) throw new PHPTAL_ParserException("Chained expressions in per-cache directive are not supported",
73 73
                                                 $this->phpelement->getSourceFile(), $this->phpelement->getSourceLine());
74 74
 
75
-             $cache_tag = '('.$code.')."@".' . $cache_tag;
75
+             $cache_tag = '('.$code.')."@".'.$cache_tag;
76 76
         }
77 77
 
78 78
         $this->cache_filename_var = $codewriter->createTempVariable();
79
-        $codewriter->doSetVar($this->cache_filename_var, $codewriter->str($codewriter->getCacheFilesBaseName()).'.md5('.$cache_tag.')' );
79
+        $codewriter->doSetVar($this->cache_filename_var, $codewriter->str($codewriter->getCacheFilesBaseName()).'.md5('.$cache_tag.')');
80 80
 
81 81
         $cond = '!file_exists('.$this->cache_filename_var.') || time() - '.$cache_len.' >= filemtime('.$this->cache_filename_var.')';
82 82
 
Please login to merge, or discard this patch.
classes/PHPTAL/Php/Attribute/PHPTAL/Tales.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -24,8 +24,9 @@
 block discarded – undo
24 24
         $mode = trim($this->expression);
25 25
         $mode = strtolower($mode);
26 26
 
27
-        if ($mode == '' || $mode == 'default')
28
-            $mode = 'tales';
27
+        if ($mode == '' || $mode == 'default') {
28
+                    $mode = 'tales';
29
+        }
29 30
 
30 31
         if ($mode != 'php' && $mode != 'tales') {
31 32
             throw new PHPTAL_TemplateException("Unsupported TALES mode '$mode'",
Please login to merge, or discard this patch.
classes/PHPTAL/Php/State.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
      */
145 145
     public function interpolateTalesVarsInString($string)
146 146
     {
147
-        return PHPTAL_Php_TalesInternal::parseString($string, false, ($this->getTalesMode() === 'tales') ? '' : 'php:' );
147
+        return PHPTAL_Php_TalesInternal::parseString($string, false, ($this->getTalesMode() === 'tales') ? '' : 'php:');
148 148
     }
149 149
 
150 150
     /**
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
     public function interpolateTalesVarsInHTML($src)
154 154
     {
155 155
         return preg_replace_callback('/((?:\$\$)*)\$\{(structure |text )?(.*?)\}|((?:\$\$)+)\{/isS',
156
-                                     array($this,'_interpolateTalesVarsInHTMLCallback'), $src);
156
+                                     array($this, '_interpolateTalesVarsInHTMLCallback'), $src);
157 157
     }
158 158
 
159 159
     /**
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
     public function interpolateTalesVarsInCDATA($src)
173 173
     {
174 174
         return preg_replace_callback('/((?:\$\$)*)\$\{(structure |text )?(.*?)\}|((?:\$\$)+)\{/isS',
175
-                                     array($this,'_interpolateTalesVarsInCDATACallback'), $src);
175
+                                     array($this, '_interpolateTalesVarsInCDATACallback'), $src);
176 176
     }
177 177
 
178 178
     /**
@@ -187,11 +187,11 @@  discard block
 block discarded – undo
187 187
     {
188 188
         // replaces $${ with literal ${ (or $$$${ with $${ etc)
189 189
         if (!empty($matches[4])) {
190
-            return substr($matches[4], strlen($matches[4])/2).'{';
190
+            return substr($matches[4], strlen($matches[4]) / 2).'{';
191 191
         }
192 192
 
193 193
         // same replacement, but before executed expression
194
-        $dollars = substr($matches[1], strlen($matches[1])/2);
194
+        $dollars = substr($matches[1], strlen($matches[1]) / 2);
195 195
 
196 196
         $code = $matches[3];
197 197
         if ($format == 'html') {
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
     public function interpolateTalesVarsInHTML($src)
154 154
     {
155 155
         return preg_replace_callback('/((?:\$\$)*)\$\{(structure |text )?(.*?)\}|((?:\$\$)+)\{/isS',
156
-                                     array($this,'_interpolateTalesVarsInHTMLCallback'), $src);
156
+                                        array($this,'_interpolateTalesVarsInHTMLCallback'), $src);
157 157
     }
158 158
 
159 159
     /**
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
     public function interpolateTalesVarsInCDATA($src)
173 173
     {
174 174
         return preg_replace_callback('/((?:\$\$)*)\$\{(structure |text )?(.*?)\}|((?:\$\$)+)\{/isS',
175
-                                     array($this,'_interpolateTalesVarsInCDATACallback'), $src);
175
+                                        array($this,'_interpolateTalesVarsInCDATACallback'), $src);
176 176
     }
177 177
 
178 178
     /**
Please login to merge, or discard this patch.
classes/PHPTAL/Php/CodeWriter.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -24,11 +24,11 @@  discard block
 block discarded – undo
24 24
     /**
25 25
      * max id of variable to give as temp
26 26
      */
27
-    private $temp_var_counter=0;
27
+    private $temp_var_counter = 0;
28 28
     /**
29 29
      * stack with free'd variables
30 30
      */
31
-    private $temp_recycling=array();
31
+    private $temp_recycling = array();
32 32
 
33 33
     /**
34 34
      * keeps track of seen functions for function_exists
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 
50 50
     public function recycleTempVariable($var)
51 51
     {
52
-        if (substr($var, 0, 6)!=='$_tmp_') throw new PHPTAL_Exception("Invalid variable recycled");
52
+        if (substr($var, 0, 6) !== '$_tmp_') throw new PHPTAL_Exception("Invalid variable recycled");
53 53
         $this->temp_recycling[] = $var;
54 54
     }
55 55
 
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
 
141 141
     public function indent()
142 142
     {
143
-        $this->_indentation ++;
143
+        $this->_indentation++;
144 144
     }
145 145
 
146 146
     public function unindent()
147 147
     {
148
-        $this->_indentation --;
148
+        $this->_indentation--;
149 149
     }
150 150
 
151 151
     public function flush()
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
             }
188 188
             $this->_result .= $codeLine;
189 189
         }
190
-        $this->_result .= "?>\n";// PHP consumes newline
190
+        $this->_result .= "?>\n"; // PHP consumes newline
191 191
         $this->_codeBuffer = array();
192 192
     }
193 193
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
     public function doDoctype($called_from_macro = false)
208 208
     {
209 209
         if ($this->_doctype) {
210
-            $code = '$ctx->setDocType('.$this->str($this->_doctype).','.($called_from_macro?'true':'false').')';
210
+            $code = '$ctx->setDocType('.$this->str($this->_doctype).','.($called_from_macro ? 'true' : 'false').')';
211 211
             $this->pushCode($code);
212 212
         }
213 213
     }
@@ -220,21 +220,21 @@  discard block
 block discarded – undo
220 220
     public function doXmlDeclaration($called_from_macro = false)
221 221
     {
222 222
         if ($this->_xmldeclaration && $this->getOutputMode() !== PHPTAL::HTML5) {
223
-            $code = '$ctx->setXmlDeclaration('.$this->str($this->_xmldeclaration).','.($called_from_macro?'true':'false').')';
223
+            $code = '$ctx->setXmlDeclaration('.$this->str($this->_xmldeclaration).','.($called_from_macro ? 'true' : 'false').')';
224 224
             $this->pushCode($code);
225 225
         }
226 226
     }
227 227
 
228 228
     public function functionExists($name)
229 229
     {
230
-        return isset($this->known_functions[$this->_functionPrefix . $name]);
230
+        return isset($this->known_functions[$this->_functionPrefix.$name]);
231 231
     }
232 232
 
233 233
     public function doTemplateFile($functionName, PHPTAL_Dom_Element $treeGen)
234 234
     {
235 235
         $this->doComment("\n*** DO NOT EDIT THIS FILE ***\n\nGenerated by PHPTAL from ".$treeGen->getSourceFile()." (edit that file instead)");
236 236
         $this->doFunction($functionName, 'PHPTAL $tpl, PHPTAL_Context $ctx');
237
-        $this->setFunctionPrefix($functionName . "_");
237
+        $this->setFunctionPrefix($functionName."_");
238 238
         $this->doSetVar('$_thistpl', '$tpl');
239 239
         $this->doInitTranslator();
240 240
         $treeGen->generateCode($this);
@@ -244,13 +244,13 @@  discard block
 block discarded – undo
244 244
 
245 245
     public function doFunction($name, $params)
246 246
     {
247
-        $name = $this->_functionPrefix . $name;
247
+        $name = $this->_functionPrefix.$name;
248 248
         $this->known_functions[$name] = true;
249 249
 
250 250
         $this->pushCodeWriterContext();
251 251
         $this->pushCode("function $name($params) {\n");
252 252
         $this->indent();
253
-        $this->_segments[] =  'function';
253
+        $this->_segments[] = 'function';
254 254
     }
255 255
 
256 256
     public function doComment($comment)
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 
282 282
     public function doForeach($out, $source)
283 283
     {
284
-        $this->_segments[] =  'foreach';
284
+        $this->_segments[] = 'foreach';
285 285
         $this->pushCode("foreach ($source as $out):");
286 286
         $this->indent();
287 287
     }
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
             $this->flush();
305 305
             $functionCode = $this->_result;
306 306
             $this->popCodeWriterContext();
307
-            $this->_result = $functionCode . $this->_result;
307
+            $this->_result = $functionCode.$this->_result;
308 308
         } elseif ($segment == 'try')
309 309
             $this->pushCode('}');
310 310
         elseif ($segment == 'catch')
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 
316 316
     public function doTry()
317 317
     {
318
-        $this->_segments[] =  'try';
318
+        $this->_segments[] = 'try';
319 319
         $this->pushCode('try {');
320 320
         $this->indent();
321 321
     }
@@ -328,14 +328,14 @@  discard block
 block discarded – undo
328 328
     public function doCatch($catch)
329 329
     {
330 330
         $this->doEnd('try');
331
-        $this->_segments[] =  'catch';
331
+        $this->_segments[] = 'catch';
332 332
         $this->pushCode('catch('.$catch.') {');
333 333
         $this->indent();
334 334
     }
335 335
 
336 336
     public function doIf($condition)
337 337
     {
338
-        $this->_segments[] =  'if';
338
+        $this->_segments[] = 'if';
339 339
         $this->pushCode('if ('.$condition.'): ');
340 340
         $this->indent();
341 341
     }
@@ -387,14 +387,14 @@  discard block
 block discarded – undo
387 387
     {
388 388
         if ($html === "") return;
389 389
         $this->flushCode();
390
-        $this->_htmlBuffer[] =  $html;
390
+        $this->_htmlBuffer[] = $html;
391 391
     }
392 392
 
393 393
     public function pushCode($codeLine)
394 394
     {
395 395
         $this->flushHtml();
396
-        $codeLine = $this->indentSpaces() . $codeLine;
397
-        $this->_codeBuffer[] =  $codeLine;
396
+        $codeLine = $this->indentSpaces().$codeLine;
397
+        $this->_codeBuffer[] = $codeLine;
398 398
     }
399 399
 
400 400
     /**
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
      */
403 403
     public function str($string)
404 404
     {
405
-        return "'".strtr($string,array("'"=>'\\\'','\\'=>'\\\\'))."'";
405
+        return "'".strtr($string, array("'"=>'\\\'', '\\'=>'\\\\'))."'";
406 406
     }
407 407
 
408 408
     public function escapeCode($code)
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
 
480 480
     private function pushCodeWriterContext()
481 481
     {
482
-        $this->_contexts[] =  clone $this;
482
+        $this->_contexts[] = clone $this;
483 483
         $this->_result = "";
484 484
         $this->_indentation = 0;
485 485
         $this->_codeBuffer = array();
Please login to merge, or discard this 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 2 patches
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.
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/RepeatController.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public function __construct($source)
59 59
     {
60
-        if ( is_string($source) ) {
61
-            $this->iterator = new ArrayIterator( str_split($source) );  // FIXME: invalid for UTF-8 encoding, use preg_match_all('/./u') trick
62
-        } elseif ( is_array($source) ) {
60
+        if (is_string($source)) {
61
+            $this->iterator = new ArrayIterator(str_split($source)); // FIXME: invalid for UTF-8 encoding, use preg_match_all('/./u') trick
62
+        } elseif (is_array($source)) {
63 63
             $this->iterator = new ArrayIterator($source);
64 64
         } elseif ($source instanceof IteratorAggregate) {
65 65
             $this->iterator = $source->getIterator();
@@ -74,11 +74,11 @@  discard block
 block discarded – undo
74 74
         } elseif ($source instanceof Traversable) {
75 75
             $this->iterator = new IteratorIterator($source);
76 76
         } elseif ($source instanceof Closure) {
77
-            $this->iterator = new ArrayIterator( (array) $source() );
77
+            $this->iterator = new ArrayIterator((array) $source());
78 78
         } elseif ($source instanceof stdClass) {
79
-            $this->iterator = new ArrayIterator( (array) $source );
79
+            $this->iterator = new ArrayIterator((array) $source);
80 80
         } else {
81
-            $this->iterator = new ArrayIterator( array() );
81
+            $this->iterator = new ArrayIterator(array());
82 82
         }
83 83
     }
84 84
 
@@ -120,11 +120,11 @@  discard block
 block discarded – undo
120 120
         if ($this->length === null) {
121 121
             if ($this->iterator instanceof Countable) {
122 122
                 return $this->length = count($this->iterator);
123
-            } elseif ( is_object($this->iterator) ) {
123
+            } elseif (is_object($this->iterator)) {
124 124
                 // for backwards compatibility with existing PHPTAL templates
125
-                if ( method_exists($this->iterator, 'size') ) {
125
+                if (method_exists($this->iterator, 'size')) {
126 126
                     return $this->length = $this->iterator->size();
127
-                } elseif ( method_exists($this->iterator, 'length') ) {
127
+                } elseif (method_exists($this->iterator, 'length')) {
128 128
                     return $this->length = $this->iterator->length();
129 129
                 }
130 130
             }
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 
134 134
         if ($this->length === '_PHPTAL_LENGTH_UNKNOWN_') // return length if end is discovered
135 135
         {
136
-            return $this->end ? $this->index + 1 : null;
136
+            return $this->end ? $this->index+1 : null;
137 137
         }
138 138
         return $this->length;
139 139
     }
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
     {
204 204
         switch ($var) {
205 205
             case 'number':
206
-                return $this->index + 1;
206
+                return $this->index+1;
207 207
             case 'start':
208 208
                 return $this->index === 0;
209 209
             case 'even':
@@ -213,13 +213,13 @@  discard block
 block discarded – undo
213 213
             case 'length':
214 214
                 return $this->length();
215 215
             case 'letter':
216
-                return strtolower( $this->int2letter($this->index+1) );
216
+                return strtolower($this->int2letter($this->index+1));
217 217
             case 'Letter':
218
-                return strtoupper( $this->int2letter($this->index+1) );
218
+                return strtoupper($this->int2letter($this->index+1));
219 219
             case 'roman':
220
-                return strtolower( $this->int2roman($this->index+1) );
220
+                return strtolower($this->int2roman($this->index+1));
221 221
             case 'Roman':
222
-                return strtoupper( $this->int2roman($this->index+1) );
222
+                return strtoupper($this->int2roman($this->index+1));
223 223
 
224 224
             case 'groups':
225 225
                 $this->initializeGroups();
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
             case 'last':
235 235
                 $this->initializeGroups();
236 236
                 // Compare the next one with the dictionary
237
-                $res = $this->groups->last( $this->iterator->current() );
237
+                $res = $this->groups->last($this->iterator->current());
238 238
                 return is_bool($res) ? $res : $this->groups;
239 239
 
240 240
             default:
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
         $this->key = $this->iterator->key();
256 256
 
257 257
         $this->iterator->next();
258
-        if ( !$this->iterator->valid() ) {
258
+        if (!$this->iterator->valid()) {
259 259
             $this->valid = false;
260 260
             $this->end = true;
261 261
         }
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
         $letters = '';
278 278
         while ($int > 0) {
279 279
             $int--;
280
-            $letters = $lookup[$int % $size] . $letters;
280
+            $letters = $lookup[$int % $size].$letters;
281 281
             $int = floor($int / $size);
282 282
         }
283 283
         return $letters;
Please login to merge, or discard this 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.