Completed
Push — master ( 1bb4b5...609c6a )
by Tom
02:53 queued 01:06
created
src/FunctionSet.php 1 patch
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -26,11 +26,12 @@
 block discarded – undo
26 26
 	private function getArgs0($name, $args) {
27 27
 		if (isset($this->functions[$name]) && !($this->functions[$name] instanceof TSSFunction\Data)) {
28 28
 			$tokens = $args[0];
29
-			if ($tokens->count() == 0) return [];
29
+			if ($tokens->count() == 0) {
30
+				return [];
31
+			}
30 32
 			$parser = new \Transphporm\Parser\Value($this);
31 33
 			return $parser->parseTokens($tokens, $this->elementData->getData($this->element));
32
-		}
33
-		else {
34
+		} else {
34 35
 			return iterator_to_array($args[0]);
35 36
 		}
36 37
 
Please login to merge, or discard this patch.
src/Property/Content.php 1 patch
Braces   +28 added lines, -13 removed lines patch added patch discarded remove patch
@@ -14,7 +14,9 @@  discard block
 block discarded – undo
14 14
 	}
15 15
 
16 16
 	public function run(array $values, \DomElement $element, array $rules, \Transphporm\Hook\PseudoMatcher $pseudoMatcher, array $properties = []) {
17
-		if (!$this->shouldRun($element)) return false;
17
+		if (!$this->shouldRun($element)) {
18
+			return false;
19
+		}
18 20
 
19 21
 		$values = $this->formatter->format($values, $rules);
20 22
 
@@ -22,14 +24,19 @@  discard block
 block discarded – undo
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;
@@ -56,9 +63,10 @@  discard block
 block discarded – undo
56 63
 	public function getNode($node, $document) {
57 64
 		foreach ($node as $n) {
58 65
 			if (is_array($n)) {
59
-				foreach ($this->getNode($n, $document) as $new) yield $new;
60
-			}
61
-			else {
66
+				foreach ($this->getNode($n, $document) as $new) {
67
+					yield $new;
68
+				}
69
+			} else {
62 70
 				yield $this->convertNode($n, $document);
63 71
 			}
64 72
 		}
@@ -69,9 +77,10 @@  discard block
 block discarded – undo
69 77
 			$new = $document->importNode($node, true);
70 78
 			//Removing this might cause problems with caching...
71 79
 			//$new->setAttribute('transphporm', 'added');
72
-		}
73
-		else {
74
-			if ($node instanceof \DomText) $node = $node->nodeValue;
80
+		} else {
81
+			if ($node instanceof \DomText) {
82
+				$node = $node->nodeValue;
83
+			}
75 84
 			$new = $document->createElement('text');
76 85
 
77 86
 			$new->appendChild($document->createTextNode($node));
@@ -82,14 +91,18 @@  discard block
 block discarded – undo
82 91
 
83 92
 
84 93
 	private function replaceContent($element, $content) {
85
-		if ($element->getAttribute('transphporm') == 'added') return;
94
+		if ($element->getAttribute('transphporm') == 'added') {
95
+			return;
96
+		}
86 97
 		//If this rule was cached, the elements that were added last time need to be removed prior to running the rule again.
87 98
 		if ($element->getAttribute('transphporm')) {
88 99
 			$this->replaceCachedContent($element);
89 100
 		}
90 101
 
91 102
 		foreach ($this->getNode($content, $element->ownerDocument) as $node) {
92
-			if (!$node->getAttribute('transphporm'))  $node->setAttribute('transphporm', 'added');
103
+			if (!$node->getAttribute('transphporm')) {
104
+				$node->setAttribute('transphporm', 'added');
105
+			}
93 106
 			$element->parentNode->insertBefore($node, $element);
94 107
 		}
95 108
 
@@ -123,6 +136,8 @@  discard block
 block discarded – undo
123 136
 	}
124 137
 
125 138
 	private function removeAllChildren($element) {
126
-		while ($element->hasChildNodes()) $element->removeChild($element->firstChild);
139
+		while ($element->hasChildNodes()) {
140
+			$element->removeChild($element->firstChild);
141
+		}
127 142
 	}
128 143
 }
129 144
\ No newline at end of file
Please login to merge, or discard this patch.
src/Builder.php 4 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -74,6 +74,10 @@
 block discarded – undo
74 74
 
75 75
 
76 76
 	//Add a postprocessing hook. This cleans up anything transphporm has added to the markup which needs to be removed
77
+
78
+	/**
79
+	 * @param Template $template
80
+	 */
77 81
 	private function doPostProcessing($template) {
78 82
 		$template->addHook('//*[@transphporm]', new Hook\PostProcess());
79 83
 		return $template;
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
 	}
42 42
 
43 43
 	public function setLocale($locale) {
44
-                $format = new \Transphporm\Module\Format($locale);
45
-                $this->modules[get_class($format)] = $format;
46
-        }
44
+				$format = new \Transphporm\Module\Format($locale);
45
+				$this->modules[get_class($format)] = $format;
46
+		}
47 47
 
