Completed
Push — master ( 0e6890...81e62d )
by Tom
02:57
created
src/Rule.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@  discard block
 block discarded – undo
10 10
 
11 11
 	const S = 1;
12 12
 	const M = 60;
13
-	const H = self::M*60;
14
-	const D = self::H*24;
13
+	const H = self::M * 60;
14
+	const D = self::H * 24;
15 15
 
16 16
 
17 17
 	public function __construct($query, $pseudo, $depth, $index, array $properties = []) {
@@ -39,9 +39,9 @@  discard block
 block discarded – undo
39 39
 		$num = (int) $frequency;
40 40
 		$unit = strtoupper(trim(str_replace($num, '', $frequency)));
41 41
 			
42
-		$offset = $num * constant(self::class . '::' . $unit);
42
+		$offset = $num * constant(self::class.'::'.$unit);
43 43
 
44
-		if ($time > $this->lastRun + $offset) return true;
44
+		if ($time > $this->lastRun+$offset) return true;
45 45
 		else return false;
46 46
 	}
47 47
 
Please login to merge, or discard this patch.
Braces   +15 added lines, -6 removed lines patch added patch discarded remove patch
@@ -35,24 +35,33 @@
 block discarded – undo
35 35
 	}
36 36
 
37 37
 	private function timeFrequency($frequency, $time = null) {
38
-		if ($time === null) $time = time();
38
+		if ($time === null) {
39
+			$time = time();
40
+		}
39 41
 		$num = (int) $frequency;
40 42
 		$unit = strtoupper(trim(str_replace($num, '', $frequency)));
41 43
 			
42 44
 		$offset = $num * constant(self::class . '::' . $unit);
43 45
 
44
-		if ($time > $this->lastRun + $offset) return true;
45
-		else return false;
46
+		if ($time > $this->lastRun + $offset) {
47
+			return true;
48
+		} else {
49
+			return false;
50
+		}
46 51
 	}
47 52
 
48 53
 	public function shouldRun($time = null) {
49 54
 		if (isset($this->properties['update-frequency']) && $this->lastRun !== 0) {
50 55
 			$frequency = $this->properties['update-frequency'];
51 56
 			$static = ['always' => true, 'never' => false];
52
-			if (isset($static[$frequency])) return $static[$frequency];
53
-			else return $this->timeFrequency($frequency, $time);
57
+			if (isset($static[$frequency])) {
58
+				return $static[$frequency];
59
+			} else {
60
+				return $this->timeFrequency($frequency, $time);
61
+			}
54 62
 
63
+		} else {
64
+			return true;
55 65
 		}
56
-		else return true;
57 66
 	}
58 67
 }
59 68
\ No newline at end of file
Please login to merge, or discard this patch.
src/Builder.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 
38 38
 		$cachedOutput = $this->loadTemplate();
39 39
 		//To be a valid XML document it must have a root element, automatically wrap it in <template> to ensure it does
40
-		$template = new Template($this->isValidDoc($cachedOutput['body']) ? $cachedOutput['body'] : '<template>' . $cachedOutput['body'] . '</template>' );
40
+		$template = new Template($this->isValidDoc($cachedOutput['body']) ? $cachedOutput['body'] : '<template>'.$cachedOutput['body'].'</template>');
41 41
 
42 42
 		//Allow $time to be set via arguments to spoof time passage during tests
43 43
 		foreach ($this->getRules($template) as $rule) {
@@ -78,11 +78,11 @@  discard block
 block discarded – undo
78 78
 	//N.b. only files can be cached
79 79
 	private function getRules($template) {		
80 80
 		if (is_file($this->tss)) {
81
-			$this->baseDir = dirname(realpath($this->tss)) . DIRECTORY_SEPARATOR;
81
+			$this->baseDir = dirname(realpath($this->tss)).DIRECTORY_SEPARATOR;
82 82
 			//The cache for the key: the filename and template prefix
83 83
 			//Each template may have a different prefix which changes the parsed TSS,
84 84
 			//Because of this the cache needs to be generated for each template prefix.
85
-			$key = $this->tss . $template->getPrefix() . $this->baseDir;
85
+			$key = $this->tss.$template->getPrefix().$this->baseDir;
86 86
 			//Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet
87 87
 			$rules = $this->cache->load($key, filemtime($this->tss));
88 88
 			if (!$rules) return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse());
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
 
108 108
 	private function getLocale() {
109 109
 		if (is_array($this->locale)) return $this->locale;
110
-		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);
111
-		else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true);
110
+		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);
111
+		else return json_decode(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'Formatter'.DIRECTORY_SEPARATOR.'Locale'.DIRECTORY_SEPARATOR.'enGB.json'), true);
112 112
 	}
113 113
 
114 114
 	public function registerProperties($object) {
Please login to merge, or discard this patch.
Braces   +25 added lines, -10 removed lines patch added patch discarded remove patch
@@ -40,7 +40,9 @@  discard block
 block discarded – undo
40 40
 
41 41
 		//Allow $time to be set via arguments to spoof time passage during tests
42 42
 		foreach ($this->getRules($template) as $rule) {
43
-			if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $data);			
43
+			if ($rule->shouldRun($this->time)) {
44
+				$this->executeTssRule($rule, $template, $data);
45
+			}
44 46
 		}
