@@ -15,8 +15,11 @@ |
||
| 15 | 15 | $bracketMatcher = new \Transphporm\Parser\BracketMatcher($element->getNodePath()); |
| 16 | 16 | $num = $bracketMatcher->match('[', ']'); |
| 17 | 17 | |
| 18 | - if (is_callable([$this, $criteria])) return $this->$criteria($num); |
|
| 19 | - else return $num == $criteria; |
|
| 18 | + if (is_callable([$this, $criteria])) { |
|
| 19 | + return $this->$criteria($num); |
|
| 20 | + } else { |
|
| 21 | + return $num == $criteria; |
|
| 22 | + } |
|
| 20 | 23 | } |
| 21 | 24 | return true; |
| 22 | 25 | } |
@@ -31,7 +31,9 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | public function hasFunction($name) { |
| 33 | 33 | foreach ($this->pseudo as $pseudo) { |
| 34 | - if (strpos($pseudo, $name) === 0) return true; |
|
| 34 | + if (strpos($pseudo, $name) === 0) { |
|
| 35 | + return true; |
|
| 36 | + } |
|
| 35 | 37 | } |
| 36 | 38 | } |
| 37 | 39 | |
@@ -50,10 +52,16 @@ discard block |
||
| 50 | 52 | $parenthesis = strpos($pseudo, '('); |
| 51 | 53 | $square = strpos($pseudo, ']'); |
| 52 | 54 | |
| 53 | - if ($parenthesis === false) $parenthesis = 999; |
|
| 54 | - if ($square === false) $square = 999; |
|
| 55 | + if ($parenthesis === false) { |
|
| 56 | + $parenthesis = 999; |
|
| 57 | + } |
|
| 58 | + if ($square === false) { |
|
| 59 | + $square = 999; |
|
| 60 | + } |
|
| 55 | 61 | |
| 56 | - if ($parenthesis < $square) return ['(', ')']; |
|
| 62 | + if ($parenthesis < $square) { |
|
| 63 | + return ['(', ')']; |
|
| 64 | + } |
|
| 57 | 65 | return ['[', ']']; |
| 58 | 66 | } |
| 59 | 67 | |
@@ -30,7 +30,9 @@ |
||
| 30 | 30 | //Find all nodes matched by the expressions in the brackets :not(EXPR) |
| 31 | 31 | foreach ($xpath->query($xpathString) as $matchedElement) { |
| 32 | 32 | //Check to see whether this node was matched by the not query |
| 33 | - if ($element->isSameNode($matchedElement)) return false; |
|
| 33 | + if ($element->isSameNode($matchedElement)) { |
|
| 34 | + return false; |
|
| 35 | + } |
|
| 34 | 36 | } |
| 35 | 37 | } |
| 36 | 38 | return true; |
@@ -12,6 +12,9 @@ discard block |
||
| 12 | 12 | private $prefix; |
| 13 | 13 | private $valueParser; |
| 14 | 14 | |
| 15 | + /** |
|
| 16 | + * @param string $tss |
|
| 17 | + */ |
|
| 15 | 18 | public function __construct($tss, $baseDir, Value $valueParser, $prefix = '') { |
| 16 | 19 | $this->tss = $this->stripComments($tss, '/*', '*/'); |
| 17 | 20 | $this->tss = $this->stripComments($this->tss, '//', "\n"); |
@@ -38,6 +41,10 @@ discard block |
||
| 38 | 41 | return $rules; |
| 39 | 42 | } |
| 40 | 43 | |
| 44 | + /** |
|
| 45 | + * @param string $selector |
|
| 46 | + * @param integer $index |
|
| 47 | + */ |
|
| 41 | 48 | private function CssToRules($selector, $index, $properties) { |
| 42 | 49 | $parts = explode(',', $selector); |
| 43 | 50 | $rules = []; |
@@ -60,6 +67,11 @@ discard block |
||
| 60 | 67 | return $rules; |
| 61 | 68 | } |
| 62 | 69 | |
| 70 | + /** |
|
| 71 | + * @param integer $pos |
|
| 72 | + * @param integer $next |
|
| 73 | + * @param integer $indexStart |
|
| 74 | + */ |
|
| 63 | 75 | private function processingInstructions($tss, $pos, $next, $indexStart) { |
| 64 | 76 | $rules = []; |
| 65 | 77 | while (($atPos = strpos($tss, '@', $pos)) !== false) { |
@@ -90,6 +102,10 @@ discard block |
||
| 90 | 102 | return ($a->depth < $b->depth) ? -1 : 1; |
| 91 | 103 | } |
| 92 | 104 | |
| 105 | + /** |
|
| 106 | + * @param string $open |
|
| 107 | + * @param string $close |
|
| 108 | + */ |
|
| 93 | 109 | private function stripComments($str, $open, $close) { |
| 94 | 110 | $pos = 0; |
| 95 | 111 | while (($pos = strpos($str, $open, $pos)) !== false) { |
@@ -100,6 +116,9 @@ discard block |
||
| 100 | 116 | return $str; |
| 101 | 117 | } |
| 102 | 118 | |
| 119 | + /** |
|
| 120 | + * @param string $str |
|
| 121 | + */ |
|
| 103 | 122 | private function getProperties($str) { |
| 104 | 123 | $stringExtractor = new StringExtractor($str); |
| 105 | 124 | $rules = explode(';', $stringExtractor); |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | $selector = trim(substr($this->tss, $pos, $next-$pos)); |
| 31 | - $pos = strpos($this->tss, '}', $next)+1; |
|
| 31 | + $pos = strpos($this->tss, '}', $next)+1; |
|
| 32 | 32 | $newRules = $this->cssToRules($selector, count($rules)+$indexStart, $this->getProperties(trim(substr($this->tss, $next+1, $pos-2-$next)))); |
| 33 | 33 | $rules = $this->writeRule($rules, $newRules); |
| 34 | 34 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | private function processingInstructions($tss, $pos, $next, $indexStart) { |
| 64 | 64 | $rules = []; |
| 65 | 65 | while (($atPos = strpos($tss, '@', $pos)) !== false) { |
| 66 | - if ($atPos <= (int) $next) { |
|
| 66 | + if ($atPos <= (int) $next) { |
|
| 67 | 67 | $spacePos = strpos($tss, ' ', $atPos); |
| 68 | 68 | $funcName = substr($tss, $atPos+1, $spacePos-$atPos-1); |
| 69 | 69 | $pos = strpos($tss, ';', $spacePos); |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | private function import($args, $indexStart) { |
| 82 | - if (is_file(trim($args,'\'" '))) $fileName = trim($args,'\'" '); |
|
| 82 | + if (is_file(trim($args, '\'" '))) $fileName = trim($args, '\'" '); |
|
| 83 | 83 | else $fileName = $this->valueParser->parse($args)[0]; |
| 84 | - $sheet = new Sheet(file_get_contents($this->baseDir . $fileName), $this->baseDir, $this->valueParser, $this->prefix); |
|
| 84 | + $sheet = new Sheet(file_get_contents($this->baseDir.$fileName), $this->baseDir, $this->valueParser, $this->prefix); |
|
| 85 | 85 | return $sheet->parse(0, [], $indexStart); |
| 86 | 86 | } |
| 87 | 87 | |
@@ -33,7 +33,9 @@ discard block |
||
| 33 | 33 | $rules = $this->writeRule($rules, $newRules); |
| 34 | 34 | } |
| 35 | 35 | //there may be processing instructions at the end |
| 36 | - if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss), count($rules)+$indexStart)) $rules = array_merge($rules, $processing['rules']); |
|
| 36 | + if ($processing = $this->processingInstructions($this->tss, $pos, strlen($this->tss), count($rules)+$indexStart)) { |
|
| 37 | + $rules = array_merge($rules, $processing['rules']); |
|
| 38 | + } |
|
| 37 | 39 | usort($rules, [$this, 'sortRules']); |
| 38 | 40 | return $rules; |
| 39 | 41 | } |
@@ -69,8 +71,7 @@ discard block |
||
| 69 | 71 | $pos = strpos($tss, ';', $spacePos); |
| 70 | 72 | $args = substr($tss, $spacePos+1, $pos-$spacePos-1); |
| 71 | 73 | $rules = array_merge($rules, $this->$funcName($args, $indexStart)); |
| 72 | - } |
|
| 73 | - else { |
|
| 74 | + } else { |
|
| 74 | 75 | break; |
| 75 | 76 | } |
| 76 | 77 | } |
@@ -79,15 +80,20 @@ discard block |
||
| 79 | 80 | } |
| 80 | 81 | |
| 81 | 82 | private function import($args, $indexStart) { |
| 82 | - if (is_file(trim($args,'\'" '))) $fileName = trim($args,'\'" '); |
|
| 83 | - else $fileName = $this->valueParser->parse($args)[0]; |
|
| 83 | + if (is_file(trim($args,'\'" '))) { |
|
| 84 | + $fileName = trim($args,'\'" '); |
|
| 85 | + } else { |
|
| 86 | + $fileName = $this->valueParser->parse($args)[0]; |
|
| 87 | + } |
|
| 84 | 88 | $sheet = new Sheet(file_get_contents($this->baseDir . $fileName), $this->baseDir, $this->valueParser, $this->prefix); |
| 85 | 89 | return $sheet->parse(0, [], $indexStart); |
| 86 | 90 | } |
| 87 | 91 | |
| 88 | 92 | private function sortRules($a, $b) { |
| 89 | 93 | //If they have the same depth, compare on index |
| 90 | - if ($a->depth === $b->depth) return $a->index < $b->index ? -1 : 1; |
|
| 94 | + if ($a->depth === $b->depth) { |
|
| 95 | + return $a->index < $b->index ? -1 : 1; |
|
| 96 | + } |
|
| 91 | 97 | |
| 92 | 98 | return ($a->depth < $b->depth) ? -1 : 1; |
| 93 | 99 | } |
@@ -96,7 +102,9 @@ discard block |
||
| 96 | 102 | $pos = 0; |
| 97 | 103 | while (($pos = strpos($str, $open, $pos)) !== false) { |
| 98 | 104 | $end = strpos($str, $close, $pos); |
| 99 | - if ($end === false) break; |
|
| 105 | + if ($end === false) { |
|
| 106 | + break; |
|
| 107 | + } |
|
| 100 | 108 | $str = substr_replace($str, '', $pos, $end-$pos+2); |
| 101 | 109 | } |
| 102 | 110 | |
@@ -109,7 +117,9 @@ discard block |
||
| 109 | 117 | $return = []; |
| 110 | 118 | |
| 111 | 119 | foreach ($rules as $rule) { |
| 112 | - if (trim($rule) === '') continue; |
|
| 120 | + if (trim($rule) === '') { |
|
| 121 | + continue; |
|
| 122 | + } |
|
| 113 | 123 | $parts = explode(':', $rule, 2); |
| 114 | 124 | $parts[1] = $stringExtractor->rebuild($parts[1]); |
| 115 | 125 | $return[trim($parts[0])] = isset($parts[1]) ? trim($parts[1]) : ''; |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | $cachedOutput = $this->loadTemplate(); |
| 51 | 51 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
| 52 | - $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>' . $cachedOutput['body'] . '</template>' ); |
|
| 52 | + $template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>'.$cachedOutput['body'].'</template>'); |
|
| 53 | 53 | |
| 54 | 54 | $this->processRules($template, $data, $featureSet); |
| 55 | 55 | |
@@ -98,11 +98,11 @@ discard block |
||
| 98 | 98 | //N.b. only files can be cached |
| 99 | 99 | private function getRules($template, $valueParser) { |
| 100 | 100 | if (is_file($this->tss)) { |
| 101 | - $this->baseDir = dirname(realpath($this->tss)) . DIRECTORY_SEPARATOR; |
|
| 101 | + $this->baseDir = dirname(realpath($this->tss)).DIRECTORY_SEPARATOR; |
|
| 102 | 102 | //The cache for the key: the filename and template prefix |
| 103 | 103 | //Each template may have a different prefix which changes the parsed TSS, |
| 104 | 104 | //Because of this the cache needs to be generated for each template prefix. |
| 105 | - $key = $this->tss . $template->getPrefix() . $this->baseDir; |
|
| 105 | + $key = $this->tss.$template->getPrefix().$this->baseDir; |
|
| 106 | 106 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
| 107 | 107 | $rules = $this->cache->load($key, filemtime($this->tss)); |
| 108 | 108 | if (!$rules) return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
@@ -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 |
@@ -47,7 +49,9 @@ discard block |
||
| 47 | 49 | $data = new FunctionSet($elementData); |
| 48 | 50 | $config = new Config($data, $elementData, new Hook\Formatter(), $headers, $this->baseDir); |
| 49 | 51 | |
| 50 | - foreach ($this->modules as $module) $module->load($config); |
|
| 52 | + foreach ($this->modules as $module) { |
|
| 53 | + $module->load($config); |
|
| 54 | + } |
|
| 51 | 55 | |
| 52 | 56 | $cachedOutput = $this->loadTemplate(); |
| 53 | 57 | //To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does |
@@ -67,7 +71,9 @@ discard block |
||
| 67 | 71 | $rules = $this->getRules($template, $valueParser); |
| 68 | 72 | |
| 69 | 73 | foreach ($rules as $rule) { |
| 70 | - if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $valueParser, $config, $functionSet); |
|
| 74 | + if ($rule->shouldRun($this->time)) { |
|
| 75 | + $this->executeTssRule($rule, $template, $valueParser, $config, $functionSet); |
|
| 76 | + } |
|
| 71 | 77 | } |
| 72 | 78 | } |
| 73 | 79 | |
@@ -92,8 +98,9 @@ discard block |
||
| 92 | 98 | if (trim($this->template)[0] !== '<') { |
| 93 | 99 | $xml = $this->cache->load($this->template, filemtime($this->template)); |
| 94 | 100 | return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []]; |
| 101 | + } else { |
|
| 102 | + return ['body' => $this->template, 'headers' => []]; |
|
| 95 | 103 | } |
| 96 | - else return ['body' => $this->template, 'headers' => []]; |
|
| 97 | 104 | } |
| 98 | 105 | |
| 99 | 106 | //Load the TSS rules either from a file or as a string |
@@ -107,10 +114,14 @@ discard block |
||
| 107 | 114 | $key = $this->tss . $template->getPrefix() . $this->baseDir; |
| 108 | 115 | //Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet |
| 109 | 116 | $rules = $this->cache->load($key, filemtime($this->tss)); |
| 110 | - if (!$rules) return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
|
| 111 | - else return $rules; |
|
| 117 | + if (!$rules) { |
|
| 118 | + return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse()); |
|
| 119 | + } else { |
|
| 120 | + return $rules; |
|
| 121 | + } |
|
| 122 | + } else { |
|
| 123 | + return (new Parser\Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse(); |
|
| 112 | 124 | } |
| 113 | - else return (new Parser\Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse(); |
|
| 114 | 125 | } |
| 115 | 126 | |
| 116 | 127 | public function setCache(\ArrayAccess $cache) { |
@@ -23,8 +23,8 @@ |
||
| 23 | 23 | $end = strpos($str, '"', $pos+1); |
| 24 | 24 | if (!$end) break; |
| 25 | 25 | while ($str[$end-1] == '\\') $end = strpos($str, '"', $end+1); |
| 26 | - $strings['$___STR' . ++$num] = substr($str, $pos, $end-$pos+1); |
|
| 27 | - $str = substr_replace($str, '$___STR' . $num, $pos, $end-$pos+1); |
|
| 26 | + $strings['$___STR'.++$num] = substr($str, $pos, $end-$pos+1); |
|
| 27 | + $str = substr_replace($str, '$___STR'.$num, $pos, $end-$pos+1); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | return [$str, $strings]; |
@@ -21,7 +21,9 @@ discard block |
||
| 21 | 21 | $strings = []; |
| 22 | 22 | while (isset($str[$pos]) && ($pos = strpos($str, '"', $pos)) !== false) { |
| 23 | 23 | $end = strpos($str, '"', $pos+1); |
| 24 | - if (!$end) break; |
|
| 24 | + if (!$end) { |
|
| 25 | + break; |
|
| 26 | + } |
|
| 25 | 27 | $end = $this->getNextPosEscaped($str, '\\', '"', $end); |
| 26 | 28 | $strings['$___STR' . ++$num] = substr($str, $pos, $end-$pos+1); |
| 27 | 29 | $str = substr_replace($str, '$___STR' . $num, $pos, $end-$pos+1); |
@@ -31,7 +33,9 @@ discard block |
||
| 31 | 33 | } |
| 32 | 34 | |
| 33 | 35 | private function getNextPosEscaped($str, $escape, $chr, $start) { |
| 34 | - while ($str[$start-1] == $escape) $start = strpos($str, $chr, $start+1); |
|
| 36 | + while ($str[$start-1] == $escape) { |
|
| 37 | + $start = strpos($str, $chr, $start+1); |
|
| 38 | + } |
|
| 35 | 39 | return $start; |
| 36 | 40 | } |
| 37 | 41 | |
@@ -14,8 +14,8 @@ |
||
| 14 | 14 | |
| 15 | 15 | private function getLocale() { |
| 16 | 16 | if (is_array($this->locale)) return $this->locale; |
| 17 | - 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); |
|
| 18 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
| 17 | + 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); |
|
| 18 | + else return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'../Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.'enGB.json'), true); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | public function load(\Transphporm\FeatureSet $featureSet) { |
@@ -13,9 +13,13 @@ |
||
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | private function getLocale() { |
| 16 | - if (is_array($this->locale)) return $this->locale; |
|
| 17 | - 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); |
|
| 18 | - else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
| 16 | + if (is_array($this->locale)) { |
|
| 17 | + return $this->locale; |
|
| 18 | + } else if (strlen($this->locale) > 0) { |
|
| 19 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true); |
|
| 20 | + } else { |
|
| 21 | + return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . '../Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true); |
|
| 22 | + } |
|
| 19 | 23 | } |
| 20 | 24 | |
| 21 | 25 | public function load(\Transphporm\FeatureSet $featureSet) { |
@@ -11,6 +11,9 @@ discard block |
||
| 11 | 11 | private $formatter; |
| 12 | 12 | |
| 13 | 13 | |
| 14 | + /** |
|
| 15 | + * @param \Transphporm\FunctionSet $data |
|
| 16 | + */ |
|
| 14 | 17 | public function __construct($data, &$headers, \Transphporm\Hook\Formatter $formatter) { |
| 15 | 18 | $this->data = $data; |
| 16 | 19 | $this->headers = &$headers; |
@@ -30,6 +33,9 @@ discard block |
||
| 30 | 33 | } |
| 31 | 34 | } |
| 32 | 35 | |
| 36 | + /** |
|
| 37 | + * @param \DOMElement $element |
|
| 38 | + */ |
|
| 33 | 39 | private function shouldRun($element) { |
| 34 | 40 | if ($element->getAttribute('transphporm') === 'remove') return false; |
| 35 | 41 | do { |
@@ -43,6 +49,10 @@ discard block |
||
| 43 | 49 | return (isset($rules['content-mode'])) ? $rules['content-mode'] : 'append'; |
| 44 | 50 | } |
| 45 | 51 | |
| 52 | + /** |
|
| 53 | + * @param \DOMElement $element |
|
| 54 | + * @param \Transphporm\Hook\PseudoMatcher $pseudoMatcher |
|
| 55 | + */ |
|
| 46 | 56 | private function processPseudo($value, $element, $pseudoMatcher) { |
| 47 | 57 | $pseudoContent = ['attr', 'header', 'before', 'after']; |
| 48 | 58 | foreach ($pseudoContent as $pseudo) { |
@@ -93,6 +103,9 @@ discard block |
||
| 93 | 103 | } |
| 94 | 104 | } |
| 95 | 105 | |
| 106 | + /** |
|
| 107 | + * @param \DOMElement $element |
|
| 108 | + */ |
|
| 96 | 109 | private function replaceContent($element, $content) { |
| 97 | 110 | //If this rule was cached, the elements that were added last time need to be removed prior to running the rule again. |
| 98 | 111 | foreach ($this->getNode($content, $element->ownerDocument) as $node) { |
@@ -101,12 +114,18 @@ discard block |
||
| 101 | 114 | $element->setAttribute('transphporm', 'remove'); |
| 102 | 115 | } |
| 103 | 116 | |
| 117 | + /** |
|
| 118 | + * @param \DOMElement $element |
|
| 119 | + */ |
|
| 104 | 120 | private function appendContent($element, $content) { |
| 105 | 121 | foreach ($this->getNode($content, $element->ownerDocument) as $node) { |
| 106 | 122 | $element->appendChild($node); |
| 107 | 123 | } |
| 108 | 124 | } |
| 109 | 125 | |
| 126 | + /** |
|
| 127 | + * @param \DOMElement $element |
|
| 128 | + */ |
|
| 110 | 129 | private function removeAllChildren($element) { |
| 111 | 130 | while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
| 112 | 131 | } |
@@ -18,21 +18,28 @@ discard block |
||
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) { |
| 21 | - if (!$this->shouldRun($element)) return false; |
|
| 21 | + if (!$this->shouldRun($element)) { |
|
| 22 | + return false; |
|
| 23 | + } |
|
| 22 | 24 | |
| 23 | 25 | $values = $this->formatter->format($values, $rules); |
| 24 | 26 | if (!$this->processPseudo($values, $element, $pseudoMatcher)) { |
| 25 | 27 | //Remove the current contents |
| 26 | 28 | $this->removeAllChildren($element); |
| 27 | 29 | //Now make a text node |
| 28 | - if ($this->getContentMode($rules) === 'replace') $this->replaceContent($element, $values); |
|
| 29 | - else $this->appendContent($element, $values); |
|
| 30 | + if ($this->getContentMode($rules) === 'replace') { |
|
| 31 | + $this->replaceContent($element, $values); |
|
| 32 | + } else { |
|
| 33 | + $this->appendContent($element, $values); |
|
| 34 | + } |
|
| 30 | 35 | } |
| 31 | 36 | } |
| 32 | 37 | |
| 33 | 38 | private function shouldRun($element) { |
| 34 | 39 | do { |
| 35 | - if ($element->getAttribute('transphporm') == 'includedtemplate') return false; |
|
| 40 | + if ($element->getAttribute('transphporm') == 'includedtemplate') { |
|
| 41 | + return false; |
|
| 42 | + } |
|
| 36 | 43 | } |
| 37 | 44 | while (($element = $element->parentNode) instanceof \DomElement); |
| 38 | 45 | return true; |
@@ -54,21 +61,26 @@ discard block |
||
| 54 | 61 | } |
| 55 | 62 | |
| 56 | 63 | private function getNode($node, $document) { |
| 57 | - if (is_array($node[0])) $node = $node[0]; |
|
| 64 | + if (is_array($node[0])) { |
|
| 65 | + $node = $node[0]; |
|
| 66 | + } |
|
| 58 | 67 | foreach ($node as $n) { |
| 59 | 68 | |
| 60 | 69 | if ($n instanceof \DomElement) { |
| 61 | 70 | $new = $document->importNode($n, true); |
| 62 | 71 | //Removing this might cause problems with caching... |
| 63 | 72 | //$new->setAttribute('transphporm', 'added'); |
| 64 | - } |
|
| 65 | - else { |
|
| 73 | + } else { |
|
| 66 | 74 | |
| 67 | 75 | |
| 68 | 76 | |
| 69 | - if ($n instanceof \DomText) $n = $n->nodeValue; |
|
| 77 | + if ($n instanceof \DomText) { |
|
| 78 | + $n = $n->nodeValue; |
|
| 79 | + } |
|
| 70 | 80 | $new = $document->createElement('text'); |
| 71 | - if (is_array($n)) throw new \Exception(); |
|
| 81 | + if (is_array($n)) { |
|
| 82 | + throw new \Exception(); |
|
| 83 | + } |
|
| 72 | 84 | |
| 73 | 85 | $new->appendChild($document->createTextNode($n)); |
| 74 | 86 | $new->setAttribute('transphporm', 'text'); |
@@ -114,6 +126,8 @@ discard block |
||
| 114 | 126 | } |
| 115 | 127 | |
| 116 | 128 | private function removeAllChildren($element) { |
| 117 | - while ($element->hasChildNodes()) $element->removeChild($element->firstChild); |
|
| 129 | + while ($element->hasChildNodes()) { |
|
| 130 | + $element->removeChild($element->firstChild); |
|
| 131 | + } |
|
| 118 | 132 | } |
| 119 | 133 | } |
| 120 | 134 | \ No newline at end of file |
@@ -35,12 +35,16 @@ |
||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | public function loadProperties(Hook\PropertyHook $hook) { |
| 38 | - foreach ($this->properties as $name => $property) $hook->registerProperty($name, $property); |
|
| 38 | + foreach ($this->properties as $name => $property) { |
|
| 39 | + $hook->registerProperty($name, $property); |
|
| 40 | + } |
|
| 39 | 41 | } |
| 40 | 42 | |
| 41 | 43 | public function createPseudoMatcher($pseudo) { |
| 42 | 44 | $pseudoMatcher = new Hook\PseudoMatcher($pseudo); |
| 43 | - foreach ($this->pseudo as $pseudoFunction) $pseudoMatcher->registerFunction($pseudoFunction); |
|
| 45 | + foreach ($this->pseudo as $pseudoFunction) { |
|
| 46 | + $pseudoMatcher->registerFunction($pseudoFunction); |
|
| 47 | + } |
|
| 44 | 48 | return $pseudoMatcher; |
| 45 | 49 | } |
| 46 | 50 | } |
| 47 | 51 | \ No newline at end of file |