48 48
 	public function addPath($dir) {
49 49
 		$this->filePath->addPath($dir);
@@ -82,15 +82,15 @@  discard block
 block discarded – undo
82 82
 
83 83
 	//Load a template, firstly check if it's a file or a valid string
84 84
 	private function loadTemplate() {
85
-        $result = ['body' => $this->template, 'headers' => []];
85
+		$result = ['body' => $this->template, 'headers' => []];
86 86
 		if (strpos($this->template, "\n") === false && is_file($this->template)) $result = $this->loadTemplateFromFile($this->template);
87 87
 		return $result;
88 88
 	}
89 89
 
90
-    private function loadTemplateFromFile($file) {
91
-        $xml = $this->cache->load($this->template, filemtime($this->template));
92
-        return $xml ? $xml : ['body' => file_get_contents($this->template) ?: "", 'headers' => []];
93
-    }
90
+	private function loadTemplateFromFile($file) {
91
+		$xml = $this->cache->load($this->template, filemtime($this->template));
92
+		return $xml ? $xml : ['body' => file_get_contents($this->template) ?: "", 'headers' => []];
93
+	}
94 94
 
95 95
 	public function setCache(\ArrayAccess $cache) {
96 96
 		$this->cache = new Cache($cache);
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -57,8 +57,8 @@
 block discarded – undo
57 57
 
58 58
 		$cachedOutput = $this->loadTemplate();
59 59
 		//To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does
60
-		$template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>' . $cachedOutput['body'] . '</template>' );
61
-		$tssCache = new SheetLoader($this->cache,  $this->filePath, $this->tss, $template->getPrefix(), $this->time);
60
+		$template = new Template($this->isValidDoc($cachedOutput['body']) ? str_ireplace('<!doctype', '<!DOCTYPE', $cachedOutput['body']) : '<template>'.$cachedOutput['body'].'</template>');
61
+		$tssCache = new SheetLoader($this->cache, $this->filePath, $this->tss, $template->getPrefix(), $this->time);
62 62
 		$valueParser = new Parser\Value($functionSet);
63 63
 		$this->config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix(), md5($this->tss)), $this->filePath, $headers);
64 64
 
Please login to merge, or discard this patch.
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -27,7 +27,9 @@  discard block
 block discarded – undo
27 27
 		$this->cache = new Cache(new \ArrayObject());
28 28
 		$this->filePath = new FilePath();
29 29
 		$modules = is_array($modules) ? $modules : $this->defaultModules;
30
-		foreach ($modules as $module) $this->loadModule(new $module);
30
+		foreach ($modules as $module) {
31
+			$this->loadModule(new $module);
32
+		}
31 33
 	}
32 34
 
33 35
 	//Allow setting the time used by Transphporm for caching. This is for testing purposes
@@ -62,7 +64,9 @@  discard block
 block discarded – undo
62 64
 		$valueParser = new Parser\Value($functionSet);
63 65
 		$this->config = new Config($functionSet, $valueParser, $elementData, new Hook\Formatter(), new Parser\CssToXpath($functionSet, $template->getPrefix(), md5($this->tss)), $this->filePath, $headers);
64 66
 
65
-		foreach ($this->modules as $module) $module->load($this->config);
67
+		foreach ($this->modules as $module) {
68
+			$module->load($this->config);
69
+		}
66 70
 
67 71
 		$tssCache->processRules($template, $this->config);
68 72
 
@@ -83,7 +87,9 @@  discard block
 block discarded – undo
83 87
 	//Load a template, firstly check if it's a file or a valid string
84 88
 	private function loadTemplate() {
85 89
         $result = ['body' => $this->template, 'headers' => []];
86
-		if (strpos($this->template, "\n") === false && is_file($this->template)) $result = $this->loadTemplateFromFile($this->template);
90
+		if (strpos($this->template, "\n") === false && is_file($this->template)) {
91
+			$result = $this->loadTemplateFromFile($this->template);
92
+		}
87 93
 		return $result;
88 94
 	}
89 95
 
@@ -102,6 +108,8 @@  discard block
 block discarded – undo
102 108
 