45 47
 		
46 48
 		$result = ['body' => $template->output($document), 'headers' => array_merge($cachedOutput['headers'], $headers)];
@@ -57,7 +59,9 @@  discard block
 block discarded – undo
57 59
 		$formatter->register(new Formatter\Date($locale));
58 60
 		$formatter->register(new Formatter\StringFormatter());
59 61
 		
60
-		foreach ($this->formatters as $format) $formatter->register($format);
62
+		foreach ($this->formatters as $format) {
63
+			$formatter->register($format);
64
+		}
61 65
 
62 66
 		$this->registerProperty('content', new Property\Content($data, $headers, $formatter));
63 67
 		$this->registerProperty('repeat', new Property\Repeat($data));
@@ -75,7 +79,9 @@  discard block
 block discarded – undo
75 79
 	private function executeTssRule($rule, $template, $data) {
76 80
 		$rule->touch();
77 81
 		$hook = new Hook\Rule($rule->properties, new Hook\PseudoMatcher($rule->pseudo, $data), $data);
78
-		foreach ($this->registeredProperties as $name => $property) $hook->registerProperty($name, $property);
82
+		foreach ($this->registeredProperties as $name => $property) {
83
+			$hook->registerProperty($name, $property);
84
+		}
79 85
 		$template->addHook($rule->query, $hook);
80 86
 	}
81 87
 
@@ -84,8 +90,9 @@  discard block
 block discarded – undo
84 90
 		if (trim($this->template)[0] !== '<') {			
85 91
 			$xml = $this->cache->load($this->template, filemtime($this->template));
86 92
 			return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []];
93
+		} else {
94
+			return ['body' => $this->template, 'headers' => []];
87 95
 		}
88
-		else return ['body' => $this->template, 'headers' => []];	
89 96
 	}
90 97
 
91 98
 	//Load the TSS rules either from a file or as a string
@@ -99,10 +106,14 @@  discard block
 block discarded – undo
99 106
 			$key = $this->tss . $template->getPrefix() . $this->baseDir;
100 107
 			//Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet
101 108
 			$rules = $this->cache->load($key, filemtime($this->tss));
102
-			if (!$rules) return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse());
103
-			else return $rules;
109
+			if (!$rules) {
110
+				return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse());
111
+			} else {
112
+				return $rules;
113
+			}
114
+		} else {
115
+			return (new Sheet($this->tss, $this->baseDir, $template->getPrefix()))->parse();
104 116
 		}
105
-		else return (new Sheet($this->tss, $this->baseDir, $template->getPrefix()))->parse();
106 117
 	}
107 118
 
108 119
 	public function setCache(\ArrayAccess $cache) {
@@ -110,9 +121,13 @@  discard block
 block discarded – undo
110 121
 	}
111 122
 
112 123
 	private function getLocale() {
113
-		if (is_array($this->locale)) return $this->locale;
114
-		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);
115
-		else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true);
124
+		if (is_array($this->locale)) {
125
+			return $this->locale;
126
+		} else if (strlen($this->locale) > 0) {
127
+			return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true);
128
+		} else {
129
+			return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true);
130
+		}
116 131
 	}
117 132
 
118 133
 	public function registerProperty($name, Property $property) {
Please login to merge, or discard this patch.
src/Hook/PostProcess.php 1 patch
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,8 +9,11 @@
 block discarded – undo
9 9
 class PostProcess implements \Transphporm\Hook {
10 10
 	public function run(\DomElement $element) {
11 11
 		$transphporm = $element->getAttribute('transphporm');
12
-		if ($transphporm === 'remove') $element->parentNode->removeChild($element);
13
-		else $element->removeAttribute('transphporm');
12
+		if ($transphporm === 'remove') {
13
+			$element->parentNode->removeChild($element);
14
+		} else {
15
+			$element->removeAttribute('transphporm');
16
+		}
14 17
 	}
15 18
 
16 19
 }
17 20
\ No newline at end of file
Please login to merge, or discard this patch.
src/Hook/Formatter.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -8,11 +8,15 @@
 block discarded – undo
8 8
 	}
9 9
 
10 10
 	public function format($value, $rules) {
11
-		if (!isset($rules['format'])) return $value;
11
+		if (!isset($rules['format'])) {
12
+			return $value;
13
+		}
12 14
 		$format = new \Transphporm\StringExtractor($rules['format']);
13 15
 		$options = explode(' ', $format);
14 16
 		$functionName = array_shift($options);
15
-		foreach ($options as &$f) $f = trim($format->rebuild($f), '"');
17
+		foreach ($options as &$f) {
18
+			$f = trim($format->rebuild($f), '"');
19
+		}
16 20
 
17 21
 		return $this->processFormat($options, $functionName, $value);		
18 22
 	}
