@@ -94,7 +94,9 @@ discard block |
||
94 | 94 | $value = ''; |
95 | 95 | foreach ($this->childNodes as $node) { |
96 | 96 | // leave it alone if there is CDATA, comment, or anything else. |
97 | - if (!$node instanceof PHPTAL_Dom_Text) return; |
|
97 | + if (!$node instanceof PHPTAL_Dom_Text) { |
|
98 | + return; |
|
99 | + } |
|
98 | 100 | |
99 | 101 | $value .= $node->getValue(); |
100 | 102 | $valueEscaped .= $node->getValueEscaped(); |
@@ -118,7 +120,9 @@ discard block |
||
118 | 120 | |
119 | 121 | public function appendChild(PHPTAL_Dom_Node $child) |
120 | 122 | { |
121 | - if ($child->parentNode) $child->parentNode->removeChild($child); |
|
123 | + if ($child->parentNode) { |
|
124 | + $child->parentNode->removeChild($child); |
|
125 | + } |
|
122 | 126 | $child->parentNode = $this; |
123 | 127 | $this->childNodes[] = $child; |
124 | 128 | } |
@@ -141,7 +145,9 @@ discard block |
||
141 | 145 | if ($node === $oldElement) { |
142 | 146 | $oldElement->parentNode = NULL; |
143 | 147 | |
144 | - if ($newElement->parentNode) $newElement->parentNode->removeChild($child); |
|
148 | + if ($newElement->parentNode) { |
|
149 | + $newElement->parentNode->removeChild($child); |
|
150 | + } |
|
145 | 151 | $newElement->parentNode = $this; |
146 | 152 | |
147 | 153 | $this->childNodes[$k] = $newElement; |
@@ -182,8 +188,7 @@ discard block |
||
182 | 188 | } |
183 | 189 | |
184 | 190 | $this->generateSurroundFoot($codewriter); |
185 | - } |
|
186 | - catch(PHPTAL_TemplateException $e) { |
|
191 | + } catch(PHPTAL_TemplateException $e) { |
|
187 | 192 | $e->hintSrcPosition($this->getSourceFile(), $this->getSourceLine()); |
188 | 193 | throw $e; |
189 | 194 | } |
@@ -212,7 +217,9 @@ discard block |
||
212 | 217 | /** Returns true if the element contains specified PHPTAL attribute. */ |
213 | 218 | public function hasAttribute($qname) |
214 | 219 | { |
215 | - foreach($this->attribute_nodes as $attr) if ($attr->getQualifiedName() == $qname) return true; |
|
220 | + foreach($this->attribute_nodes as $attr) { |
|
221 | + if ($attr->getQualifiedName() == $qname) return true; |
|
222 | + } |
|
216 | 223 | return false; |
217 | 224 | } |
218 | 225 | |
@@ -224,7 +231,9 @@ discard block |
||
224 | 231 | public function getAttributeNodeNS($ns_uri, $localname) |
225 | 232 | { |
226 | 233 | foreach ($this->attribute_nodes as $attr) { |
227 | - if ($attr->getNamespaceURI() === $ns_uri && $attr->getLocalName() === $localname) return $attr; |
|
234 | + if ($attr->getNamespaceURI() === $ns_uri && $attr->getLocalName() === $localname) { |
|
235 | + return $attr; |
|
236 | + } |
|
228 | 237 | } |
229 | 238 | return null; |
230 | 239 | } |
@@ -241,7 +250,9 @@ discard block |
||
241 | 250 | |
242 | 251 | public function getAttributeNode($qname) |
243 | 252 | { |
244 | - foreach($this->attribute_nodes as $attr) if ($attr->getQualifiedName() === $qname) return $attr; |
|
253 | + foreach($this->attribute_nodes as $attr) { |
|
254 | + if ($attr->getQualifiedName() === $qname) return $attr; |
|
255 | + } |
|
245 | 256 | return null; |
246 | 257 | } |
247 | 258 | |
@@ -252,7 +263,9 @@ discard block |
||
252 | 263 | */ |
253 | 264 | public function getOrCreateAttributeNode($qname) |
254 | 265 | { |
255 | - if ($attr = $this->getAttributeNode($qname)) return $attr; |
|
266 | + if ($attr = $this->getAttributeNode($qname)) { |
|
267 | + return $attr; |
|
268 | + } |
|
256 | 269 | |
257 | 270 | $attr = new PHPTAL_Dom_Attr($qname, "", null, 'UTF-8'); // FIXME: should find namespace and encoding |
258 | 271 | $this->attribute_nodes[] = $attr; |
@@ -294,19 +307,27 @@ discard block |
||
294 | 307 | */ |
295 | 308 | public function hasRealContent() |
296 | 309 | { |
297 | - if (count($this->contentAttributes) > 0) return true; |
|
310 | + if (count($this->contentAttributes) > 0) { |
|
311 | + return true; |
|
312 | + } |
|
298 | 313 | |
299 | 314 | foreach ($this->childNodes as $node) { |
300 | - if (!$node instanceof PHPTAL_Dom_Text || $node->getValueEscaped() !== '') return true; |
|
315 | + if (!$node instanceof PHPTAL_Dom_Text || $node->getValueEscaped() !== '') { |
|
316 | + return true; |
|
317 | + } |
|
301 | 318 | } |
302 | 319 | return false; |
303 | 320 | } |
304 | 321 | |
305 | 322 | public function hasRealAttributes() |
306 | 323 | { |
307 | - if ($this->hasAttributeNS('http://xml.zope.org/namespaces/tal', 'attributes')) return true; |
|
324 | + if ($this->hasAttributeNS('http://xml.zope.org/namespaces/tal', 'attributes')) { |
|
325 | + return true; |
|
326 | + } |
|
308 | 327 | foreach ($this->attribute_nodes as $attr) { |
309 | - if ($attr->getReplacedState() !== PHPTAL_Dom_Attr::HIDDEN) return true; |
|
328 | + if ($attr->getReplacedState() !== PHPTAL_Dom_Attr::HIDDEN) { |
|
329 | + return true; |
|
330 | + } |
|
310 | 331 | } |
311 | 332 | return false; |
312 | 333 | } |
@@ -322,7 +343,9 @@ discard block |
||
322 | 343 | |
323 | 344 | public function generateHead(PHPTAL_Php_CodeWriter $codewriter) |
324 | 345 | { |
325 | - if ($this->headFootDisabled) return; |
|
346 | + if ($this->headFootDisabled) { |
|
347 | + return; |
|
348 | + } |
|
326 | 349 | if ($this->headPrintCondition) { |
327 | 350 | $codewriter->doIf($this->headPrintCondition); |
328 | 351 | } |
@@ -355,9 +378,10 @@ discard block |
||
355 | 378 | foreach($this->childNodes as $child) { |
356 | 379 | $child->generateCode($codewriter); |
357 | 380 | } |
358 | - } |
|
359 | - else foreach($this->contentAttributes as $att) { |
|
381 | + } else { |
|
382 | + foreach($this->contentAttributes as $att) { |
|
360 | 383 | $att->before($codewriter); |
384 | + } |
|
361 | 385 | $att->after($codewriter); |
362 | 386 | } |
363 | 387 | } |
@@ -365,10 +389,12 @@ discard block |
||
365 | 389 | |
366 | 390 | public function generateFoot(PHPTAL_Php_CodeWriter $codewriter) |
367 | 391 | { |
368 | - if ($this->headFootDisabled) |
|
369 | - return; |
|
370 | - if ($this->isEmptyNode($codewriter->getOutputMode())) |
|
371 | - return; |
|
392 | + if ($this->headFootDisabled) { |
|
393 | + return; |
|
394 | + } |
|
395 | + if ($this->isEmptyNode($codewriter->getOutputMode())) { |
|
396 | + return; |
|
397 | + } |
|
372 | 398 | |
373 | 399 | if ($this->footPrintCondition) { |
374 | 400 | $codewriter->doIf($this->footPrintCondition); |
@@ -481,15 +507,16 @@ discard block |
||
481 | 507 | $handler = $nsattr->createAttributeHandler($this, $domattr->getValue()); |
482 | 508 | $this->talHandlers[$prio] = $handler; |
483 | 509 | |
484 | - if ($nsattr instanceof PHPTAL_NamespaceAttributeSurround) |
|
485 | - $this->surroundAttributes[] = $handler; |
|
486 | - else if ($nsattr instanceof PHPTAL_NamespaceAttributeReplace) |
|
487 | - $this->replaceAttributes[] = $handler; |
|
488 | - else if ($nsattr instanceof PHPTAL_NamespaceAttributeContent) |
|
489 | - $this->contentAttributes[] = $handler; |
|
490 | - else |
|
491 | - throw new PHPTAL_ParserException("Unknown namespace attribute class ".get_class($nsattr), |
|
510 | + if ($nsattr instanceof PHPTAL_NamespaceAttributeSurround) { |
|
511 | + $this->surroundAttributes[] = $handler; |
|
512 | + } else if ($nsattr instanceof PHPTAL_NamespaceAttributeReplace) { |
|
513 | + $this->replaceAttributes[] = $handler; |
|
514 | + } else if ($nsattr instanceof PHPTAL_NamespaceAttributeContent) { |
|
515 | + $this->contentAttributes[] = $handler; |
|
516 | + } else { |
|
517 | + throw new PHPTAL_ParserException("Unknown namespace attribute class ".get_class($nsattr), |
|
492 | 518 | $this->getSourceFile(), $this->getSourceLine()); |
519 | + } |
|
493 | 520 | |
494 | 521 | } |
495 | 522 | } |
@@ -119,7 +119,9 @@ |
||
119 | 119 | */ |
120 | 120 | public function isValidAttributeNS($namespace_uri, $local_name) |
121 | 121 | { |
122 | - if (!$this->isHandledNamespace($namespace_uri)) return false; |
|
122 | + if (!$this->isHandledNamespace($namespace_uri)) { |
|
123 | + return false; |
|
124 | + } |
|
123 | 125 | |
124 | 126 | $attrs = $this->namespaces_by_uri[$namespace_uri]->getAttributes(); |
125 | 127 | return isset($attrs[$local_name]); |
@@ -34,8 +34,12 @@ |
||
34 | 34 | |
35 | 35 | public function prefixToNamespaceURI($prefix) |
36 | 36 | { |
37 | - if ($prefix === 'xmlns') return 'http://www.w3.org/2000/xmlns/'; |
|
38 | - if ($prefix === 'xml') return 'http://www.w3.org/XML/1998/namespace'; |
|
37 | + if ($prefix === 'xmlns') { |
|
38 | + return 'http://www.w3.org/2000/xmlns/'; |
|
39 | + } |
|
40 | + if ($prefix === 'xml') { |
|
41 | + return 'http://www.w3.org/XML/1998/namespace'; |
|
42 | + } |
|
39 | 43 | |
40 | 44 | // domdefs provides fallback for all known phptal ns |
41 | 45 | if (isset($this->prefix_to_uri[$prefix])) { |
@@ -34,10 +34,12 @@ |
||
34 | 34 | $codewriter->pushHTML($codewriter->interpolateCDATA(str_replace('</', '<\/', $value))); |
35 | 35 | } elseif (($mode === PHPTAL::XHTML && $inCDATAelement) // safe for text/html |
36 | 36 | || ($mode === PHPTAL::XML && preg_match('/[<>&]/', $value)) // non-useless in XML |
37 | - || ($mode !== PHPTAL::HTML5 && preg_match('/<\?|\${structure/', $value))) // hacks with structure (in X[HT]ML) may need it |
|
37 | + || ($mode !== PHPTAL::HTML5 && preg_match('/<\?|\${structure/', $value))) { |
|
38 | + // hacks with structure (in X[HT]ML) may need it |
|
38 | 39 | { |
39 | 40 | // in text/html "</" is dangerous and the only sensible way to escape is ECMAScript string escapes. |
40 | 41 | if ($mode === PHPTAL::XHTML) $value = str_replace('</', '<\/', $value); |
42 | + } |
|
41 | 43 | |
42 | 44 | $codewriter->pushHTML($codewriter->interpolateCDATA('<![CDATA['.$value.']]>')); |
43 | 45 | } else { |
@@ -124,7 +124,9 @@ discard block |
||
124 | 124 | for (; $i<$len; $i++) { |
125 | 125 | $c = $src[$i]; // Change to substr($src, $i, 1); if you want to use mb_string.func_overload |
126 | 126 | |
127 | - if ($c === "\n") $builder->setSource($this->_file, ++$this->_line); |
|
127 | + if ($c === "\n") { |
|
128 | + $builder->setSource($this->_file, ++$this->_line); |
|
129 | + } |
|
128 | 130 | |
129 | 131 | switch ($state) { |
130 | 132 | case self::ST_ROOT: |
@@ -174,7 +176,9 @@ discard block |
||
174 | 176 | case self::ST_TAG_NAME: |
175 | 177 | if (self::isWhiteChar($c) || $c === '/' || $c === '>') { |
176 | 178 | $tagname = substr($src, $mark, $i-$mark); |
177 | - if (!$this->isValidQName($tagname)) $this->raiseError("Invalid tag name '$tagname'"); |
|
179 | + if (!$this->isValidQName($tagname)) { |
|
180 | + $this->raiseError("Invalid tag name '$tagname'"); |
|
181 | + } |
|
178 | 182 | |
179 | 183 | if ($c === '/') { |
180 | 184 | $state = self::ST_TAG_SINGLE; |
@@ -220,7 +224,9 @@ discard block |
||
220 | 224 | } elseif ($state === self::ST_TAG_ATTRIBUTES && $this->isValidQName($c)) { |
221 | 225 | $mark = $i; // mark attribute key start |
222 | 226 | $state = self::ST_ATTR_KEY; |
223 | - } else $this->raiseError("Unexpected character '$c' between attributes of < $tagname >"); |
|
227 | + } else { |
|
228 | + $this->raiseError("Unexpected character '$c' between attributes of < $tagname >"); |
|
229 | + } |
|
224 | 230 | break; |
225 | 231 | |
226 | 232 | case self::ST_COMMENT: |
@@ -287,8 +293,11 @@ discard block |
||
287 | 293 | $this->raiseError("Attribute $attribute in < $tagname > is defined more than once"); |
288 | 294 | } |
289 | 295 | |
290 | - if ($c === '=') $state = self::ST_ATTR_VALUE; |
|
291 | - else /* white char */ $state = self::ST_ATTR_EQ; |
|
296 | + if ($c === '=') { |
|
297 | + $state = self::ST_ATTR_VALUE; |
|
298 | + } else { |
|
299 | + /* white char */ $state = self::ST_ATTR_EQ; |
|
300 | + } |
|
292 | 301 | } elseif ($c === '/' || $c==='>') { |
293 | 302 | $attribute = substr($src, $mark, $i-$mark); |
294 | 303 | if (!$this->isValidQName($attribute)) { |
@@ -330,11 +339,15 @@ discard block |
||
330 | 339 | } |
331 | 340 | } |
332 | 341 | |
333 | - if ($state === self::ST_TEXT) // allows text past root node, which is in violation of XML spec |
|
342 | + if ($state === self::ST_TEXT) { |
|
343 | + // allows text past root node, which is in violation of XML spec |
|
334 | 344 | { |
335 | 345 | if ($i > $mark) { |
336 | 346 | $text = substr($src, $mark, $i-$mark); |
337 | - if (!ctype_space($text)) $this->raiseError("Characters found after end of the root element (wrap document in < tal:block > to avoid this error)"); |
|
347 | + } |
|
348 | + if (!ctype_space($text)) { |
|
349 | + $this->raiseError("Characters found after end of the root element (wrap document in < tal:block > to avoid this error)"); |
|
350 | + } |
|
338 | 351 | } |
339 | 352 | } else { |
340 | 353 | if ($state === self::ST_ROOT) { |
@@ -346,8 +359,7 @@ discard block |
||
346 | 359 | } |
347 | 360 | |
348 | 361 | $builder->onDocumentEnd(); |
349 | - } |
|
350 | - catch(PHPTAL_TemplateException $e) |
|
362 | + } catch(PHPTAL_TemplateException $e) |
|
351 | 363 | { |
352 | 364 | $e->hintSrcPosition($this->_file, $this->_line); |
353 | 365 | throw $e; |
@@ -363,7 +375,9 @@ discard block |
||
363 | 375 | |
364 | 376 | private function checkEncoding($str) |
365 | 377 | { |
366 | - if ($str === '') return ''; |
|
378 | + if ($str === '') { |
|
379 | + return ''; |
|
380 | + } |
|
367 | 381 | |
368 | 382 | if ($this->input_encoding === 'UTF-8') { |
369 | 383 | |
@@ -454,7 +468,9 @@ discard block |
||
454 | 468 | private static function convertPHPBlockToTALES($m) |
455 | 469 | { |
456 | 470 | list(, $type, $code) = $m; |
457 | - if ($type === '=') $code = 'echo '.$code; |
|
471 | + if ($type === '=') { |
|
472 | + $code = 'echo '.$code; |
|
473 | + } |
|
458 | 474 | return '${structure phptal-internal-php-block:'.rawurlencode($code).'}'; |
459 | 475 | } |
460 | 476 |
@@ -53,7 +53,9 @@ |
||
53 | 53 | { |
54 | 54 | if (count($this->_stack) > 0) { |
55 | 55 | $left='</'.$this->_current->getQualifiedName().'>'; |
56 | - for ($i = count($this->_stack)-1; $i>0; $i--) $left .= '</'.$this->_stack[$i]->getQualifiedName().'>'; |
|
56 | + for ($i = count($this->_stack)-1; $i>0; $i--) { |
|
57 | + $left .= '</'.$this->_stack[$i]->getQualifiedName().'>'; |
|
58 | + } |
|
57 | 59 | throw new PHPTAL_ParserException("Not all elements were closed before end of the document. Missing: ".$left, |
58 | 60 | $this->file, $this->line); |
59 | 61 | } |
@@ -34,7 +34,9 @@ discard block |
||
34 | 34 | |
35 | 35 | public function __construct() |
36 | 36 | { |
37 | - if (!function_exists('gettext')) throw new PHPTAL_ConfigurationException("Gettext not installed"); |
|
37 | + if (!function_exists('gettext')) { |
|
38 | + throw new PHPTAL_ConfigurationException("Gettext not installed"); |
|
39 | + } |
|
38 | 40 | $this->useDomain("messages"); // PHP bug #21965 |
39 | 41 | } |
40 | 42 | |
@@ -75,11 +77,15 @@ discard block |
||
75 | 77 | $langs = func_get_args(); |
76 | 78 | |
77 | 79 | $langCode = $this->trySettingLanguages(LC_ALL, $langs); |
78 | - if ($langCode) return $langCode; |
|
80 | + if ($langCode) { |
|
81 | + return $langCode; |
|
82 | + } |
|
79 | 83 | |
80 | 84 | if (defined("LC_MESSAGES")) { |
81 | 85 | $langCode = $this->trySettingLanguages(LC_MESSAGES, $langs); |
82 | - if ($langCode) return $langCode; |
|
86 | + if ($langCode) { |
|
87 | + return $langCode; |
|
88 | + } |
|
83 | 89 | } |
84 | 90 | |
85 | 91 | throw new PHPTAL_ConfigurationException('Language(s) code(s) "'.implode(', ', $langs).'" not supported by your system'); |
@@ -142,7 +148,9 @@ discard block |
||
142 | 148 | */ |
143 | 149 | public function translate($key, $htmlencode=true) |
144 | 150 | { |
145 | - if ($this->_canonicalize) $key = self::_canonicalizeKey($key); |
|
151 | + if ($this->_canonicalize) { |
|
152 | + $key = self::_canonicalizeKey($key); |
|
153 | + } |
|
146 | 154 | |
147 | 155 | $value = gettext($key); |
148 | 156 |
@@ -94,8 +94,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -116,8 +116,7 @@ discard block |
||
116 | 116 | } else { |
117 | 117 | throw new PHPTAL_ConfigurationException("Executed macro in file with DOCTYPE when using echoExecute(). This is not supported yet. Remove DOCTYPE or use PHPTAL->execute()."); |
118 | 118 | } |
119 | - } |
|
120 | - else if (!$this->_docType) { |
|
119 | + } else if (!$this->_docType) { |
|
121 | 120 | $this->_docType = $doctype; |
122 | 121 | } |
123 | 122 | } |
@@ -317,7 +316,9 @@ discard block |
||
317 | 316 | { |
318 | 317 | if ($current !== $path) { |
319 | 318 | $pathinfo = " (in path '.../$path')"; |
320 | - } else $pathinfo = ''; |
|
319 | + } else { |
|
320 | + $pathinfo = ''; |
|
321 | + } |
|
321 | 322 | |
322 | 323 | if (!empty($basename)) { |
323 | 324 | $basename = "'" . $basename . "' "; |
@@ -353,7 +354,9 @@ discard block |
||
353 | 354 | public static function path($base, $path, $nothrow=false) |
354 | 355 | { |
355 | 356 | if ($base === null) { |
356 | - if ($nothrow) return null; |
|
357 | + if ($nothrow) { |
|
358 | + return null; |
|
359 | + } |
|
357 | 360 | PHPTAL_Context::pathError($base, $path, $path, $path); |
358 | 361 | } |
359 | 362 | |
@@ -412,8 +415,7 @@ discard block |
||
412 | 415 | { |
413 | 416 | $base = $base->__call($current, array()); |
414 | 417 | continue; |
415 | - } |
|
416 | - catch(BadMethodCallException $e) {} |
|
418 | + } catch(BadMethodCallException $e) {} |
|
417 | 419 | } |
418 | 420 | |
419 | 421 | if ($nothrow) { |
@@ -437,8 +439,9 @@ discard block |
||
437 | 439 | continue; |
438 | 440 | } |
439 | 441 | |
440 | - if ($nothrow) |
|
441 | - return null; |
|
442 | + if ($nothrow) { |
|
443 | + return null; |
|
444 | + } |
|
442 | 445 | |
443 | 446 | PHPTAL_Context::pathError($base, $path, $current, $prev); |
444 | 447 | } |
@@ -460,8 +463,9 @@ discard block |
||
460 | 463 | |
461 | 464 | // if this point is reached, then the part cannot be resolved |
462 | 465 | |
463 | - if ($nothrow) |
|
464 | - return null; |
|
466 | + if ($nothrow) { |
|
467 | + return null; |
|
468 | + } |
|
465 | 469 | |
466 | 470 | PHPTAL_Context::pathError($base, $path, $current, $prev); |
467 | 471 | } |