@@ -1,14 +1,14 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Transphporm; |
3 | 3 | class Exception extends \Exception { |
4 | - const PROPERTY = 'property'; |
|
5 | - const TSS_FUNCTION = 'function'; |
|
6 | - const PSEUDO = 'pseudo'; |
|
7 | - const FORMATTER = 'formatter'; |
|
4 | + const PROPERTY = 'property'; |
|
5 | + const TSS_FUNCTION = 'function'; |
|
6 | + const PSEUDO = 'pseudo'; |
|
7 | + const FORMATTER = 'formatter'; |
|
8 | 8 | |
9 | - public function __construct(RunException $runException, $file, $line) { |
|
10 | - $message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file); |
|
9 | + public function __construct(RunException $runException, $file, $line) { |
|
10 | + $message = $runException->getMessage() . ' on Line ' . $line . ' of ' . ($file === null ? 'tss' : $file); |
|
11 | 11 | |
12 | - parent::__construct($message, 0, $runException->getPrevious()); |
|
13 | - } |
|
12 | + parent::__construct($message, 0, $runException->getPrevious()); |
|
13 | + } |
|
14 | 14 | } |
@@ -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 | } |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace Transphporm; |
3 | 3 | class TSSCache { |
4 | - private $cache; |
|
5 | - private $prefix; |
|
4 | + private $cache; |
|
5 | + private $prefix; |
|
6 | 6 | |
7 | - public function __construct(Cache $cache, $prefix) { |
|
8 | - $this->cache = $cache; |
|
9 | - $this->prefix = $prefix; |
|
10 | - } |
|
7 | + public function __construct(Cache $cache, $prefix) { |
|
8 | + $this->cache = $cache; |
|
9 | + $this->prefix = $prefix; |
|
10 | + } |
|
11 | 11 | |
12 | 12 | private function getRulesFromCache($file) { |
13 | 13 | //The cache for the key: the filename and template prefix |
@@ -28,12 +28,12 @@ discard block |
||
28 | 28 | return $file . $this->prefix . dirname(realpath($file)) . DIRECTORY_SEPARATOR; |
29 | 29 | } |
30 | 30 | |
31 | - public function load($tss) { |
|
32 | - return $this->getRulesFromCache($tss); |
|
33 | - } |
|
31 | + public function load($tss) { |
|
32 | + return $this->getRulesFromCache($tss); |
|
33 | + } |
|
34 | 34 | |
35 | - public function write($file, $rules, $imports = []) { |
|
36 | - if (is_file($file)) $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]); |
|
37 | - return $rules; |
|
38 | - } |
|
35 | + public function write($file, $rules, $imports = []) { |
|
36 | + if (is_file($file)) $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]); |
|
37 | + return $rules; |
|
38 | + } |
|
39 | 39 | } |
@@ -25,7 +25,7 @@ |
||
25 | 25 | } |
26 | 26 | |
27 | 27 | private function getCacheKey($file) { |
28 | - return $file . $this->prefix . dirname(realpath($file)) . DIRECTORY_SEPARATOR; |
|
28 | + return $file.$this->prefix.dirname(realpath($file)).DIRECTORY_SEPARATOR; |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | public function load($tss) { |
@@ -18,7 +18,9 @@ discard block |
||
18 | 18 | $rules = $this->cache->load($key, filemtime($file)); |
19 | 19 | if ($rules) { |
20 | 20 | foreach ($rules['import'] as $file) { |
21 | - if (!$this->cache->load($this->getCacheKey($file), filemtime($file))) return false; |
|
21 | + if (!$this->cache->load($this->getCacheKey($file), filemtime($file))) { |
|
22 | + return false; |
|
23 | + } |
|
22 | 24 | } |
23 | 25 | } |
24 | 26 | return $rules; |
@@ -33,7 +35,9 @@ discard block |
||
33 | 35 | } |
34 | 36 | |
35 | 37 | public function write($file, $rules, $imports = []) { |
36 | - if (is_file($file)) $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]); |
|
38 | + if (is_file($file)) { |
|
39 | + $this->cache->write($this->getCacheKey($file), ['rules' => $rules, 'import' => $imports]); |
|
40 | + } |
|
37 | 41 | return $rules; |
38 | 42 | } |
39 | 43 | } |
@@ -12,13 +12,13 @@ |
||
12 | 12 | |
13 | 13 | if ($this->isJsonFile($json)) { |
14 | 14 | $path = $this->filePath->getFilePath($json); |
15 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
15 | + if (!file_exists($path)) throw new \Exception('File does not exist at: '.$path); |
|
16 | 16 | $json = file_get_contents($path); |
17 | 17 | } |
18 | 18 | |
19 | 19 | $map = json_decode($json, true); |
20 | 20 | |
21 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
21 | + if (!is_array($map)) throw new \Exception('Could not decode json: '.json_last_error_msg()); |
|
22 | 22 | |
23 | 23 | return $map; |
24 | 24 | } |
@@ -1,29 +1,29 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Transphporm\TSSFunction; |
3 | 3 | class Json implements \Transphporm\TSSFunction { |
4 | - private $filePath; |
|
4 | + private $filePath; |
|
5 | 5 | |
6 | - public function __construct(\Transphporm\FilePath $filePath) { |
|
7 | - $this->filePath = $filePath; |
|
8 | - } |
|
6 | + public function __construct(\Transphporm\FilePath $filePath) { |
|
7 | + $this->filePath = $filePath; |
|
8 | + } |
|
9 | 9 | |
10 | - public function run(array $args, \DomElement $element = null) { |
|
11 | - $json = $args[0]; |
|
10 | + public function run(array $args, \DomElement $element = null) { |
|
11 | + $json = $args[0]; |
|
12 | 12 | |
13 | - if ($this->isJsonFile($json)) { |
|
14 | - $path = $this->filePath->getFilePath($json); |
|
15 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
16 | - $json = file_get_contents($path); |
|
17 | - } |
|
13 | + if ($this->isJsonFile($json)) { |
|
14 | + $path = $this->filePath->getFilePath($json); |
|
15 | + if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
16 | + $json = file_get_contents($path); |
|
17 | + } |
|
18 | 18 | |
19 | - $map = json_decode($json, true); |
|
19 | + $map = json_decode($json, true); |
|
20 | 20 | |
21 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
21 | + if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
22 | 22 | |
23 | - return $map; |
|
24 | - } |
|
23 | + return $map; |
|
24 | + } |
|
25 | 25 | |
26 | - private function isJsonFile($json) { |
|
27 | - return trim($json)[0] != '{' && trim($json)[0] != '['; |
|
28 | - } |
|
26 | + private function isJsonFile($json) { |
|
27 | + return trim($json)[0] != '{' && trim($json)[0] != '['; |
|
28 | + } |
|
29 | 29 | } |
@@ -12,13 +12,17 @@ |
||
12 | 12 | |
13 | 13 | if ($this->isJsonFile($json)) { |
14 | 14 | $path = $this->filePath->getFilePath($json); |
15 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
15 | + if (!file_exists($path)) { |
|
16 | + throw new \Exception('File does not exist at: ' . $path); |
|
17 | + } |
|
16 | 18 | $json = file_get_contents($path); |
17 | 19 | } |
18 | 20 | |
19 | 21 | $map = json_decode($json, true); |
20 | 22 | |
21 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
23 | + if (!is_array($map)) { |
|
24 | + throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
25 | + } |
|
22 | 26 | |
23 | 27 | return $map; |
24 | 28 | } |
@@ -31,10 +31,11 @@ |
||
31 | 31 | ]; |
32 | 32 | |
33 | 33 | if ($funcs[$this->mode] === 'concat' && is_numeric($newValue) |
34 | - && is_numeric($this->result[count($this->result)-1])) |
|
35 | - $this->add($newValue); |
|
36 | - else |
|
37 | - $this->{$funcs[$this->mode]}($newValue); |
|
34 | + && is_numeric($this->result[count($this->result)-1])) { |
|
35 | + $this->add($newValue); |
|
36 | + } else { |
|
37 | + $this->{$funcs[$this->mode]}($newValue); |
|
38 | + } |
|
38 | 39 | } |
39 | 40 | |
40 | 41 | public function arg($value) { |
@@ -7,6 +7,9 @@ |
||
7 | 7 | $this->templateFunction = $templateFunction; |
8 | 8 | } |
9 | 9 | |
10 | + /** |
|
11 | + * @param string $val |
|
12 | + */ |
|
10 | 13 | public function html($val) { |
11 | 14 | return $this->templateFunction->run(['<template>' . $val . '</template>']); |
12 | 15 | } |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Transphporm\Formatter; |
3 | 3 | class HTMLFormatter { |
4 | - private $templateFunction; |
|
4 | + private $templateFunction; |
|
5 | 5 | |
6 | - public function __construct(\Transphporm\TSSFunction\Template $templateFunction) { |
|
7 | - $this->templateFunction = $templateFunction; |
|
8 | - } |
|
6 | + public function __construct(\Transphporm\TSSFunction\Template $templateFunction) { |
|
7 | + $this->templateFunction = $templateFunction; |
|
8 | + } |
|
9 | 9 | |
10 | - public function html($val) { |
|
10 | + public function html($val) { |
|
11 | 11 | return $this->templateFunction->run(['<template>' . $val . '</template>']); |
12 | 12 | } |
13 | 13 |
@@ -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 | } |
@@ -15,8 +15,8 @@ |
||
15 | 15 | |
16 | 16 | private function getLocale() { |
17 | 17 | if (is_array($this->locale)) return $this->locale; |
18 | - else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
19 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
18 | + else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'../Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.$this->locale.'.json'), true); |
|
19 | + else return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'../Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.'enGB.json'), true); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | public function load(\Transphporm\Config $config) { |
@@ -14,9 +14,13 @@ |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | private function getLocale() { |
17 | - if (is_array($this->locale)) return $this->locale; |
|
18 | - else if (strlen($this->locale) > 0) return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
19 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
17 | + if (is_array($this->locale)) { |
|
18 | + return $this->locale; |
|
19 | + } else if (strlen($this->locale) > 0) { |
|
20 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
21 | + } else { |
|
22 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
23 | + } |
|
20 | 24 | } |
21 | 25 | |
22 | 26 | public function load(\Transphporm\Config $config) { |
@@ -7,7 +7,9 @@ |
||
7 | 7 | namespace Transphporm\Pseudo; |
8 | 8 | class Attribute implements \Transphporm\Pseudo { |
9 | 9 | public function match($name, $args, \DomElement $element) { |
10 | - if (!($name === null || in_array($name, ['data', 'iteration', 'root']))) return true; |
|
10 | + if (!($name === null || in_array($name, ['data', 'iteration', 'root']))) { |
|
11 | + return true; |
|
12 | + } |
|
11 | 13 | return $args[0]; |
12 | 14 | } |
13 | 15 | } |
@@ -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) { |