Completed
Branch 1.3.x (b833d8)
by Ben
05:10
created
classes/PHPTAL/Php/Attribute/TAL/Attributes.php 3 patches
Doc Comments   +5 added lines patch added patch discarded remove patch
@@ -91,6 +91,7 @@  discard block
 block discarded – undo
91 91
 
92 92
     /**
93 93
      * attribute will be output regardless of its evaluated value. NULL behaves just like "".
94
+     * @param string $code
94 95
      */
95 96
     private function prepareAttributeUnconditional(PHPTAL_Php_CodeWriter $codewriter, $qname, $code)
96 97
     {
@@ -107,6 +108,7 @@  discard block
 block discarded – undo
107 108
 
108 109
     /**
109 110
      * If evaluated value of attribute is NULL, it will not be output at all.
111
+     * @param string $code
110 112
      */
111 113
     private function prepareAttributeConditional(PHPTAL_Php_CodeWriter $codewriter, $qname, $code)
112 114
     {
@@ -139,6 +141,9 @@  discard block
 block discarded – undo
139 141
         $this->phpelement->getOrCreateAttributeNode($qname)->overwriteFullWithVariable($this->_attkey);
140 142
     }
141 143
 
144
+    /**
145
+     * @param string $code
146
+     */
142 147
     private function prepareBooleanAttribute(PHPTAL_Php_CodeWriter $codewriter, $qname, $code)
143 148
     {
144 149
         $attkey = $this->getVarName($qname, $codewriter);
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -186,7 +186,7 @@
 block discarded – undo
186 186
         $executor->doElse();
187 187
         $attr_str = ($this->_default_escaped !== false)
188 188
             ? ' '.$this->_attribute.'='.$codewriter->quoteAttributeValue($this->_default_escaped)  // default value
189
-            : '';                                 // do not print attribute
189
+            : ''; // do not print attribute
190 190
         $codewriter->doSetVar($this->_attkey, $codewriter->str($attr_str));
191 191
         $executor->breakChain();
192 192
     }
Please login to merge, or discard this patch.
Braces   +13 added lines, -9 removed lines patch added patch discarded remove patch
@@ -115,10 +115,11 @@  discard block
 block discarded – undo
115 115
 
116 116
         $codewriter->doIf("null !== ($attkey = ($code))");
117 117
 
118
-        if ($this->_echoType !== PHPTAL_Php_Attribute::ECHO_STRUCTURE)
119
-            $codewriter->doSetVar($attkey, $codewriter->str(" $qname=\"").".".$codewriter->escapeCode($attkey).".'\"'");
120
-        else
121
-            $codewriter->doSetVar($attkey, $codewriter->str(" $qname=\"").".".$codewriter->stringifyCode($attkey).".'\"'");
118
+        if ($this->_echoType !== PHPTAL_Php_Attribute::ECHO_STRUCTURE) {
119
+                    $codewriter->doSetVar($attkey, $codewriter->str(" $qname=\"").".".$codewriter->escapeCode($attkey).".'\"'");
120
+        } else {
121
+                    $codewriter->doSetVar($attkey, $codewriter->str(" $qname=\"").".".$codewriter->stringifyCode($attkey).".'\"'");
122
+        }
122 123
 
123 124
         $codewriter->doElse();
124 125
         $codewriter->doSetVar($attkey, "''");
@@ -166,7 +167,9 @@  discard block
 block discarded – undo
166 167
 
167 168
     public function after(PHPTAL_Php_CodeWriter $codewriter)
168 169
     {
169
-        foreach ($this->vars_to_recycle as $var) $codewriter->recycleTempVariable($var);
170
+        foreach ($this->vars_to_recycle as $var) {
171
+            $codewriter->recycleTempVariable($var);
172
+        }
170 173
     }
171 174
 
172 175
     public function talesChainNothingKeyword(PHPTAL_Php_TalesChainExecutor $executor)
@@ -202,10 +205,11 @@  discard block
 block discarded – undo
202 205
         }
203 206
         $executor->doIf($condition);
204 207
 
205
-        if ($this->_echoType == PHPTAL_Php_Attribute::ECHO_STRUCTURE)
206
-            $value = $codewriter->stringifyCode($this->_attkey);
207
-        else
208
-            $value = $codewriter->escapeCode($this->_attkey);
208
+        if ($this->_echoType == PHPTAL_Php_Attribute::ECHO_STRUCTURE) {
209
+                    $value = $codewriter->stringifyCode($this->_attkey);
210
+        } else {
211
+                    $value = $codewriter->escapeCode($this->_attkey);
212
+        }
209 213
 
