@@ -7,8 +7,12 @@ |
||
| 7 | 7 | namespace Transphporm\Property; |
| 8 | 8 | class Display implements \Transphporm\Property { |
| 9 | 9 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
| 10 | - if ($pseudoMatcher->hasFunction('attr')) $element->removeAttribute($pseudoMatcher->getFuncArgs('attr')[0]); |
|
| 11 | - else if (strtolower($values[0]) === 'none') $element->setAttribute('transphporm', 'remove'); |
|
| 12 | - else $element->setAttribute('transphporm', 'show'); |
|
| 10 | + if ($pseudoMatcher->hasFunction('attr')) { |
|
| 11 | + $element->removeAttribute($pseudoMatcher->getFuncArgs('attr')[0]); |
|
| 12 | + } else if (strtolower($values[0]) === 'none') { |
|
| 13 | + $element->setAttribute('transphporm', 'remove'); |
|
| 14 | + } else { |
|
| 15 | + $element->setAttribute('transphporm', 'show'); |
|
| 16 | + } |
|
| 13 | 17 | } |
| 14 | 18 | } |
@@ -7,7 +7,7 @@ |
||
| 7 | 7 | const FORMATTER = 'formatter'; |
| 8 | 8 | |
| 9 | 9 | public function __construct(RunException $runException, $file, $line) { |
| 10 | - $message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file); |
|
| 10 | + $message = $runException->getMessage().' on Line '.$line.' of '.($file === null ? 'tss' : $file); |
|
| 11 | 11 | |
| 12 | 12 | parent::__construct($message, 0, $runException->getPrevious()); |
| 13 | 13 | } |
@@ -6,14 +6,14 @@ |
||
| 6 | 6 | * @version 1.2 */ |
| 7 | 7 | namespace Transphporm; |
| 8 | 8 | class Exception extends \Exception { |
| 9 | - const PROPERTY = 'property'; |
|
| 10 | - const TSS_FUNCTION = 'function'; |
|
| 11 | - const PSEUDO = 'pseudo'; |
|
| 12 | - const FORMATTER = 'formatter'; |
|
| 9 | + const PROPERTY = 'property'; |
|
| 10 | + const TSS_FUNCTION = 'function'; |
|
| 11 | + const PSEUDO = 'pseudo'; |
|
| 12 | + const FORMATTER = 'formatter'; |
|
| 13 | 13 | |
| 14 | - public function __construct(RunException $runException, $file, $line) { |
|
| 15 | - $message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file); |
|
| 14 | + public function __construct(RunException $runException, $file, $line) { |
|
| 15 | + $message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file); |
|
| 16 | 16 | |
| 17 | - parent::__construct($message, 0, $runException->getPrevious()); |
|
| 18 | - } |
|
| 17 | + parent::__construct($message, 0, $runException->getPrevious()); |
|
| 18 | + } |
|
| 19 | 19 | } |
@@ -8,12 +8,12 @@ |
||
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | public function html($val) { |
| 11 | - return $this->templateFunction->run(['<template>' . $val . '</template>']); |
|
| 11 | + return $this->templateFunction->run(['<template>'.$val.'</template>']); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | public function debug($val) { |
| 15 | 15 | ob_start(); |
| 16 | 16 | var_dump($val); |
| 17 | - return $this->html('<pre>' . ob_get_clean() . '</pre>'); |
|
| 17 | + return $this->html('<pre>'.ob_get_clean().'</pre>'); |
|
| 18 | 18 | } |
| 19 | 19 | } |
@@ -6,13 +6,13 @@ |
||
| 6 | 6 | * @version 1.2 */ |
| 7 | 7 | namespace Transphporm\Formatter; |
| 8 | 8 | class HTMLFormatter { |
| 9 | - private $templateFunction; |
|
| 9 | + private $templateFunction; |
|
| 10 | 10 | |
| 11 | - public function __construct(\Transphporm\TSSFunction\Template $templateFunction) { |
|
| 12 | - $this->templateFunction = $templateFunction; |
|
| 13 | - } |
|
| 11 | + public function __construct(\Transphporm\TSSFunction\Template $templateFunction) { |
|
| 12 | + $this->templateFunction = $templateFunction; |
|
| 13 | + } |
|
| 14 | 14 | |
| 15 | - public function html($val) { |
|
| 15 | + public function html($val) { |
|
| 16 | 16 | return $this->templateFunction->run(['<template>' . $val . '</template>']); |
| 17 | 17 | } |
| 18 | 18 | |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | private $pseudo; |
| 11 | 11 | private $depth; |
| 12 | 12 | private $index; |
| 13 | - private $file; |
|
| 13 | + private $file; |
|
| 14 | 14 | private $line; |
| 15 | 15 | private $properties = []; |
| 16 | 16 | private $lastRun = 0; |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | $this->pseudo = $pseudo; |
| 27 | 27 | $this->depth = $depth; |
| 28 | 28 | $this->index = $index; |
| 29 | - $this->file = $file; |
|
| 29 | + $this->file = $file; |
|
| 30 | 30 | $this->line = $line; |
| 31 | 31 | $this->properties = $properties; |
| 32 | 32 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | $offset = $this->getUpdateFrequency($frequency); |
| 50 | 50 | |
| 51 | - if ($time > $this->lastRun + $offset) return true; |
|
| 51 | + if ($time > $this->lastRun+$offset) return true; |
|
| 52 | 52 | else return false; |
| 53 | 53 | } |
| 54 | 54 | |
@@ -75,8 +75,8 @@ discard block |
||
| 75 | 75 | $num = (int) $frequency; |
| 76 | 76 | $unit = strtoupper(trim(str_replace($num, '', $frequency))); |
| 77 | 77 | if ($frequency == 'always') return 0; |
| 78 | - else if ($frequency == 'never') return self::D*3650; //Not quite never, in 10 years will cause issues on 32 bit PHP builds re 2038 problem |
|
| 78 | + else if ($frequency == 'never') return self::D * 3650; //Not quite never, in 10 years will cause issues on 32 bit PHP builds re 2038 problem |
|
| 79 | 79 | |
| 80 | - return $num * constant(self::class . '::' . $unit); |
|
| 80 | + return $num * constant(self::class.'::'.$unit); |
|
| 81 | 81 | } |
| 82 | 82 | } |
@@ -44,22 +44,31 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | private function timeFrequency($frequency, $time = null) { |
| 47 | - if ($time === null) $time = time(); |
|
| 47 | + if ($time === null) { |
|
| 48 | + $time = time(); |
|
| 49 | + } |
|
| 48 | 50 | |
| 49 | 51 | $offset = $this->getUpdateFrequency($frequency); |
| 50 | 52 | |
| 51 | - if ($time > $this->lastRun + $offset) return true; |
|
| 52 | - else return false; |
|
| 53 | + if ($time > $this->lastRun + $offset) { |
|
| 54 | + return true; |
|
| 55 | + } else { |
|
| 56 | + return false; |
|
| 57 | + } |
|
| 53 | 58 | } |
| 54 | 59 | |
| 55 | 60 | public function shouldRun($time = null) { |
| 56 | 61 | if (isset($this->properties['update-frequency']) && $this->lastRun !== 0) { |
| 57 | 62 | $frequency = $this->properties['update-frequency']->read(); |
| 58 | 63 | $static = ['always' => true, 'never' => false]; |
| 59 | - if (isset($static[$frequency])) return $static[$frequency]; |
|
| 60 | - else return $this->timeFrequency($frequency, $time); |
|
| 64 | + if (isset($static[$frequency])) { |
|
| 65 | + return $static[$frequency]; |
|
| 66 | + } else { |
|
| 67 | + return $this->timeFrequency($frequency, $time); |
|
| 68 | + } |
|
| 69 | + } else { |
|
| 70 | + return true; |
|
| 61 | 71 | } |
| 62 | - else return true; |
|
| 63 | 72 | } |
| 64 | 73 | |
| 65 | 74 | public function getUpdateFrequency($frequency = null) { |
@@ -67,15 +76,22 @@ discard block |
||
| 67 | 76 | $frequency = isset($this->properties['update-frequency']) ? $this->properties['update-frequency']->read() : false; |
| 68 | 77 | } |
| 69 | 78 | |
| 70 | - if (empty($frequency)) return 0; |
|
| 71 | - else return $this->calcUpdateFrequency($frequency); |
|
| 79 | + if (empty($frequency)) { |
|
| 80 | + return 0; |
|
| 81 | + } else { |
|
| 82 | + return $this->calcUpdateFrequency($frequency); |
|
| 83 | + } |
|
| 72 | 84 | } |
| 73 | 85 | |
| 74 | 86 | private function calcUpdateFrequency($frequency) { |
| 75 | 87 | $num = (int) $frequency; |
| 76 | 88 | $unit = strtoupper(trim(str_replace($num, '', $frequency))); |
| 77 | - if ($frequency == 'always') return 0; |
|
| 78 | - else if ($frequency == 'never') return self::D*3650; //Not quite never, in 10 years will cause issues on 32 bit PHP builds re 2038 problem |
|
| 89 | + if ($frequency == 'always') { |
|
| 90 | + return 0; |
|
| 91 | + } else if ($frequency == 'never') { |
|
| 92 | + return self::D*3650; |
|
| 93 | + } |
|
| 94 | + //Not quite never, in 10 years will cause issues on 32 bit PHP builds re 2038 problem |
|
| 79 | 95 | |
| 80 | 96 | return $num * constant(self::class . '::' . $unit); |
| 81 | 97 | } |
@@ -21,7 +21,8 @@ |
||
| 21 | 21 | $key = md5($key); |
| 22 | 22 | if (isset($this->cache[$key]) && $this->cache[$key]['timestamp'] >= $modified) { |
| 23 | 23 | return $this->cache[$key]['content']; |
| 24 | + } else { |
|
| 25 | + return false; |
|
| 24 | 26 | } |
| 25 | - else return false; |
|
| 26 | 27 | } |
| 27 | 28 | } |
| 28 | 29 | \ No newline at end of file |
@@ -14,7 +14,9 @@ discard block |
||
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function format($value, $rules) { |
| 17 | - if (!isset($rules['format'])) return $value; |
|
| 17 | + if (!isset($rules['format'])) { |
|
| 18 | + return $value; |
|
| 19 | + } |
|
| 18 | 20 | $tokens = $rules['format']; |
| 19 | 21 | |
| 20 | 22 | $functionName = $tokens->from(\Transphporm\Parser\Tokenizer::NAME, true)->read(); |
@@ -27,15 +29,16 @@ discard block |
||
| 27 | 29 | |
| 28 | 30 | try { |
| 29 | 31 | return $this->processFormat($options, $functionName, $value); |
| 30 | - } |
|
| 31 | - catch (\Exception $e) { |
|
| 32 | + } catch (\Exception $e) { |
|
| 32 | 33 | throw new \Transphporm\RunException(\Transphporm\Exception::FORMATTER, $functionName, $e); |
| 33 | 34 | } |
| 34 | 35 | } |
| 35 | 36 | |
| 36 | 37 | //TODO: Abstract all error reporting externally with a method for turning it on/off |
| 37 | 38 | private function assert($condition, $error) { |
| 38 | - if (!$condition) throw new \Exception($error); |
|
| 39 | + if (!$condition) { |
|
| 40 | + throw new \Exception($error); |
|
| 41 | + } |
|
| 39 | 42 | } |
| 40 | 43 | |
| 41 | 44 | private function processFormat($format, $functionName, $value) { |
@@ -11,25 +11,33 @@ |
||
| 11 | 11 | private $lastParentNode; |
| 12 | 12 | |
| 13 | 13 | public function match($name, $args, \DomElement $element) { |
| 14 | - if ($element->parentNode !== $this->lastParentNode) $this->count = 0; |
|
| 14 | + if ($element->parentNode !== $this->lastParentNode) { |
|
| 15 | + $this->count = 0; |
|
| 16 | + } |
|
| 15 | 17 | |
| 16 | 18 | $this->lastParentNode = $element->parentNode; |
| 17 | 19 | |
| 18 | 20 | |
| 19 | 21 | |
| 20 | - if ($name !== 'nth-child') return true; |
|
| 22 | + if ($name !== 'nth-child') { |
|
| 23 | + return true; |
|
| 24 | + } |
|
| 21 | 25 | |
| 22 | 26 | $this->count++; |
| 23 | 27 | $criteria = $args[0]; |
| 24 | 28 | |
| 25 | - if (is_callable([$this, $criteria])) return $this->$criteria($this->count); |
|
| 29 | + if (is_callable([$this, $criteria])) { |
|
| 30 | + return $this->$criteria($this->count); |
|
| 31 | + } |
|
| 26 | 32 | $this->assert(is_numeric($criteria), "Argument passed to 'nth-child' must be 'odd', 'even', or of type int"); |
| 27 | 33 | return $this->count == $criteria; |
| 28 | 34 | } |
| 29 | 35 | |
| 30 | 36 | //TODO: Abstract assertions throughout |
| 31 | 37 | private function assert($condition, $error) { |
| 32 | - if (!$condition) throw new \Exception($error); |
|
| 38 | + if (!$condition) { |
|
| 39 | + throw new \Exception($error); |
|
| 40 | + } |
|
| 33 | 41 | } |
| 34 | 42 | |
| 35 | 43 | private function odd($num) { |
@@ -40,7 +40,7 @@ |
||
| 40 | 40 | private function getTemplateContent($newNode, $tss) { |
| 41 | 41 | $result = []; |
| 42 | 42 | foreach ($newNode->childNodes as $node) { |
| 43 | - if (isset($node->tagName) && $node->tagName === 'template') $result[] = $this->getTemplateContent($node, $tss); |
|
| 43 | + if (isset($node->tagName) && $node->tagName === 'template') $result[] = $this->getTemplateContent($node, $tss); |
|
| 44 | 44 | else $result[] = $this->getClonedElement($node, $tss); |
| 45 | 45 | } |
| 46 | 46 | return $result; |
@@ -25,13 +25,18 @@ discard block |
||
| 25 | 25 | $selector = $this->readArray($args, 1); |
| 26 | 26 | $tss = $this->readArray($args, 2); |
| 27 | 27 | |
| 28 | - if (trim($args[0])[0] === '<') $xml = $args[0]; |
|
| 29 | - else $xml = $this->filePath->getFilePath($args[0]); |
|
| 28 | + if (trim($args[0])[0] === '<') { |
|
| 29 | + $xml = $args[0]; |
|
| 30 | + } else { |
|
| 31 | + $xml = $this->filePath->getFilePath($args[0]); |
|
| 32 | + } |
|
| 30 | 33 | |
| 31 | 34 | $newTemplate = new \Transphporm\Builder($xml, $tss ? $this->filePath->getFilePath($tss) : null); |
| 32 | 35 | |
| 33 | 36 | $doc = $newTemplate->output($this->elementData->getData($element), true)->body; |
| 34 | - if ($selector != '') return $this->templateSubsection($doc, $selector); |
|
| 37 | + if ($selector != '') { |
|
| 38 | + return $this->templateSubsection($doc, $selector); |
|
| 39 | + } |
|
| 35 | 40 | |
| 36 | 41 | return $this->getTemplateContent($doc->documentElement, $tss); |
| 37 | 42 | } |
@@ -39,8 +44,11 @@ discard block |
||
| 39 | 44 | private function getTemplateContent($newNode, $tss) { |
| 40 | 45 | $result = []; |
| 41 | 46 | foreach ($newNode->childNodes as $node) { |
| 42 | - if (isset($node->tagName) && $node->tagName === 'template') $result[] = $this->getTemplateContent($node, $tss); |
|
| 43 | - else $result[] = $this->getClonedElement($node, $tss); |
|
| 47 | + if (isset($node->tagName) && $node->tagName === 'template') { |
|
| 48 | + $result[] = $this->getTemplateContent($node, $tss); |
|
| 49 | + } else { |
|
| 50 | + $result[] = $this->getClonedElement($node, $tss); |
|
| 51 | + } |
|
| 44 | 52 | } |
| 45 | 53 | return $result; |
| 46 | 54 | } |
@@ -59,7 +67,9 @@ discard block |
||
| 59 | 67 | |
| 60 | 68 | private function getClonedElement($node, $tss) { |
| 61 | 69 | $clone = $node->cloneNode(true); |
| 62 | - if ($tss != null && $clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate'); |
|
| 70 | + if ($tss != null && $clone instanceof \DomElement) { |
|
| 71 | + $clone->setAttribute('transphporm', 'includedtemplate'); |
|
| 72 | + } |
|
| 63 | 73 | return $clone; |
| 64 | 74 | } |
| 65 | 75 | } |
@@ -18,8 +18,11 @@ |
||
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public function run(array $args, \DomElement $element = null) { |
| 21 | - if ($this->dataKey === "root") $data = $this->data->getData(null, 'data'); |
|
| 22 | - else $data = $this->data->getData($element, $this->dataKey); |
|
| 21 | + if ($this->dataKey === "root") { |
|
| 22 | + $data = $this->data->getData(null, 'data'); |
|
| 23 | + } else { |
|
| 24 | + $data = $this->data->getData($element, $this->dataKey); |
|
| 25 | + } |
|
| 23 | 26 | $parser = new \Transphporm\Parser\Value($this->functionSet, true, true); |
| 24 | 27 | $return = $parser->parseTokens(new \Transphporm\Parser\Tokens($args), $data); |
| 25 | 28 | return $return[0]; |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | * @version 1.2 */ |
| 7 | 7 | namespace Transphporm\TSSFunction; |
| 8 | 8 | /* Handles data() and iteration() function calls from the stylesheet */ |
| 9 | -class Data implements \Transphporm\TSSFunction{ |
|
| 9 | +class Data implements \Transphporm\TSSFunction { |
|
| 10 | 10 | private $data; |
| 11 | 11 | private $dataKey; |
| 12 | 12 | private $functionSet; |