103 109
 	public function __destruct() {
104 110
 		//Required hack as DomXPath can only register static functions clear the statically stored instance to avoid memory leaks
105
-		if (isset($this->config)) $this->config->getCssToXpath()->cleanup();
111
+		if (isset($this->config)) {
112
+			$this->config->getCssToXpath()->cleanup();
113
+		}
106 114
 	}
107 115
 }
Please login to merge, or discard this patch.
src/SheetLoader.php 4 patches
Doc Comments   +16 added lines patch added patch discarded remove patch
@@ -13,6 +13,10 @@  discard block
 block discarded – undo
13 13
     private $time;
14 14
     private $import = [];
15 15
 
16
+    /**
17
+     * @param string $tss
18
+     * @param string $prefix
19
+     */
16 20
     public function __construct(Cache $cache, FilePath $filePath, $tss, $prefix, $time) {
17 21
         $this->cache = $cache;
18 22
         $this->filePath = $filePath;
@@ -54,6 +58,9 @@  discard block
 block discarded – undo
54 58
 		return $rules;
55 59
     }
56 60
 
61
+	/**
62
+	 * @param Template $template
63
+	 */
57 64
 	public function processRules($template, \Transphporm\Config $config) {
58 65
 		$rules = $this->getRules($this->tss, $config->getCssToXpath(), $config->getValueParser());
59 66
 
@@ -67,6 +74,11 @@  discard block
 block discarded – undo
67 74
 	}
68 75
 
69 76
 	//Load the TSS
77
+
78
+	/**
79
+	 * @param Parser\CssToXpath $cssToXpath
80
+	 * @param Parser\Value $valueParser
81
+	 */
70 82
 	public function getRules($tss, $cssToXpath, $valueParser) {
71 83
 		if (is_file($tss)) {
72 84
     		//$rules = $this->cache->load($tss);
@@ -79,6 +91,10 @@  discard block
 block discarded – undo
79 91
 	}
80 92
 
81 93
 	//Process a TSS rule e.g. `ul li {content: "foo"; format: bar}
94
+
95
+	/**
96
+	 * @param Config $config
97
+	 */
82 98
 	private function executeTssRule($rule, $template, $config) {
83 99
 		$rule->touch();
84 100
 
Please login to merge, or discard this patch.
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,19 +7,19 @@  discard block
 block discarded – undo
7 7
 namespace Transphporm;
8 8
 //Separates out TSS file loading/caching from parsing
9 9
 class SheetLoader {
10
-    private $cache;
11
-    private $prefix;
12
-    private $sheet;
13
-    private $time;
14
-    private $import = [];
15
-
16
-    public function __construct(Cache $cache, FilePath $filePath, $tss, $prefix, $time) {
17
-        $this->cache = $cache;
18
-        $this->filePath = $filePath;
19
-        $this->prefix = $prefix;
20
-        $this->tss = $tss;
21
-        $this->time = $time;
22
-    }
10
+	private $cache;
11
+	private $prefix;
12
+	private $sheet;
13
+	private $time;
14
+	private $import = [];
15
+
16
+	public function __construct(Cache $cache, FilePath $filePath, $tss, $prefix, $time) {
17
+		$this->cache = $cache;
18
+		$this->filePath = $filePath;
19
+		$this->prefix = $prefix;
20
+		$this->tss = $tss;
21
+		$this->time = $time;
22
+	}
23 23
 
24 24
 	private function getRulesFromCache($file) {
25 25
 		//The cache for the key: the filename and template prefix
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 		return $file . $this->prefix . dirname(realpath($file)) . DIRECTORY_SEPARATOR;
45 45
 	}
46 46
 	//write the sheet to cache
47
-    public function write($file, $rules, $imports = []) {
47
+	public function write($file, $rules, $imports = []) {
48 48
 		if (is_file($file)) {
49 49
 			$key = $this->getCacheKey($file);
50 50
 			$existing = $this->cache->load($key, filemtime($file));
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 			$this->cache->write($key, ['rules' => $rules, 'import' => $imports]);
53 53
 		}
54 54
 		return $rules;
55
-    }
55
+	}
56 56
 
57 57
 	public function processRules($template, \Transphporm\Config $config) {
58 58
 		$rules = $this->getRules($this->tss, $config->getCssToXpath(), $config->getValueParser());
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
 	//Load the TSS
70 70
 	public function getRules($tss, $cssToXpath, $valueParser) {
71 71
 		if (is_file($tss)) {
72
-    		//$rules = $this->cache->load($tss);
73
-    		$rules = $this->getRulesFromCache($tss)['rules'];
72
+			//$rules = $this->cache->load($tss);
73
+			$rules = $this->getRulesFromCache($tss)['rules'];
74 74
 			$this->filePath->addPath(dirname(realpath($tss)));
75 75
 			if (empty($rules)) $tss = file_get_contents($tss);
76 76
 			else return $rules;
77
-    	}
77
+		}
78 78
 		return (new Parser\Sheet($tss, $cssToXpath, $valueParser, $this->filePath, $this))->parse();
79 79
 	}
80 80
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	}
42 42
 
43 43
 	private function getCacheKey($file) {
44
-		return $file . $this->prefix . dirname(realpath($file)) . DIRECTORY_SEPARATOR;
44
+		return $file.$this->prefix.dirname(realpath($file)).DIRECTORY_SEPARATOR;
45 45
 	}
46 46
 	//write the sheet to cache
47 47
     public function write($file, $rules, $imports = []) {
@@ -101,6 +101,6 @@  discard block
 block discarded – undo
101 101
 
102 102
 
103 103
 	private function sortPseudo($a, $b) {
104
-		return count($a->pseudo) < count($b->pseudo)  ? -1  :1;
104
+		return count($a->pseudo) < count($b->pseudo) ? -1 : 1;
105 105
 	}
106 106
 }
Please login to merge, or discard this patch.
Braces   +25 added lines, -9 removed lines patch added patch discarded remove patch
@@ -30,7 +30,9 @@  discard block
 block discarded – undo
30 30
 		$rules = $this->cache->load($key, filemtime($file));
31 31
 		if ($rules) {
32 32
 			foreach ($rules['import'] as $file) {
33
-				if (!$this->cache->load($this->getCacheKey($file), filemtime($file))) return false;
33
+				if (!$this->cache->load($this->getCacheKey($file), filemtime($file))) {
34
+					return false;
35
+				}
34 36
 			}
35 37
 		}
36 38
 		return $rules;
@@ -48,7 +50,9 @@  discard block
 block discarded – undo
48 50
 		if (is_file($file)) {
49 51
 			$key = $this->getCacheKey($file);
50 52
 			$existing = $this->cache->load($key, filemtime($file));
51
-			if (isset($existing['import']) && empty($imports)) $imports = $existing['import'];
53
+			if (isset($existing['import']) && empty($imports)) {
54
+				$imports = $existing['import'];
55
+			}
52 56
 			$this->cache->write($key, ['rules' => $rules, 'import' => $imports]);
53 57
 		}
54 58
 		return $rules;
@@ -60,10 +64,14 @@  discard block
 block discarded – undo
60 64
 		usort($rules, [$this, 'sortRules']);
61 65
 
62 66
 		foreach ($rules as $rule) {
63
-			if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $config);
67
+			if ($rule->shouldRun($this->time)) {
68
+				$this->executeTssRule($rule, $template, $config);
69
+			}
64 70
 		}
65 71
 
66
-		if (is_file($this->tss)) $this->write($this->tss, $rules, $this->import);
72
+		if (is_file($this->tss)) {
73
+			$this->write($this->tss, $rules, $this->import);
74
+		}
67 75
 	}