Please login to merge, or discard this patch.
src/Property/Display.php 1 patch
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -7,7 +7,10 @@
 block discarded – undo
7 7
 namespace Transphporm\Property;
8 8
 class Display implements \Transphporm\Property {
9 9
 	public function run($value, \DomElement $element, \Transphporm\Hook\Rule $rule) {
10
-		if (strtolower($value[0]) === 'none') $element->setAttribute('transphporm', 'remove');
11
-		else $element->setAttribute('transphporm', 'show');
10
+		if (strtolower($value[0]) === 'none') {
11
+			$element->setAttribute('transphporm', 'remove');
12
+		} else {
13
+			$element->setAttribute('transphporm', 'show');
14
+		}
12 15
 	}
13 16
 }
14 17
\ No newline at end of file
Please login to merge, or discard this patch.
src/Property/Bind.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 		$this->data = $data;
13 13
 	}
14 14
 
15
-	public function run($value, \DomElement $element, \Transphporm\Hook\Rule $rule)  {
15
+	public function run($value, \DomElement $element, \Transphporm\Hook\Rule $rule) {
16 16
 		$this->data->bind($element, $value);
17 17
 	}
18 18
 }
19 19
\ No newline at end of file
Please login to merge, or discard this patch.
src/Property/Content.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
 
41 41
 	private function pseudoBefore($value, $element, $rule) {
42 42
 		if (in_array('before', $rule->getPseudoMatcher()->getPseudo())) {
43
-			$element->firstChild->nodeValue = implode('', $value) . $element->firstChild->nodeValue;
43
+			$element->firstChild->nodeValue = implode('', $value).$element->firstChild->nodeValue;
44 44
 			return true;
45 45
 		}
46 46
 	}
Please login to merge, or discard this patch.
Braces   +8 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,8 +22,11 @@  discard block
 block discarded – undo
22 22
 			//Remove the current contents
23 23
 			$this->removeAllChildren($element);
24 24
 			//Now make a text node
25
-			if ($this->getContentMode($rule->getRules()) === 'replace') $this->replaceContent($element, $value);
26
-			else $this->appendContent($element, $value);
25
+			if ($this->getContentMode($rule->getRules()) === 'replace') {
26
+				$this->replaceContent($element, $value);
27
+			} else {
28
+				$this->appendContent($element, $value);
29
+			}
27 30
 		}
28 31
 	}
29 32
 
@@ -88,6 +91,8 @@  discard block
 block discarded – undo
88 91
 	}
89 92
 
90 93
 	private function removeAllChildren($element) {
91
-		while ($element->hasChildNodes()) $element->removeChild($element->firstChild);
94
+		while ($element->hasChildNodes()) {
95
+			$element->removeChild($element->firstChild);
96
+		}
92 97
 	}
93 98
 }
94 99
\ No newline at end of file
Please login to merge, or discard this patch.
src/Property/Repeat.php 3 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@
 block discarded – undo
12 12
 		$this->data = $data;
13 13
 	}
14 14
 
15
-	public function run($value, \DomElement $element, \Transphporm\Hook\Rule $rule)  {
15
+	public function run($value, \DomElement $element, \Transphporm\Hook\Rule $rule) {
16 16
 		if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element);
17 17
 
18 18
 		foreach ($value as $key => $iteration) {
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,9 @@  discard block
 block discarded – undo
13 13
 	}
14 14
 
15 15
 	public function run($value, \DomElement $element, \Transphporm\Hook\Rule $rule)  {
16
-		if ($element->getAttribute('transphporm') === 'added') return $element->parentNode->removeChild($element);
16
+		if ($element->getAttribute('transphporm') === 'added') {
17
+			return $element->parentNode->removeChild($element);
18
+		}
17 19
 
18 20
 		foreach ($value as $key => $iteration) {
19 21
 			$clone = $element->cloneNode(true);
@@ -37,7 +39,9 @@  discard block
 block discarded – undo
37 39
 
38 40
 	private function createHook($newRules, $rule) {
39 41
 		$hook = new \Transphporm\Hook\Rule($newRules, $rule->getPseudoMatcher(), $this->data);
40
-		foreach ($rule->getProperties() as $name => $property) $hook->registerProperty($name, $property);
42
+		foreach ($rule->getProperties() as $name => $property) {
43
+			$hook->registerProperty($name, $property);
44
+		}
41 45
 		return $hook;
42 46
 	}
43 47
 }
44 48
\ No newline at end of file
Please login to merge, or discard this patch.
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -35,6 +35,9 @@
 block discarded – undo
35 35
 		return false;
36 36
 	}
37 37
 
38
+	/**
39
+	 * @param \Transphporm\Hook\Rule $rule
40
+	 */
38 41
 	private function createHook($newRules, $rule) {
39 42
 		$hook = new \Transphporm\Hook\Rule($newRules, $rule->getPseudoMatcher(), $this->data);
40 43
 		foreach ($rule->getProperties() as $name => $property) $hook->registerProperty($name, $property);
Please login to merge, or discard this patch.