@@ -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 | } |
@@ -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 | } |
@@ -6,29 +6,29 @@ |
||
6 | 6 | * @version 1.2 */ |
7 | 7 | namespace Transphporm\TSSFunction; |
8 | 8 | class Json implements \Transphporm\TSSFunction { |
9 | - private $filePath; |
|
9 | + private $filePath; |
|
10 | 10 | |
11 | - public function __construct(\Transphporm\FilePath $filePath) { |
|
12 | - $this->filePath = $filePath; |
|
13 | - } |
|
11 | + public function __construct(\Transphporm\FilePath $filePath) { |
|
12 | + $this->filePath = $filePath; |
|
13 | + } |
|
14 | 14 | |
15 | - public function run(array $args, \DomElement $element = null) { |
|
16 | - $json = $args[0]; |
|
15 | + public function run(array $args, \DomElement $element = null) { |
|
16 | + $json = $args[0]; |
|
17 | 17 | |
18 | - if ($this->isJsonFile($json)) { |
|
19 | - $path = $this->filePath->getFilePath($json); |
|
20 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
21 | - $json = file_get_contents($path); |
|
22 | - } |
|
18 | + if ($this->isJsonFile($json)) { |
|
19 | + $path = $this->filePath->getFilePath($json); |
|
20 | + if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
21 | + $json = file_get_contents($path); |
|
22 | + } |
|
23 | 23 | |
24 | - $map = json_decode($json, true); |
|
24 | + $map = json_decode($json, true); |
|
25 | 25 | |
26 | - if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
26 | + if (!is_array($map)) throw new \Exception('Could not decode json: ' . json_last_error_msg()); |
|
27 | 27 | |
28 | - return $map; |
|
29 | - } |
|
28 | + return $map; |
|
29 | + } |
|
30 | 30 | |
31 | - private function isJsonFile($json) { |
|
32 | - return trim($json)[0] != '{' && trim($json)[0] != '['; |
|
33 | - } |
|
31 | + private function isJsonFile($json) { |
|
32 | + return trim($json)[0] != '{' && trim($json)[0] != '['; |
|
33 | + } |
|
34 | 34 | } |
@@ -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 | } |
@@ -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 |
@@ -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) { |
@@ -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 | } |