68 76
 
69 77
 	//Load the TSS
@@ -72,8 +80,11 @@  discard block
 block discarded – undo
72 80
     		//$rules = $this->cache->load($tss);
73 81
     		$rules = $this->getRulesFromCache($tss)['rules'];
74 82
 			$this->filePath->addPath(dirname(realpath($tss)));
75
-			if (empty($rules)) $tss = file_get_contents($tss);
76
-			else return $rules;
83
+			if (empty($rules)) {
84
+				$tss = file_get_contents($tss);
85
+			} else {
86
+				return $rules;
87
+			}
77 88
     	}
78 89
 		return (new Parser\Sheet($tss, $cssToXpath, $valueParser, $this->filePath, $this))->parse();
79 90
 	}
@@ -91,10 +102,15 @@  discard block
 block discarded – undo
91 102
 
92 103
 	private function sortRules($a, $b) {
93 104
 		//If they have the same depth, compare on index
94
-		if ($a->query === $b->query) return $this->sortPseudo($a, $b);
105
+		if ($a->query === $b->query) {
106
+			return $this->sortPseudo($a, $b);
107
+		}
95 108
 
96
-		if ($a->depth === $b->depth) $property = 'index';
97
-		else $property = 'depth';
109
+		if ($a->depth === $b->depth) {
110
+			$property = 'index';
111
+		} else {
112
+			$property = 'depth';
113
+		}
98 114
 
99 115
 		return ($a->$property < $b->$property) ? -1 : 1;
100 116
 	}
Please login to merge, or discard this patch.