@@ -105,7 +105,7 @@ |
||
| 105 | 105 | $string = $this->extractString($i); |
| 106 | 106 | $length = strlen($string)+1; |
| 107 | 107 | $char = $this->getChar($char); |
| 108 | - $string = str_replace('\\' . $char, $char, $string); |
|
| 108 | + $string = str_replace('\\'.$char, $char, $string); |
|
| 109 | 109 | $tokens[] = ['type' => self::STRING, 'value' => $string]; |
| 110 | 110 | return $length; |
| 111 | 111 | } |
@@ -69,8 +69,11 @@ discard block |
||
| 69 | 69 | $i += $this->doStrings($tokens, $char, $i); |
| 70 | 70 | $i += $this->doBrackets($tokens, $char, $i); |
| 71 | 71 | } |
| 72 | - if ($returnObj) return new Tokens($tokens); |
|
| 73 | - else return $tokens; |
|
| 72 | + if ($returnObj) { |
|
| 73 | + return new Tokens($tokens); |
|
| 74 | + } else { |
|
| 75 | + return $tokens; |
|
| 76 | + } |
|
| 74 | 77 | } |
| 75 | 78 | |
| 76 | 79 | private function doSimpleTokens(&$tokens, $char) { |
@@ -93,10 +96,15 @@ discard block |
||
| 93 | 96 | } |
| 94 | 97 | |
| 95 | 98 | private function processLiterals(&$tokens, $name) { |
| 96 | - if (is_numeric($name)) $tokens[] = ['type' => self::NUMERIC, 'value' => $name]; |
|
| 97 | - else if ($name == 'true') $tokens[] = ['type' => self::BOOL, 'value' => true]; |
|
| 98 | - else if ($name == 'false') $tokens[] = ['type' => self::BOOL, 'value' => false]; |
|
| 99 | - else $tokens[] = ['type' => self::NAME, 'value' => $name]; |
|
| 99 | + if (is_numeric($name)) { |
|
| 100 | + $tokens[] = ['type' => self::NUMERIC, 'value' => $name]; |
|
| 101 | + } else if ($name == 'true') { |
|
| 102 | + $tokens[] = ['type' => self::BOOL, 'value' => true]; |
|
| 103 | + } else if ($name == 'false') { |
|
| 104 | + $tokens[] = ['type' => self::BOOL, 'value' => false]; |
|
| 105 | + } else { |
|
| 106 | + $tokens[] = ['type' => self::NAME, 'value' => $name]; |
|
| 107 | + } |
|
| 100 | 108 | } |
| 101 | 109 | |
| 102 | 110 | private function doBrackets(&$tokens, $char, $i) { |
@@ -130,7 +138,9 @@ discard block |
||
| 130 | 138 | private function extractString($pos) { |
| 131 | 139 | $char = $this->str[$pos]; |
| 132 | 140 | $end = strpos($this->str, $char, $pos+1); |
| 133 | - while ($end !== false && $this->str[$end-1] == '\\') $end = strpos($this->str, $char, $end+1); |
|
| 141 | + while ($end !== false && $this->str[$end-1] == '\\') { |
|
| 142 | + $end = strpos($this->str, $char, $end+1); |
|
| 143 | + } |
|
| 134 | 144 | |
| 135 | 145 | return substr($this->str, $pos+1, $end-$pos-1); |
| 136 | 146 | } |
@@ -139,19 +149,27 @@ discard block |
||
| 139 | 149 | $close = strpos($this->str, $closeBracket, $open); |
| 140 | 150 | |
| 141 | 151 | $cPos = $open+1; |
| 142 | - while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) $close = strpos($this->str, $closeBracket, $close+1); |
|
| 152 | + while (($cPos = strpos($this->str, $startBracket, $cPos+1)) !== false && $cPos < $close) { |
|
| 153 | + $close = strpos($this->str, $closeBracket, $close+1); |
|
| 154 | + } |
|
| 143 | 155 | return substr($this->str, $open+1, $close-$open-1); |
| 144 | 156 | } |
| 145 | 157 | |
| 146 | 158 | private function identifyChar($chr) { |
| 147 | - if (isset($this->chars[$chr])) return $this->chars[$chr]; |
|
| 148 | - else return self::NAME; |
|
| 159 | + if (isset($this->chars[$chr])) { |
|
| 160 | + return $this->chars[$chr]; |
|
| 161 | + } else { |
|
| 162 | + return self::NAME; |
|
| 163 | + } |
|
| 149 | 164 | } |
| 150 | 165 | |
| 151 | 166 | private function getChar($num) { |
| 152 | 167 | $chars = array_reverse($this->chars); |
| 153 | - if (isset($chars[$num])) return $chars[$num]; |
|
| 154 | - else return false; |
|
| 168 | + if (isset($chars[$num])) { |
|
| 169 | + return $chars[$num]; |
|
| 170 | + } else { |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 155 | 173 | } |
| 156 | 174 | |
| 157 | 175 | public function serialize($tokens) { |
@@ -169,8 +187,11 @@ discard block |
||
| 169 | 187 | |
| 170 | 188 | private function serializeValue($token) { |
| 171 | 189 | if (isset($token['value'])) { |
| 172 | - if ($token['value'] instanceof Tokens) return $this->serialize($token['value']); |
|
| 173 | - else return $token['value']; |
|
| 190 | + if ($token['value'] instanceof Tokens) { |
|
| 191 | + return $this->serialize($token['value']); |
|
| 192 | + } else { |
|
| 193 | + return $token['value']; |
|
| 194 | + } |
|
| 174 | 195 | } |
| 175 | 196 | } |
| 176 | 197 | } |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | * @version 1.0 */ |
| 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; |
@@ -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); |
| 24 | 27 | $return = $parser->parseTokens($args, $data); |
| 25 | 28 | return $return[0]; |
@@ -11,14 +11,14 @@ |
||
| 11 | 11 | $json = $args[0]; |
| 12 | 12 | |
| 13 | 13 | if (trim($json)[0] != '{') { |
| 14 | - $path = $this->baseDir . $json; |
|
| 15 | - if (!file_exists($path)) throw new \Exception('File does not exist at: ' . $path); |
|
| 14 | + $path = $this->baseDir.$json; |
|
| 15 | + if (!file_exists($path)) throw new \Exception('File does not exist at: '.$path); |
|
| 16 | 16 | $json = file_get_contents($json); |
| 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 (trim($json)[0] != '{') { |
| 14 | 14 | $path = $this->baseDir . $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($json); |
| 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 | } |
@@ -1,29 +1,29 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Transphporm\TSSFunction; |
| 3 | 3 | class Json implements \Transphporm\TSSFunction { |
| 4 | - private $baseDir; |
|
| 4 | + private $baseDir; |
|
| 5 | 5 | |
| 6 | - public function __construct(&$baseDir) { |
|
| 7 | - $this->baseDir = &$baseDir; |
|
| 8 | - } |
|
| 6 | + public function __construct(&$baseDir) { |
|
| 7 | + $this->baseDir = &$baseDir; |
|
| 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->baseDir . $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->baseDir . $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 | } |
@@ -51,7 +51,7 @@ |
||
| 51 | 51 | |
| 52 | 52 | public function extract($last, $autoLookup) { |
| 53 | 53 | $value = $this->read($last); |
| 54 | - if ($value && ($autoLookup || is_array($this->data)) ) { |
|
| 54 | + if ($value && ($autoLookup || is_array($this->data))) { |
|
| 55 | 55 | return $value; |
| 56 | 56 | } |
| 57 | 57 | throw new \UnexpectedValueException('Not found'); |
@@ -14,16 +14,23 @@ discard block |
||
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function traverse($key) { |
| 17 | - if (isset($this->data->{$key})) $this->data = $this->data->{$key}; |
|
| 18 | - else if (is_array($this->data) && isset($this->data[$key])) $this->data = $this->data[$key]; |
|
| 17 | + if (isset($this->data->{$key})) { |
|
| 18 | + $this->data = $this->data->{$key}; |
|
| 19 | + } else if (is_array($this->data) && isset($this->data[$key])) { |
|
| 20 | + $this->data = $this->data[$key]; |
|
| 21 | + } |
|
| 19 | 22 | } |
| 20 | 23 | |
| 21 | 24 | public function read($value) { |
| 22 | 25 | if (is_array($this->data)) { |
| 23 | - if (isset($this->data[$value])) return $this->data[$value]; |
|
| 26 | + if (isset($this->data[$value])) { |
|
| 27 | + return $this->data[$value]; |
|
| 28 | + } |
|
| 29 | + } else if (isset($this->data->$value)) { |
|
| 30 | + return $this->data->$value; |
|
| 31 | + } else { |
|
| 32 | + return false; |
|
| 24 | 33 | } |
| 25 | - else if (isset($this->data->$value)) return $this->data->$value; |
|
| 26 | - else return false; |
|
| 27 | 34 | } |
| 28 | 35 | |
| 29 | 36 | public function isFunctionSet() { |
@@ -36,7 +43,9 @@ discard block |
||
| 36 | 43 | |
| 37 | 44 | public function parseNested($parser, $token, $funcName) { |
| 38 | 45 | $args = $parser->parseTokens($token['value'], $this->data); |
| 39 | - if ($args[0] == $this->data) $args = []; |
|
| 46 | + if ($args[0] == $this->data) { |
|
| 47 | + $args = []; |
|
| 48 | + } |
|
| 40 | 49 | return $this->callFunc($funcName, $args, $this->data); |
| 41 | 50 | } |
| 42 | 51 | |
@@ -45,8 +54,11 @@ discard block |
||
| 45 | 54 | } |
| 46 | 55 | |
| 47 | 56 | private function callFuncOnObject($obj, $func, $args) { |
| 48 | - if (isset($obj->$func) && is_callable($obj->$func)) return call_user_func_array($obj->$func, $args); |
|
| 49 | - else return call_user_func_array([$obj, $func], $args); |
|
| 57 | + if (isset($obj->$func) && is_callable($obj->$func)) { |
|
| 58 | + return call_user_func_array($obj->$func, $args); |
|
| 59 | + } else { |
|
| 60 | + return call_user_func_array([$obj, $func], $args); |
|
| 61 | + } |
|
| 50 | 62 | } |
| 51 | 63 | |
| 52 | 64 | public function extract($last, $autoLookup) { |
@@ -16,7 +16,9 @@ discard block |
||
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | public function match($name, $args, \DomElement $element) { |
| 19 | - if ($name !== 'not') return true; |
|
| 19 | + if ($name !== 'not') { |
|
| 20 | + return true; |
|
| 21 | + } |
|
| 20 | 22 | |
| 21 | 23 | $xpath = new \DomXpath($element->ownerDocument); |
| 22 | 24 | return $this->notElement($args, $xpath, $element); |
@@ -29,7 +31,9 @@ discard block |
||
| 29 | 31 | //Find all nodes matched by the expressions in the brackets :not(EXPR) |
| 30 | 32 | foreach ($xpath->query($xpathString) as $matchedElement) { |
| 31 | 33 | //Check to see whether this node was matched by the not query |
| 32 | - if ($element->isSameNode($matchedElement)) return false; |
|
| 34 | + if ($element->isSameNode($matchedElement)) { |
|
| 35 | + return false; |
|
| 36 | + } |
|
| 33 | 37 | } |
| 34 | 38 | } |
| 35 | 39 | return true; |
@@ -14,7 +14,9 @@ |
||
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | public function match($name, $args, \DomElement $element) { |
| 17 | - if (!($name === null || in_array($name, ['data', 'iteration', 'root']))) return true; |
|
| 17 | + if (!($name === null || in_array($name, ['data', 'iteration', 'root']))) { |
|
| 18 | + return true; |
|
| 19 | + } |
|
| 18 | 20 | return $args[0]; |
| 19 | 21 | } |
| 20 | 22 | } |
@@ -28,6 +28,9 @@ discard block |
||
| 28 | 28 | } |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | + /** |
|
| 32 | + * @param \DOMElement $element |
|
| 33 | + */ |
|
| 31 | 34 | private function shouldRun($element) { |
| 32 | 35 | do { |
| 33 | 36 | if ($element->getAttribute('transphporm') == 'includedtemplate') return false; |
@@ -40,6 +43,10 @@ discard block |
||
| 40 | 43 | return (isset($rules['content-mode'])) ? $rules['content-mode'] : 'append'; |
| 41 | 44 | } |
| 42 | 45 | |
| 46 | + /** |
|
| 47 | + * @param \DOMElement $element |
|
| 48 | + * @param \Transphporm\Hook\PseudoMatcher $pseudoMatcher |
|
| 49 | + */ |
|
| 43 | 50 | private function processPseudo($value, $element, $pseudoMatcher) { |
| 44 | 51 | $pseudoContent = ['attr', 'header', 'before', 'after']; |
| 45 | 52 | foreach ($pseudoContent as $pseudo) { |
@@ -96,6 +103,9 @@ discard block |
||
| 96 | 103 | } |
| 97 | 104 | } |
| 98 | 105 | |
| 106 | + /** |
|
| 107 | + * @param \DOMElement $element |
|
| 108 | + */ |
|
| 99 | 109 | private function replaceContent($element, $content) { |
| 100 | 110 | //If this rule was cached, the elements that were added last time need to be removed prior to running the rule again. |
| 101 | 111 | foreach ($this->getNode($content, $element->ownerDocument) as $node) { |
@@ -104,12 +114,18 @@ discard block |
||
| 104 | 114 | $element->setAttribute('transphporm', 'remove'); |
| 105 | 115 | } |
| 106 | 116 | |
| 117 | + /** |
|
| 118 | + * @param \DOMElement $element |
|
| 119 | + */ |
|
| 107 | 120 | private function appendContent($element, $content) { |
| 108 | 121 | foreach ($this->getNode($content, $element->ownerDocument) as $node) { |
| 109 | 122 | $element->appendChild($node); |
| 110 | 123 | } |
| 111 | 124 | } |
| 112 | 125 | |
| 126 | + /** |
|
| 127 | + * @param \DOMElement $element |
|
| 128 | + */ |
|
| 113 | 129 | private function removeAllChildren($element) { |
| 114 | 130 | while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
| 115 | 131 | } |
@@ -15,21 +15,28 @@ discard block |
||
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
| 18 | - if (!$this->shouldRun($element)) return false; |
|
| 18 | + if (!$this->shouldRun($element)) { |
|
| 19 | + return false; |
|
| 20 | + } |
|
| 19 | 21 | $values = $this->formatter->format($values, $rules); |
| 20 | 22 | |
| 21 | 23 | if (!$this->processPseudo($values, $element, $pseudoMatcher)) { |
| 22 | 24 | //Remove the current contents |
| 23 | 25 | $this->removeAllChildren($element); |
| 24 | 26 | //Now make a text node |
| 25 | - if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $values); |
|
| 26 | - else $this->appendContent($element, $values); |
|
| 27 | + if ($this->getContentMode($rules) === 'replace') { |
|
| 28 | + $this->replaceContent($element, $values); |
|
| 29 | + } else { |
|
| 30 | + $this->appendContent($element, $values); |
|
| 31 | + } |
|
| 27 | 32 | } |
| 28 | 33 | } |
| 29 | 34 | |
| 30 | 35 | private function shouldRun($element) { |
| 31 | 36 | do { |
| 32 | - if ($element->getAttribute('transphporm') == 'includedtemplate') return false; |
|
| 37 | + if ($element->getAttribute('transphporm') == 'includedtemplate') { |
|
| 38 | + return false; |
|
| 39 | + } |
|
| 33 | 40 | } |
| 34 | 41 | while (($element = $element->parentNode) instanceof \DomElement); |
| 35 | 42 | return true; |
@@ -53,9 +60,10 @@ discard block |
||
| 53 | 60 | private function getNode($node, $document) { |
| 54 | 61 | foreach ($node as $n) { |
| 55 | 62 | if (is_array($n)) { |
| 56 | - foreach ($this->getNode($n, $document) as $new) yield $new; |
|
| 57 | - } |
|
| 58 | - else { |
|
| 63 | + foreach ($this->getNode($n, $document) as $new) { |
|
| 64 | + yield $new; |
|
| 65 | + } |
|
| 66 | + } else { |
|
| 59 | 67 | yield $this->convertNode($n, $document); |
| 60 | 68 | } |
| 61 | 69 | } |
@@ -66,9 +74,10 @@ discard block |
||
| 66 | 74 | $new = $document->importNode($node, true); |
| 67 | 75 | //Removing this might cause problems with caching... |
| 68 | 76 | //$new->setAttribute('transphporm', 'added'); |
| 69 | - } |
|
| 70 | - else { |
|
| 71 | - if ($node instanceof \DomText) $node = $node->nodeValue; |
|
| 77 | + } else { |
|
| 78 | + if ($node instanceof \DomText) { |
|
| 79 | + $node = $node->nodeValue; |
|
| 80 | + } |
|
| 72 | 81 | $new = $document->createElement('text'); |
| 73 | 82 | |
| 74 | 83 | $new->appendChild($document->createTextNode($node)); |
@@ -114,6 +123,8 @@ discard block |
||
| 114 | 123 | } |
| 115 | 124 | |
| 116 | 125 | private function removeAllChildren($element) { |
| 117 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
| 126 | + while ($element->hasChildNodes()) { |
|
| 127 | + $element->removeChild($element->firstChild); |
|
| 128 | + } |
|
| 118 | 129 | } |
| 119 | 130 | } |
@@ -84,7 +84,7 @@ |
||
| 84 | 84 | |
| 85 | 85 | private function import($args, $indexStart) { |
| 86 | 86 | $fileName = $args[0]; |
| 87 | - $sheet = new Sheet(file_get_contents($this->baseDir . $fileName), dirname(realpath($this->baseDir . $fileName)) . DIRECTORY_SEPARATOR, $this->xPath, $this->valueParser); |
|
| 87 | + $sheet = new Sheet(file_get_contents($this->baseDir.$fileName), dirname(realpath($this->baseDir.$fileName)).DIRECTORY_SEPARATOR, $this->xPath, $this->valueParser); |
|
| 88 | 88 | return $sheet->parse($indexStart); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -13,6 +13,9 @@ discard block |
||
| 13 | 13 | private $xPath; |
| 14 | 14 | private $tokenizer; |
| 15 | 15 | |
| 16 | + /** |
|
| 17 | + * @param string $tss |
|
| 18 | + */ |
|
| 16 | 19 | public function __construct($tss, $baseDir, CssToXpath $xPath, Value $valueParser) { |
| 17 | 20 | $this->tss = $this->stripComments($tss, '//', "\n"); |
| 18 | 21 | $this->tss = $this->stripComments($this->tss, '/*', '*/'); |
@@ -44,6 +47,9 @@ discard block |
||
| 44 | 47 | return $rules; |
| 45 | 48 | } |
| 46 | 49 | |
| 50 | + /** |
|
| 51 | + * @param integer $index |
|
| 52 | + */ |
|
| 47 | 53 | private function CssToRules($selector, $index, $properties) { |
| 48 | 54 | $parts = $selector->trim()->splitOnToken(Tokenizer::ARG); |
| 49 | 55 | $rules = []; |
@@ -67,6 +73,9 @@ discard block |
||
| 67 | 73 | return $rules; |
| 68 | 74 | } |
| 69 | 75 | |
| 76 | + /** |
|
| 77 | + * @param integer $indexStart |
|
| 78 | + */ |
|
| 70 | 79 | private function processingInstructions($token, $indexStart) { |
| 71 | 80 | if ($token['type'] !== Tokenizer::AT_SIGN) return false; |
| 72 | 81 | $tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false); |
@@ -90,6 +99,10 @@ discard block |
||
| 90 | 99 | return ($a->depth < $b->depth) ? -1 : 1; |
| 91 | 100 | } |
| 92 | 101 | |
| 102 | + /** |
|
| 103 | + * @param string $open |
|
| 104 | + * @param string $close |
|
| 105 | + */ |
|
| 93 | 106 | private function stripComments($str, $open, $close) { |
| 94 | 107 | $pos = 0; |
| 95 | 108 | while (($pos = strpos($str, $open, $pos)) !== false) { |
@@ -102,14 +102,14 @@ |
||
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | private function getProperties($tokens) { |
| 105 | - $rules = $tokens->splitOnToken(Tokenizer::SEMI_COLON); |
|
| 105 | + $rules = $tokens->splitOnToken(Tokenizer::SEMI_COLON); |
|
| 106 | 106 | |
| 107 | - $return = []; |
|
| 108 | - foreach ($rules as $rule) { |
|
| 109 | - $name = $rule->from(Tokenizer::NAME, true)->to(Tokenizer::COLON)->read(); |
|
| 110 | - $return[$name] = $rule->from(Tokenizer::COLON)->trim(); |
|
| 111 | - } |
|
| 107 | + $return = []; |
|
| 108 | + foreach ($rules as $rule) { |
|
| 109 | + $name = $rule->from(Tokenizer::NAME, true)->to(Tokenizer::COLON)->read(); |
|
| 110 | + $return[$name] = $rule->from(Tokenizer::COLON)->trim(); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - return $return; |
|
| 114 | - } |
|
| 113 | + return $return; |
|
| 114 | + } |
|
| 115 | 115 | } |
@@ -33,7 +33,9 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | $selector = $this->tss->from($token['type'], true)->to(Tokenizer::OPEN_BRACE); |
| 35 | 35 | $this->tss->skip(count($selector)); |
| 36 | - if (count($selector) === 0) break; |
|
| 36 | + if (count($selector) === 0) { |
|
| 37 | + break; |
|
| 38 | + } |
|
| 37 | 39 | |
| 38 | 40 | $newRules = $this->cssToRules($selector, count($rules)+$indexStart, $this->getProperties($this->tss->current()['value'])); |
| 39 | 41 | $rules = $this->writeRule($rules, $newRules); |
@@ -44,7 +46,9 @@ discard block |
||
| 44 | 46 | } |
| 45 | 47 | |
| 46 | 48 | private function checkError($rules) { |
| 47 | - if (empty($rules) && count($this->tss) > 0) throw new \Exception('No TSS rules parsed'); |
|
| 49 | + if (empty($rules) && count($this->tss) > 0) { |
|
| 50 | + throw new \Exception('No TSS rules parsed'); |
|
| 51 | + } |
|
| 48 | 52 | } |
| 49 | 53 | |
| 50 | 54 | private function CssToRules($selector, $index, $properties) { |
@@ -71,7 +75,9 @@ discard block |
||
| 71 | 75 | } |
| 72 | 76 | |
| 73 | 77 | private function processingInstructions($token, $indexStart) { |
| 74 | - if ($token['type'] !== Tokenizer::AT_SIGN) return false; |
|
| 78 | + if ($token['type'] !== Tokenizer::AT_SIGN) { |
|
| 79 | + return false; |
|
| 80 | + } |
|
| 75 | 81 | $tokens = $this->tss->from(Tokenizer::AT_SIGN, false)->to(Tokenizer::SEMI_COLON, false); |
| 76 | 82 | $funcName = $tokens->from(Tokenizer::NAME, true)->read(); |
| 77 | 83 | $args = $this->valueParser->parseTokens($tokens->from(Tokenizer::NAME)); |
@@ -88,7 +94,9 @@ discard block |
||
| 88 | 94 | |
| 89 | 95 | private function sortRules($a, $b) { |
| 90 | 96 | //If they have the same depth, compare on index |
| 91 | - if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1; |
|
| 97 | + if ($a->depth === $b->depth) { |
|
| 98 | + return $a->index < $b->index ? -1 : 1; |
|
| 99 | + } |
|
| 92 | 100 | |
| 93 | 101 | return ($a->depth < $b->depth) ? -1 : 1; |
| 94 | 102 | } |
@@ -97,7 +105,9 @@ discard block |
||
| 97 | 105 | $pos = 0; |
| 98 | 106 | while (($pos = strpos($str, $open, $pos)) !== false) { |
| 99 | 107 | $end = strpos($str, $close, $pos); |
| 100 | - if ($end === false) break; |
|
| 108 | + if ($end === false) { |
|
| 109 | + break; |
|
| 110 | + } |
|
| 101 | 111 | $str = substr_replace($str, '', $pos, $end-$pos+strlen($close)); |
| 102 | 112 | } |
| 103 | 113 | |
@@ -49,11 +49,11 @@ |
||
| 49 | 49 | $functionSet->setElement($element[0]); |
| 50 | 50 | |
| 51 | 51 | $attributes = array(); |
| 52 | - foreach($element[0]->attributes as $attribute_name => $attribute_node) { |
|
| 53 | - $attributes[$attribute_name] = $attribute_node->nodeValue; |
|
| 54 | - } |
|
| 52 | + foreach($element[0]->attributes as $attribute_name => $attribute_node) { |
|
| 53 | + $attributes[$attribute_name] = $attribute_node->nodeValue; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - $parser = new \Transphporm\Parser\Value($functionSet, true); |
|
| 56 | + $parser = new \Transphporm\Parser\Value($functionSet, true); |
|
| 57 | 57 | $return = $parser->parseTokens($attr, $attributes); |
| 58 | 58 | |
| 59 | 59 | return $return[0] === '' ? false : $return[0]; |
@@ -18,12 +18,12 @@ discard block |
||
| 18 | 18 | $this->functionSet = $functionSet; |
| 19 | 19 | |
| 20 | 20 | $this->translators = [ |
| 21 | - Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//' . $prefix . $string; }, |
|
| 22 | - '' => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
| 23 | - Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/' . $prefix . $string; }, |
|
| 24 | - Tokenizer::NUM_SIGN => function($string) { return '[@id=\'' . $string . '\']'; }, |
|
| 25 | - Tokenizer::DOT => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' ' . $string . ' \')]'; }, |
|
| 26 | - Tokenizer::OPEN_SQUARE_BRACKET => function($string) use ($hash) { return '[' .'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \'' . base64_encode(serialize($string)) . '\', ., "' . $hash . '")' . ']'; } |
|
| 21 | + Tokenizer::WHITESPACE => function($string) use ($prefix) { return '//'.$prefix.$string; }, |
|
| 22 | + '' => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
| 23 | + Tokenizer::GREATER_THAN => function($string) use ($prefix) { return '/'.$prefix.$string; }, |
|
| 24 | + Tokenizer::NUM_SIGN => function($string) { return '[@id=\''.$string.'\']'; }, |
|
| 25 | + Tokenizer::DOT => function($string) { return '[contains(concat(\' \', normalize-space(@class), \' \'), \' '.$string.' \')]'; }, |
|
| 26 | + Tokenizer::OPEN_SQUARE_BRACKET => function($string) use ($hash) { return '['.'php:function(\'\Transphporm\Parser\CssToXpath::processAttr\', \''.base64_encode(serialize($string)).'\', ., "'.$hash.'")'.']'; } |
|
| 27 | 27 | ]; |
| 28 | 28 | } |
| 29 | 29 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $functionSet->setElement($element[0]); |
| 48 | 48 | |
| 49 | 49 | $attributes = array(); |
| 50 | - foreach($element[0]->attributes as $attribute_name => $attribute_node) { |
|
| 50 | + foreach ($element[0]->attributes as $attribute_name => $attribute_node) { |
|
| 51 | 51 | $attributes[$attribute_name] = $attribute_node->nodeValue; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $tokens = []; |
| 79 | 79 | |
| 80 | 80 | foreach ($css->splitOnToken(Tokenizer::GREATER_THAN) as $token) { |
| 81 | - foreach ($token->trim() as $t) $tokens[] = $t; |
|
| 81 | + foreach ($token->trim() as $t) $tokens[] = $t; |
|
| 82 | 82 | $tokens[] = ['type' => Tokenizer::GREATER_THAN]; |
| 83 | 83 | } |
| 84 | 84 | $tokens = new Tokens(array_slice($tokens, 0, -1)); |
@@ -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)); |