210 214
         $codewriter->doSetVar($this->_attkey, $codewriter->str(" {$this->_attribute}=\"").".$value.'\"'");
211 215
     }
Please login to merge, or discard this patch.
classes/PHPTAL/Php/Attribute/TAL/Condition.php 2 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -61,6 +61,10 @@
 block discarded – undo
61 61
     }
62 62
 
63 63
 
64
+    /**
65
+     * @param string $exp
66
+     * @param boolean $islast
67
+     */
64 68
     public function talesChainPart(PHPTAL_Php_TalesChainExecutor $executor, $exp, $islast)
65 69
     {
66 70
         // check if the expression is empty
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
             $code = 'false';
53 53
         }
54 54
 
55
-        $codewriter->doIf('phptal_true(' . $code . ')');
55
+        $codewriter->doIf('phptal_true('.$code.')');
56 56
     }
57 57
 
58 58
     public function after(PHPTAL_Php_CodeWriter $codewriter)
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
     {
66 66
         // check if the expression is empty
67 67
         if ($exp !== 'false') {
68
-            $this->expressions[] = '!phptal_isempty(' . $exp . ')';
68
+            $this->expressions[] = '!phptal_isempty('.$exp.')';
69 69
         }
70 70
 
71 71
         if ($islast) {
72 72
             // for the last one in the chain build a ORed condition
73
-            $executor->getCodeWriter()->doIf( implode(' || ', $this->expressions ) );
73
+            $executor->getCodeWriter()->doIf(implode(' || ', $this->expressions));
74 74
             // The executor will always end an if so we output a dummy if
75 75
             $executor->doIf('false');
76 76
         }
Please login to merge, or discard this patch.
classes/PHPTAL/Php/State.php 3 patches
Doc Comments   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
     /**
99 99
      * Syntax rules to follow in generated code
100 100
      *
101
-     * @return one of PHPTAL::XHTML, PHPTAL::XML, PHPTAL::HTML5
101
+     * @return integer of PHPTAL::XHTML, PHPTAL::XML, PHPTAL::HTML5
102 102
      */
103 103
     public function getOutputMode()
104 104
     {
@@ -183,6 +183,9 @@  discard block
 block discarded – undo
183 183
         return $this->_interpolateTalesVarsCallback($matches, 'cdata');
184 184
     }
185 185
 
186
+    /**
187
+     * @param string $format
188
+     */
186 189
     private function _interpolateTalesVarsCallback($matches, $format)
187 190
     {
188 191
         // replaces $${ with literal ${ (or $$$${ with $${ etc)
@@ -225,7 +228,7 @@  discard block
 block discarded – undo
225 228
      * expects PHP code and returns PHP code that will generate escaped string
226 229
      * Optimizes case when PHP string is given.
227 230
      *
228
-     * @return php code
231
+     * @return string code
229 232
      */
230 233
     public function htmlchars($php)
231 234
     {
Please login to merge, or discard this patch.
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/TalesInternal.php 3 patches
Doc Comments   +5 added lines patch added patch discarded remove patch
@@ -228,6 +228,7 @@  discard block
 block discarded – undo
228 228
 
229 229
     /**
230 230
      * @param string $tales_prefix prefix added to all TALES in the string
231
+     * @param boolean $nothrow
231 232
      */
232 233
     static public function parseString($expression, $nothrow, $tales_prefix)
233 234
     {
@@ -435,6 +436,10 @@  discard block
 block discarded – undo
435 436
      * helper function for compileToPHPExpression
436 437
      * @access private
437 438
      */
439
+
440
+    /**
441
+     * @param boolean $nothrow
442
+     */
438 443
     private static function convertExpressionsToExpression(array $array, $nothrow)
439 444
     {
440 445
         if (count($array)==1) return '($ctx->noThrow('.($nothrow?'true':'false').')||1?('.
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.
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/PreFilter/Compress.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -139,6 +139,9 @@
 block discarded – undo
139 139
         'html','head','table','thead','tfoot','select','optgroup','dl','ol','ul','tr','datalist',
140 140
     );
141 141
 
142
+    /**
143
+     * @return PHPTAL_Dom_Element
144
+     */
142 145
     private function hasNoInterelementSpace(PHPTAL_Dom_Element $element)
143 146
     {
144 147
         if ($element->getLocalName() === 'block'
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -23,13 +23,13 @@  discard block
 block discarded – undo
23 23
      * keeps track whether last element had trailing whitespace (or didn't need it).
24 24
      * If had_space==false, next element must keep leading space.
25 25
      */
26
-    private $had_space=false;
26
+    private $had_space = false;
27 27
 
28 28
     /**
29 29
      * last text node before closing tag that may need trailing whitespace trimmed.
30 30
      * It's often last-child, but comments, multiple end tags make that trickier.
31 31
      */
32
-    private $most_recent_text_node=null;
32
+    private $most_recent_text_node = null;
33 33
 
34 34
     function filterDOM(PHPTAL_Dom_Element $root)
35 35
     {
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
         }
42 42
 
43 43
         // tal:replace makes element behave like text
44
-        if ($root->getAttributeNS('http://xml.zope.org/namespaces/tal','replace')) {
44
+        if ($root->getAttributeNS('http://xml.zope.org/namespaces/tal', 'replace')) {
45 45
             $this->most_recent_text_node = null;
46 46
             $this->had_space = false;
47 47
             return;
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 
56 56
         // mostly block-level elements
57 57
         // if element is conditional, it may not always break the line
58
-        $breaks_line = $no_spaces || ($this->breaksLine($root) && !$root->getAttributeNS('http://xml.zope.org/namespaces/tal','condition'));
58
+        $breaks_line = $no_spaces || ($this->breaksLine($root) && !$root->getAttributeNS('http://xml.zope.org/namespaces/tal', 'condition'));
59 59
 
60 60
         // start tag newline
61 61
         if ($breaks_line) {
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
             // HTML 5 (9.1.2.5) specifies quirk that a first *single* newline in <pre> can be removed
78 78
             if (count($root->childNodes) && $root->childNodes[0] instanceof PHPTAL_Dom_Text) {
79 79
                 if (preg_match('/^\n[^\n]/', $root->childNodes[0]->getValueEscaped())) {
80
-                    $root->childNodes[0]->setValueEscaped(substr($root->childNodes[0]->getValueEscaped(),1));
80
+                    $root->childNodes[0]->setValueEscaped(substr($root->childNodes[0]->getValueEscaped(), 1));
81 81
                 }
82 82
             }
83 83
             $this->findElementToFilter($root);
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
                 // collapsed whitespace-only nodes are ignored (otherwise trimming of most_recent_text_node would be useless)
102 102
                 if ($norm !== '') {
103 103
                     $this->most_recent_text_node = $node;
104
-                    $this->had_space = (substr($norm,-1) == ' ');
104
+                    $this->had_space = (substr($norm, -1) == ' ');
105 105
                 }
106 106
             } else if ($node instanceof PHPTAL_Dom_Element) {
107 107
                 $this->filterDOM($node);
@@ -115,12 +115,12 @@  discard block
 block discarded – undo
115 115
         }
116 116
 
117 117
         // repeated element may need trailing space.
118
-        if (!$breaks_line && $root->getAttributeNS('http://xml.zope.org/namespaces/tal','repeat')) {
118
+        if (!$breaks_line && $root->getAttributeNS('http://xml.zope.org/namespaces/tal', 'repeat')) {
119 119
             $this->most_recent_text_node = null;
120 120
         }
121 121
 
122 122
         // tal:content may replace element with something without space
123
-        if (!$breaks_line && $root->getAttributeNS('http://xml.zope.org/namespaces/tal','content')) {
123
+        if (!$breaks_line && $root->getAttributeNS('http://xml.zope.org/namespaces/tal', 'content')) {
124 124
             $this->had_space = false;
125 125
             $this->most_recent_text_node = null;
126 126
         }
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
     }
137 137
 
138 138
     private static $no_interelement_space = array(
139
-        'html','head','table','thead','tfoot','select','optgroup','dl','ol','ul','tr','datalist',
139
+        'html', 'head', 'table', 'thead', 'tfoot', 'select', 'optgroup', 'dl', 'ol', 'ul', 'tr', 'datalist',
140 140
     );
141 141
 
142 142
     private function hasNoInterelementSpace(PHPTAL_Dom_Element $element)
@@ -155,15 +155,15 @@  discard block
 block discarded – undo
155 155
      *  li is deliberately omitted, as it's commonly used with display:inline in menus.
156 156
      */
157 157
     private static $breaks_line = array(
158
-        'address','article','aside','base','blockquote','body','br','dd','div','dl','dt','fieldset','figure',
159
-        'footer','form','h1','h2','h3','h4','h5','h6','head','header','hgroup','hr','html','legend','link',
160
-        'meta','nav','ol','option','p','param','pre','section','style','table','tbody','td','th','thead',
161
-        'title','tr','ul','details',
158
+        'address', 'article', 'aside', 'base', 'blockquote', 'body', 'br', 'dd', 'div', 'dl', 'dt', 'fieldset', 'figure',
159
+        'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'legend', 'link',
160
+        'meta', 'nav', 'ol', 'option', 'p', 'param', 'pre', 'section', 'style', 'table', 'tbody', 'td', 'th', 'thead',
161
+        'title', 'tr', 'ul', 'details',
162 162
     );
163 163
 
164 164
     private function breaksLine(PHPTAL_Dom_Element $element)
165 165
     {
166
-        if ($element->getAttributeNS('http://xml.zope.org/namespaces/metal','define-macro')) {
166
+        if ($element->getAttributeNS('http://xml.zope.org/namespaces/metal', 'define-macro')) {
167 167
             return true;
168 168
         }
169 169
 
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
      *  replaced elements need to preserve spaces before and after
184 184
      */
185 185
     private static $inline_blocks = array(
186
-        'select','input','button','img','textarea','output','progress','meter',
186
+        'select', 'input', 'button', 'img', 'textarea', 'output', 'progress', 'meter',
187 187
     );
188 188
 
189 189
     private function isInlineBlock(PHPTAL_Dom_Element $element)
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 	 * pre-defined order of attributes roughly by popularity
220 220
 	 */
221 221
 	private static $attributes_order = array(
222
-        'href','src','class','rel','type','title','width','height','alt','content','name','style','lang','id',
222
+        'href', 'src', 'class', 'rel', 'type', 'title', 'width', 'height', 'alt', 'content', 'name', 'style', 'lang', 'id',
223 223
     );
224 224
 
225 225
 	/**
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 		$b_index = array_search($b, self::$attributes_order);
233 233
 
234 234
 		if ($a_index !== false && $b_index !== false) {
235
-			return $a_index - $b_index;
235
+			return $a_index-$b_index;
236 236
 		}
237 237
 		if ($a_index === false && $b_index === false) {
238 238
 			return strcmp($a, $b);
@@ -256,26 +256,26 @@  discard block
 block discarded – undo
256 256
 
257 257
         // <meta charset>
258 258
 	    if ('meta' === $element->getLocalName() &&
259
-	        $element->getAttributeNS('','http-equiv') === 'Content-Type') {
260
-	            $element->removeAttributeNS('','http-equiv');
261
-	            $element->removeAttributeNS('','content');
262
-	            $element->setAttributeNS('','charset',strtolower($this->getPHPTAL()->getEncoding()));
259
+	        $element->getAttributeNS('', 'http-equiv') === 'Content-Type') {
260
+	            $element->removeAttributeNS('', 'http-equiv');
261
+	            $element->removeAttributeNS('', 'content');
262
+	            $element->setAttributeNS('', 'charset', strtolower($this->getPHPTAL()->getEncoding()));
263 263
         }
264
-        elseif (('link' === $element->getLocalName() && $element->getAttributeNS('','rel') === 'stylesheet') ||
264
+        elseif (('link' === $element->getLocalName() && $element->getAttributeNS('', 'rel') === 'stylesheet') ||
265 265
             ('style' === $element->getLocalName())) {
266 266
             // There's only one type of stylesheets that works.
267
-            $element->removeAttributeNS('','type');
267
+            $element->removeAttributeNS('', 'type');
268 268
 
269 269
         } elseif ('script' === $element->getLocalName()) {
270
-            $element->removeAttributeNS('','language');
270
+            $element->removeAttributeNS('', 'language');
271 271
 
272 272
             // Only remove type that matches default. E4X, vbscript, coffeescript, etc. must be preserved
273
-            $type = $element->getAttributeNS('','type');
273
+            $type = $element->getAttributeNS('', 'type');
274 274
             $is_std = preg_match('/^(?:text|application)\/(?:ecma|java)script(\s*;\s*charset\s*=\s*[^;]*)?$/', $type);
275 275
 
276 276
             // Remote scripts should have type specified in HTTP headers.
277
-            if ($is_std || $element->getAttributeNS('','src')) {
278
-                $element->removeAttributeNS('','type');
277
+            if ($is_std || $element->getAttributeNS('', 'src')) {
278
+                $element->removeAttributeNS('', 'type');
279 279
             }
280 280
         }
281 281
     }
Please login to merge, or discard this 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.
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
         }
173 173
 
174 174
         if ($element->getNamespaceURI() !== 'http://www.w3.org/1999/xhtml'
175
-	        && $element->getNamespaceURI() !== '') {
176
-	        return false;
175
+            && $element->getNamespaceURI() !== '') {
176
+            return false;
177 177
         }
178 178
 
179 179
         return in_array($element->getLocalName(), self::$breaks_line);
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
     private function isInlineBlock(PHPTAL_Dom_Element $element)
190 190
     {
191 191
         if ($element->getNamespaceURI() !== 'http://www.w3.org/1999/xhtml'
192
-	        && $element->getNamespaceURI() !== '') {
193
-	        return false;
192
+            && $element->getNamespaceURI() !== '') {
193
+            return false;
194 194
         }
195 195
 
196 196
         return in_array($element->getLocalName(), self::$inline_blocks);
@@ -209,45 +209,45 @@  discard block
 block discarded – undo
209 209
             $attrs_by_qname[$attrnode->getQualifiedName()] = $attrnode;
210 210
         }
211 211
 
212
-	if (count($attrs_by_qname) > 1) {
213
-		uksort($attrs_by_qname, array($this, 'compareQNames'));
214
-		$element->setAttributeNodes(array_values($attrs_by_qname));
215
-	}
212
+    if (count($attrs_by_qname) > 1) {
213
+        uksort($attrs_by_qname, array($this, 'compareQNames'));
214
+        $element->setAttributeNodes(array_values($attrs_by_qname));
215
+    }
216 216
     }
217 217
 
218 218
     /**
219
-	 * pre-defined order of attributes roughly by popularity
220
-	 */
221
-	private static $attributes_order = array(
219
+     * pre-defined order of attributes roughly by popularity
220
+     */
221
+    private static $attributes_order = array(
222 222
         'href','src','class','rel','type','title','width','height','alt','content','name','style','lang','id',
223 223
     );
224 224
 
225
-	/**
226
-	 * compare names according to $attributes_order array.
227
-	 * Elements that are not in array, are considered greater than all elements in array,
228
-	 * and are sorted alphabetically.
229
-	 */
230
-	private static function compareQNames($a, $b) {
231
-		$a_index = array_search($a, self::$attributes_order);
232
-		$b_index = array_search($b, self::$attributes_order);
233
-
234
-		if ($a_index !== false && $b_index !== false) {
235
-			return $a_index - $b_index;
236
-		}
237
-		if ($a_index === false && $b_index === false) {
238
-			return strcmp($a, $b);
239
-		}
240
-		return ($a_index === false) ? 1 : -1;
241
-	}
225
+    /**
226
+     * compare names according to $attributes_order array.
227
+     * Elements that are not in array, are considered greater than all elements in array,
228
+     * and are sorted alphabetically.
229
+     */
230
+    private static function compareQNames($a, $b) {
231
+        $a_index = array_search($a, self::$attributes_order);
232
+        $b_index = array_search($b, self::$attributes_order);
233
+
234
+        if ($a_index !== false && $b_index !== false) {
235
+            return $a_index - $b_index;
236
+        }
237
+        if ($a_index === false && $b_index === false) {
238
+            return strcmp($a, $b);
239
+        }
240
+        return ($a_index === false) ? 1 : -1;
241
+    }
242 242
 
243 243
     /**
244 244
      * HTML5 doesn't care about boilerplate
245 245
      */
246
-	private function elementSpecificOptimizations(PHPTAL_Dom_Element $element)
247
-	{
248
-	    if ($element->getNamespaceURI() !== 'http://www.w3.org/1999/xhtml'
249
-	     && $element->getNamespaceURI() !== '') {
250
-	        return;
246
+    private function elementSpecificOptimizations(PHPTAL_Dom_Element $element)
247
+    {
248
+        if ($element->getNamespaceURI() !== 'http://www.w3.org/1999/xhtml'
249
+         && $element->getNamespaceURI() !== '') {
250
+            return;
251 251
         }
252 252
 
253 253
         if ($this->getPHPTAL()->getOutputMode() !== PHPTAL::HTML5) {
@@ -255,11 +255,11 @@  discard block
 block discarded – undo
255 255
         }
256 256
 
257 257
         // <meta charset>
258
-	    if ('meta' === $element->getLocalName() &&
259
-	        $element->getAttributeNS('','http-equiv') === 'Content-Type') {
260
-	            $element->removeAttributeNS('','http-equiv');
261
-	            $element->removeAttributeNS('','content');
262
-	            $element->setAttributeNS('','charset',strtolower($this->getPHPTAL()->getEncoding()));
258
+        if ('meta' === $element->getLocalName() &&
259
+            $element->getAttributeNS('','http-equiv') === 'Content-Type') {
260
+                $element->removeAttributeNS('','http-equiv');
261
+                $element->removeAttributeNS('','content');
262
+                $element->setAttributeNS('','charset',strtolower($this->getPHPTAL()->getEncoding()));
263 263
         }
264 264
         elseif (('link' === $element->getLocalName() && $element->getAttributeNS('','rel') === 'stylesheet') ||
265 265
             ('style' === $element->getLocalName())) {
Please login to merge, or discard this patch.
classes/PHPTAL/PreFilter/Normalize.php 3 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -86,6 +86,7 @@
 block discarded – undo
86 86
 
87 87
     /**
88 88
      * does not trim
89
+     * @return string
89 90
      */
90 91
     protected function normalizeSpace($text, $encoding)
91 92
     {
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
                     $root->removeChild($node);
51 51
                 } else if ($lastTextNode) {
52 52
                     // "foo " . " bar" gives 2 spaces.
53
-                    $norm = $lastTextNode->getValueEscaped().ltrim($norm,' ');
53
+                    $norm = $lastTextNode->getValueEscaped().ltrim($norm, ' ');
54 54
 
55 55
                     $lastTextNode->setValueEscaped($norm); // assumes all nodes use same encoding (they do)
56 56
                     $root->removeChild($node);
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      */
90 90
     protected function normalizeSpace($text, $encoding)
91 91
     {
92
-        $utf_regex_mod = ($encoding=='UTF-8'?'u':'');
92
+        $utf_regex_mod = ($encoding == 'UTF-8' ? 'u' : '');
93 93
 
94 94
         return preg_replace('/[ \t\r\n]+/'.$utf_regex_mod, ' ', $text); // \s removes nbsp
95 95
     }
Please login to merge, or discard this 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/StringSource.php 1 patch
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -21,6 +21,10 @@
 block discarded – undo
21 21
 {
22 22
     const NO_PATH_PREFIX = '<string ';
23 23
 
24
+    /**
25
+     * @param string $data
26
+     * @param string $realpath
27
+     */
24 28
     public function __construct($data, $realpath = null)
25 29
     {
26 30
         $this->_data = $data;
Please login to merge, or discard this patch.
classes/PHPTAL/TalesRegistry.php 1 patch
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@
 block discarded – undo
75 75
      * callback.
76 76
      *
77 77
      * @param string $prefix
78
-     * @param mixed $callback
78
+     * @param string[] $callback
79 79
      * @param bool $is_fallback if true, method will be used as last resort (if there's no phptal_tales_foo)
80 80
      */
81 81
     public function registerPrefix($prefix, $callback, $is_fallback = false)
Please login to merge, or discard this patch.
tools/phptal_lint.php 3 patches
Doc Comments   +13 added lines patch added patch discarded remove patch
@@ -127,6 +127,10 @@  discard block
 block discarded – undo
127 127
         echo "  Use 'phptal_lint.php .' to scan current directory\n\n";
128 128
     }
129 129
 
130
+    /**
131
+     * @param integer $num
132
+     * @param string $word
133
+     */
130 134
     function plural($num, $word)
131 135
     {
132 136
         if ($num == 1) return "$num $word";
@@ -196,6 +200,9 @@  discard block
 block discarded – undo
196 200
     public $skipped = 0, $skipped_filenames = array();
197 201
     public $checked = 0;
198 202
 
203
+    /**
204
+     * @param boolean $bool
205
+     */
199 206
     function skipUnknownModifiers($bool)
200 207
     {
201 208
         $this->skipUnknownModifiers = $bool;
@@ -205,11 +212,17 @@  discard block
 block discarded – undo
205 212
         $this->accept_pattern = '/\.(?:' . implode('|', $ext) . ')$/i';
206 213
     }
207 214
 
215
+    /**
216
+     * @param string $symbol
217
+     */
208 218
     protected function reportProgress($symbol)
209 219
     {
210 220
         echo $symbol;
211 221
     }
212 222
 
223
+    /**
224
+     * @param string $path
225
+     */
213 226
     function scan($path)
214 227
     {
215 228
         foreach (new DirectoryIterator($path) as $entry) {
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
     {
28 28
         try
29 29
         {
30
-            if (! empty($_SERVER['REQUEST_URI'])) {
30
+            if (!empty($_SERVER['REQUEST_URI'])) {
31 31
                 throw new Exception("Please use this tool from command line");
32 32
             }
33 33
 
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
                 echo " Skipped ".$this->plural($lint->skipped, "non-template file").".";
77 77
             }
78 78
             echo "\n";
79
-            if (! $custom_extensions && count($lint->skipped_filenames)) {
79
+            if (!$custom_extensions && count($lint->skipped_filenames)) {
80 80
                 echo "Skipped file(s): ", implode(', ', array_keys($lint->skipped_filenames)), ".\n";
81 81
             }
82 82
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
                 echo "\n";
87 87
                 exit(2);
88 88
             } else if (count($lint->warnings)) {
89
-                echo "Found ".$this->plural(count($lint->warnings),"warning").":\n";
89
+                echo "Found ".$this->plural(count($lint->warnings), "warning").":\n";
90 90
                 $this->display_erorr_array($lint->warnings);
91 91
                 echo "\n";
92 92
                 exit(0);
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
                 exit($lint->checked ? 0 : 1);
96 96
             }
97 97
         }
98
-        catch(Exception $e) {
99
-            fwrite(STDERR, $e->getMessage() . "\n");
98
+        catch (Exception $e) {
99
+            fwrite(STDERR, $e->getMessage()."\n");
100 100
             $errcode = $e->getCode();
101 101
             exit($errcode ? $errcode : 1);
102 102
         }
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
     function usage()
120 120
     {
121 121
         $this->require_phptal();
122
-        echo "PHPTAL Lint 1.1.3 (PHPTAL ", strtr(PHPTAL_VERSION,"_","."), ")\n";
122
+        echo "PHPTAL Lint 1.1.3 (PHPTAL ", strtr(PHPTAL_VERSION, "_", "."), ")\n";
123 123
 
124 124
         echo "Usage: phptal_lint.php [-e extensions] [-i php_file_or_directory] file_or_directory_to_check ...\n";
125 125
         echo "  -e comma-separated list of extensions\n";
@@ -136,11 +136,11 @@  discard block
 block discarded – undo
136 136
     function extended_getopt(array $options)
137 137
     {
138 138
         $results = array('--filenames--'=>array());
139
-        for ($i = 1; $i < count($_SERVER['argv']); $i ++) {
139
+        for ($i = 1; $i < count($_SERVER['argv']); $i++) {
140 140
             if (in_array($_SERVER['argv'][$i], $options)) {
141
-                $results[substr($_SERVER['argv'][$i], 1)][] = $_SERVER['argv'][++ $i];
141
+                $results[substr($_SERVER['argv'][$i], 1)][] = $_SERVER['argv'][++$i];
142 142
             } else if ($_SERVER['argv'][$i] == '--') {
143
-                $results['--filenames--'] = array_merge($results['--filenames--'], array_slice($_SERVER['argv'],$i+1));
143
+                $results['--filenames--'] = array_merge($results['--filenames--'], array_slice($_SERVER['argv'], $i+1));
144 144
                 break;
145 145
             } else if (substr($_SERVER['argv'][$i], 0, 1) == '-') {
146 146
                     $this->usage();
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
     {
172 172
         if (class_exists('PHPTAL', false)) return;
173 173
 
174
-        $myphptal = dirname(__FILE__) . '/../classes/PHPTAL.php';
174
+        $myphptal = dirname(__FILE__).'/../classes/PHPTAL.php';
175 175
         if (file_exists($myphptal)) {
176 176
             require_once $myphptal;
177 177
         } else {
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
     }
203 203
 
204 204
     function acceptExtensions(array $ext) {
205
-        $this->accept_pattern = '/\.(?:' . implode('|', $ext) . ')$/i';
205
+        $this->accept_pattern = '/\.(?:'.implode('|', $ext).')$/i';
206 206
     }
207 207
 
208 208
     protected function reportProgress($symbol)
@@ -226,17 +226,17 @@  discard block
 block discarded – undo
226 226
 
227 227
             if ($entry->isDir()) {
228 228
                 $this->reportProgress('.');
229
-                $this->scan($path . DIRECTORY_SEPARATOR . $filename);
229
+                $this->scan($path.DIRECTORY_SEPARATOR.$filename);
230 230
                 continue;
231 231
             }
232 232
 
233
-            if (! preg_match($this->accept_pattern, $filename)) {
233
+            if (!preg_match($this->accept_pattern, $filename)) {
234 234
                 $this->skipped++;
235 235
                 $this->skipped_filenames[$filename] = true;
236 236
                 continue;
237 237
             }
238 238
 
239
-            $result = $this->testFile($path . DIRECTORY_SEPARATOR . $filename);
239
+            $result = $this->testFile($path.DIRECTORY_SEPARATOR.$filename);
240 240
 
241 241
             if (self::TEST_OK == $result) {
242 242
                 $this->reportProgress('.');
@@ -258,25 +258,25 @@  discard block
 block discarded – undo
258 258
     function testFile($fullpath)
259 259
     {
260 260
         try {
261
-            $this->checked ++;
261
+            $this->checked++;
262 262
             $phptal = new PHPTAL($fullpath);
263 263
             $phptal->setForceReparse(true);
264 264
             $phptal->prepare();
265 265
             return self::TEST_OK;
266 266
         }
267
-        catch(PHPTAL_UnknownModifierException $e) {
267
+        catch (PHPTAL_UnknownModifierException $e) {
268 268
             if ($this->skipUnknownModifiers && is_callable(array($e, 'getModifierName'))) {
269 269
                 $this->warnings[] = array(dirname($fullpath), basename($fullpath), "Unknown expression modifier: ".$e->getModifierName()." (use -i to include your custom modifier functions)", $e->getLine());
270 270
                 return self::TEST_SKIPPED;
271 271
             }
272 272
             $log_exception = $e;
273 273
         }
274
-        catch(Exception $e) {
274
+        catch (Exception $e) {
275 275
             $log_exception = $e;
276 276
         }
277 277
 
278 278
         // Takes exception from either of the two catch blocks above
279
-        $this->errors[] = array(dirname($fullpath) , basename($fullpath) , $log_exception->getMessage() , $log_exception->getLine());
279
+        $this->errors[] = array(dirname($fullpath), basename($fullpath), $log_exception->getMessage(), $log_exception->getLine());
280 280
         return self::TEST_ERROR;
281 281
     }
282 282
 }
Please login to merge, or discard this patch.
Braces   +9 added lines, -8 removed lines patch added patch discarded remove patch
@@ -94,8 +94,7 @@  discard block
 block discarded – undo
94 94
                 echo "No errors found!\n";
95 95
                 exit($lint->checked ? 0 : 1);
96 96
             }
97
-        }
98
-        catch(Exception $e) {
97
+        } catch(Exception $e) {
99 98
             fwrite(STDERR, $e->getMessage() . "\n");
100 99
             $errcode = $e->getCode();
101 100
             exit($errcode ? $errcode : 1);
@@ -129,7 +128,9 @@  discard block
 block discarded – undo
129 128
 
130 129
     function plural($num, $word)
131 130
     {
132
-        if ($num == 1) return "$num $word";
131
+        if ($num == 1) {
132
+            return "$num $word";
133
+        }
133 134
         return "$num {$word}s";
134 135
     }
135 136
 
@@ -169,7 +170,9 @@  discard block
 block discarded – undo
169 170
 
170 171
     function require_phptal()
171 172
     {
172
-        if (class_exists('PHPTAL', false)) return;
173
+        if (class_exists('PHPTAL', false)) {
174
+            return;
175
+        }
173 176
 
174 177
         $myphptal = dirname(__FILE__) . '/../classes/PHPTAL.php';
175 178
         if (file_exists($myphptal)) {
@@ -263,15 +266,13 @@  discard block
 block discarded – undo
263 266
             $phptal->setForceReparse(true);
264 267
             $phptal->prepare();
265 268
             return self::TEST_OK;
266
-        }
267
-        catch(PHPTAL_UnknownModifierException $e) {
269
+        } catch(PHPTAL_UnknownModifierException $e) {
268 270
             if ($this->skipUnknownModifiers && is_callable(array($e, 'getModifierName'))) {
269 271
                 $this->warnings[] = array(dirname($fullpath), basename($fullpath), "Unknown expression modifier: ".$e->getModifierName()." (use -i to include your custom modifier functions)", $e->getLine());
270 272
                 return self::TEST_SKIPPED;
271 273
             }
272 274
             $log_exception = $e;
273
-        }
274
-        catch(Exception $e) {
275
+        } catch(Exception $e) {
275 276
             $log_exception = $e;
276 277
         }
277 278
 
Please login to merge, or discard this patch.