@@ -69,7 +69,9 @@ discard block |
||
69 | 69 | $selector->type = $token['type']; |
70 | 70 | $selectors[] = $selector; |
71 | 71 | } |
72 | - if (isset($token['value'])) $selectors[count($selectors)-1]->string = $token['value']; |
|
72 | + if (isset($token['value'])) { |
|
73 | + $selectors[count($selectors)-1]->string = $token['value']; |
|
74 | + } |
|
73 | 75 | } |
74 | 76 | return $selectors; |
75 | 77 | } |
@@ -79,7 +81,9 @@ discard block |
||
79 | 81 | $selectors = $this->split($css); |
80 | 82 | $xpath = '/'; |
81 | 83 | foreach ($selectors as $selector) { |
82 | - if (isset($this->translators[$selector->type])) $xpath .= $this->translators[$selector->type]($selector->string, $xpath); |
|
84 | + if (isset($this->translators[$selector->type])) { |
|
85 | + $xpath .= $this->translators[$selector->type]($selector->string, $xpath); |
|
86 | + } |
|
83 | 87 | } |
84 | 88 | |
85 | 89 | $xpath = str_replace('/[', '/*[', $xpath); |
@@ -90,7 +94,9 @@ discard block |
||
90 | 94 | private function removeSpacesFromDirectDecend($css) { |
91 | 95 | $tokens = []; |
92 | 96 | foreach ($css->splitOnToken(Tokenizer::GREATER_THAN) as $token) { |
93 | - foreach ($token->trim() as $t) $tokens[] = $t; |
|
97 | + foreach ($token->trim() as $t) { |
|
98 | + $tokens[] = $t; |
|
99 | + } |
|
94 | 100 | $tokens[] = ['type' => Tokenizer::GREATER_THAN]; |
95 | 101 | } |
96 | 102 | return new Tokens(array_slice($tokens, 0, -1)); |
@@ -43,11 +43,11 @@ |
||
43 | 43 | $functionSet->setElement($element[0]); |
44 | 44 | |
45 | 45 | $attributes = array(); |
46 | - foreach($element[0]->attributes as $attribute_name => $attribute_node) { |
|
47 | - $attributes[$attribute_name] = $attribute_node->nodeValue; |
|
48 | - } |
|
46 | + foreach($element[0]->attributes as $attribute_name => $attribute_node) { |
|
47 | + $attributes[$attribute_name] = $attribute_node->nodeValue; |
|
48 | + } |
|
49 | 49 | |
50 | - $parser = new \Transphporm\Parser\Value($functionSet, true); |
|
50 | + $parser = new \Transphporm\Parser\Value($functionSet, true); |
|
51 | 51 | $return = $parser->parseTokens($attr, $attributes); |
52 | 52 | |
53 | 53 | return $return[0] === '' ? false : $return[0]; |
@@ -19,12 +19,12 @@ discard block |
||
19 | 19 | $this->functionSet = $functionSet; |
20 | 20 | |
21 | 21 | $this->translators = [ |
22 | - Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//' . $prefix . $string; }, |
|
23 | - '' => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
24 | - Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
25 | - Tokenizer::NUM_SIGN => function($string) { return '[@id=\'' . $string . '\']'; }, |
|
26 | - Tokenizer::DOT => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' ' . $string . ' \')]'; }, |
|
27 | - Tokenizer::OPEN_SQUARE_BRACKET => function($string) use ($hash) { return '[' .'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \'' . base64_encode(serialize($string)) . '\', ., "' . $hash . '")' . ']'; } |
|
22 | + Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//'.$prefix.$string; }, |
|
23 | + '' => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
24 | + Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
25 | + Tokenizer::NUM_SIGN => function($string) { return '[@id=\''.$string.'\']'; }, |
|
26 | + Tokenizer::DOT => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' '.$string.' \')]'; }, |
|
27 | + Tokenizer::OPEN_SQUARE_BRACKET => function($string) use ($hash) { return '['.'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \''.base64_encode(serialize($string)).'\', ., "'.$hash.'")'.']'; } |
|
28 | 28 | ]; |
29 | 29 | } |
30 | 30 | |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $functionSet->setElement($element[0]); |
44 | 44 | |
45 | 45 | $attributes = array(); |
46 | - foreach($element[0]->attributes as $attribute_name => $attribute_node) { |
|
46 | + foreach ($element[0]->attributes as $attribute_name => $attribute_node) { |
|
47 | 47 | $attributes[$attribute_name] = $attribute_node->nodeValue; |
48 | 48 | } |
49 | 49 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | private function removeSpacesFromDirectDecend($css) { |
91 | 91 | $tokens = []; |
92 | 92 | foreach ($css->splitOnToken(Tokenizer::GREATER_THAN) as $token) { |
93 | - foreach ($token->trim() as $t) $tokens[] = $t; |
|
93 | + foreach ($token->trim() as $t) $tokens[] = $t; |
|
94 | 94 | $tokens[] = ['type' => Tokenizer::GREATER_THAN]; |
95 | 95 | } |
96 | 96 | return new Tokens(array_slice($tokens, 0, -1)); |
@@ -67,12 +67,16 @@ |
||
67 | 67 | } |
68 | 68 | |
69 | 69 | public function loadProperties(Hook\PropertyHook $hook) { |
70 | - foreach ($this->properties as $name => $property) $hook->registerProperty($name, $property); |
|
70 | + foreach ($this->properties as $name => $property) { |
|
71 | + $hook->registerProperty($name, $property); |
|
72 | + } |
|
71 | 73 | } |
72 | 74 | |
73 | 75 | public function createPseudoMatcher($pseudo) { |
74 | 76 | $pseudoMatcher = new Hook\PseudoMatcher($pseudo, $this->valueParser); |
75 | - foreach ($this->pseudo as $pseudoFunction) $pseudoMatcher->registerFunction(clone $pseudoFunction); |
|
77 | + foreach ($this->pseudo as $pseudoFunction) { |
|
78 | + $pseudoMatcher->registerFunction(clone $pseudoFunction); |
|
79 | + } |
|
76 | 80 | return $pseudoMatcher; |
77 | 81 | } |
78 | 82 |
@@ -6,39 +6,39 @@ |
||
6 | 6 | * @version 1.0 */ |
7 | 7 | namespace Transphporm\Parser; |
8 | 8 | class TokenFilterIterator implements \Iterator { |
9 | - private $ignore; |
|
10 | - private $tokens; |
|
9 | + private $ignore; |
|
10 | + private $tokens; |
|
11 | 11 | |
12 | - public function __construct(Tokens $tokens, array $ignore) { |
|
13 | - $this->ignore = $ignore; |
|
14 | - $this->tokens = $tokens; |
|
15 | - } |
|
12 | + public function __construct(Tokens $tokens, array $ignore) { |
|
13 | + $this->ignore = $ignore; |
|
14 | + $this->tokens = $tokens; |
|
15 | + } |
|
16 | 16 | |
17 | - public function current() { |
|
18 | - return $this->tokens->current(); |
|
19 | - } |
|
17 | + public function current() { |
|
18 | + return $this->tokens->current(); |
|
19 | + } |
|
20 | 20 | |
21 | - public function key() { |
|
22 | - return $this->tokens->key(); |
|
23 | - } |
|
21 | + public function key() { |
|
22 | + return $this->tokens->key(); |
|
23 | + } |
|
24 | 24 | |
25 | - public function valid() { |
|
26 | - return $this->tokens->valid(); |
|
27 | - } |
|
25 | + public function valid() { |
|
26 | + return $this->tokens->valid(); |
|
27 | + } |
|
28 | 28 | |
29 | - public function next() { |
|
30 | - do { |
|
31 | - $this->tokens->next(); |
|
32 | - } |
|
33 | - while ($this->shouldContinue()); |
|
34 | - } |
|
29 | + public function next() { |
|
30 | + do { |
|
31 | + $this->tokens->next(); |
|
32 | + } |
|
33 | + while ($this->shouldContinue()); |
|
34 | + } |
|
35 | 35 | |
36 | - public function rewind() { |
|
37 | - $this->tokens->rewind(); |
|
38 | - while ($this->shouldContinue()) $this->tokens->next(); |
|
39 | - } |
|
36 | + public function rewind() { |
|
37 | + $this->tokens->rewind(); |
|
38 | + while ($this->shouldContinue()) $this->tokens->next(); |
|
39 | + } |
|
40 | 40 | |
41 | - private function shouldContinue() { |
|
42 | - return $this->tokens->valid() && in_array($this->tokens->current()['type'], $this->ignore); |
|
43 | - } |
|
41 | + private function shouldContinue() { |
|
42 | + return $this->tokens->valid() && in_array($this->tokens->current()['type'], $this->ignore); |
|
43 | + } |
|
44 | 44 | } |
@@ -35,7 +35,9 @@ |
||
35 | 35 | |
36 | 36 | public function rewind() { |
37 | 37 | $this->tokens->rewind(); |
38 | - while ($this->shouldContinue()) $this->tokens->next(); |
|
38 | + while ($this->shouldContinue()) { |
|
39 | + $this->tokens->next(); |
|
40 | + } |
|
39 | 41 | } |
40 | 42 | |
41 | 43 | private function shouldContinue() { |
@@ -62,6 +62,10 @@ discard block |
||
62 | 62 | return (object) $result; |
63 | 63 | } |
64 | 64 | |
65 | + /** |
|
66 | + * @param Template $template |
|
67 | + * @param Config $config |
|
68 | + */ |
|
65 | 69 | private function processRules($template, $config) { |
66 | 70 | $rules = $this->getRules($template, $config); |
67 | 71 | |
@@ -71,6 +75,10 @@ discard block |
||
71 | 75 | } |
72 | 76 | |
73 | 77 | //Add a postprocessing hook. This cleans up anything transphporm has added to the markup which needs to be removed |
78 | + |
|
79 | + /** |
|
80 | + * @param Template $template |
|
81 | + */ |
|
74 | 82 | private function doPostProcessing($template) { |
75 | 83 | $template->addHook('//*[@transphporm]', new Hook\PostProcess()); |
76 | 84 | return $template; |
@@ -51,7 +51,7 @@ |
||
51 | 51 | |
52 | 52 | $cachedOutput = $this->loadTemplate(); |
53 | 53 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
54 | - $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>' . $cachedOutput['body'] . '</template>' ); |
|
54 | + $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>'.$cachedOutput['body'].'</template>'); |
|
55 | 55 | $valueParser = new Parser\Value($functionSet); |
56 | 56 | $config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix()), new FilePath($this->rootDir), $headers); |
57 | 57 |
@@ -26,7 +26,9 @@ discard block |
||
26 | 26 | $this->cache = new Cache(new \ArrayObject()); |
27 | 27 | |
28 | 28 | $modules = is_array($modules) ? $modules : $this->defaultModules; |
29 | - foreach ($modules as $module) $this->loadModule(new $module); |
|
29 | + foreach ($modules as $module) { |
|
30 | + $this->loadModule(new $module); |
|
31 | + } |
|
30 | 32 | } |
31 | 33 | |
32 | 34 | //Allow setting the time used by Transphporm for caching. This is for testing purposes |
@@ -55,7 +57,9 @@ discard block |
||
55 | 57 | $valueParser = new Parser\Value($functionSet); |
56 | 58 | $config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix()), new FilePath($this->rootDir), $headers); |
57 | 59 | |
58 | - foreach ($this->modules as $module) $module->load($config); |
|
60 | + foreach ($this->modules as $module) { |
|
61 | + $module->load($config); |
|
62 | + } |
|
59 | 63 | |
60 | 64 | $this->processRules($template, $config); |
61 | 65 | |
@@ -70,7 +74,9 @@ discard block |
||
70 | 74 | $rules = $this->getRules($template, $config); |
71 | 75 | |
72 | 76 | foreach ($rules as $rule) { |
73 | - if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $config); |
|
77 | + if ($rule->shouldRun($this->time)) { |
|
78 | + $this->executeTssRule($rule, $template, $config); |
|
79 | + } |
|
74 | 80 | } |
75 | 81 | } |
76 | 82 | |
@@ -95,8 +101,9 @@ discard block |
||
95 | 101 | if (trim($this->template)[0] !== '<') { |
96 | 102 | $xml = $this->cache->load($this->template, filemtime($this->template)); |
97 | 103 | return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
104 | + } else { |
|
105 | + return ['body' => $this->template, 'headers' => []]; |
|
98 | 106 | } |
99 | - else return ['body' => $this->template, 'headers' => []]; |
|
100 | 107 | } |
101 | 108 | |
102 | 109 | //Load the TSS rules either from a file or as a string |
@@ -1,9 +1,9 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace Transphporm; |
3 | 3 | class RunException extends \Exception { |
4 | - public function __construct($operationType, $operationName, \Exception $previous) { |
|
5 | - $message = 'TSS Error: Problem carrying out ' . $operationType . ' \'' . $operationName . '\''; |
|
4 | + public function __construct($operationType, $operationName, \Exception $previous) { |
|
5 | + $message = 'TSS Error: Problem carrying out ' . $operationType . ' \'' . $operationName . '\''; |
|
6 | 6 | |
7 | - parent::__construct($message, 0, $previous); |
|
8 | - } |
|
7 | + parent::__construct($message, 0, $previous); |
|
8 | + } |
|
9 | 9 | } |
@@ -2,7 +2,7 @@ |
||
2 | 2 | namespace Transphporm; |
3 | 3 | class RunException extends \Exception { |
4 | 4 | public function __construct($operationType, $operationName, \Exception $previous) { |
5 | - $message = 'TSS Error: Problem carrying out ' . $operationType . ' \'' . $operationName . '\''; |
|
5 | + $message = 'TSS Error: Problem carrying out '.$operationType.' \''.$operationName.'\''; |
|
6 | 6 | |
7 | 7 | parent::__construct($message, 0, $previous); |
8 | 8 | } |
@@ -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 | } |
@@ -17,6 +17,9 @@ |
||
17 | 17 | $this->xPath = $xPath; |
18 | 18 | } |
19 | 19 | |
20 | + /** |
|
21 | + * @param integer $index |
|
22 | + */ |
|
20 | 23 | private function readArray($array, $index) { |
21 | 24 | return isset($array[$index]) ? $array[$index] : null; |
22 | 25 | } |
@@ -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 | |
@@ -40,8 +45,11 @@ discard block |
||
40 | 45 | private function getTemplateContent($newNode, $tss) { |
41 | 46 | $result = []; |
42 | 47 | foreach ($newNode->childNodes as $node) { |
43 | - if (isset($node->tagName) && $node->tagName === 'template') $result[] = $this->getTemplateContent($node, $tss); |
|
44 | - else $result[] = $this->getClonedElement($node, $tss); |
|
48 | + if (isset($node->tagName) && $node->tagName === 'template') { |
|
49 | + $result[] = $this->getTemplateContent($node, $tss); |
|
50 | + } else { |
|
51 | + $result[] = $this->getClonedElement($node, $tss); |
|
52 | + } |
|
45 | 53 | } |
46 | 54 | return $result; |
47 | 55 | } |
@@ -60,7 +68,9 @@ discard block |
||
60 | 68 | |
61 | 69 | private function getClonedElement($node, $tss) { |
62 | 70 | $clone = $node->cloneNode(true); |
63 | - if ($tss != null && $clone instanceof \DomElement) $clone->setAttribute('transphporm', 'includedtemplate'); |
|
71 | + if ($tss != null && $clone instanceof \DomElement) { |
|
72 | + $clone->setAttribute('transphporm', 'includedtemplate'); |
|
73 | + } |
|
64 | 74 | return $clone; |
65 | 75 | } |
66 | 76 | } |
@@ -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 | } |