Completed
Push — master ( be6b9d...0e6890 )
by Tom
03:08
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
@@ -43,7 +43,9 @@  discard block
 block discarded – undo
43 43
 
44 44
 		//Allow $time to be set via arguments to spoof time passage during tests
45 45
 		foreach ($this->getRules($template) as $rule) {
46
-			if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $data);			
46
+			if ($rule->shouldRun($this->time)) {
47
+				$this->executeTssRule($rule, $template, $data);
48
+			}
47 49
 		}
48 50
 		
49 51
 		$result = ['body' => $template->output($document), 'headers' => array_merge($cachedOutput['headers'], $headers)];
@@ -63,7 +65,9 @@  discard block
 block discarded – undo
63 65
 	private function executeTssRule($rule, $template, $data) {
64 66
 		$rule->touch();
65 67
 		$hook = new Hook\Rule($rule->properties, new Hook\PseudoMatcher($rule->pseudo, $data), $data);
66
-		foreach ($this->registeredProperties as $name => $property) $hook->registerProperty($name, $property);
68
+		foreach ($this->registeredProperties as $name => $property) {
69
+			$hook->registerProperty($name, $property);
70
+		}
67 71
 		$template->addHook($rule->query, $hook);
68 72
 	}
69 73
 
@@ -72,8 +76,9 @@  discard block
 block discarded – undo
72 76
 		if (trim($this->template)[0] !== '<') {			
73 77
 			$xml = $this->cache->load($this->template, filemtime($this->template));
74 78
 			return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []];
79
+		} else {
80
+			return ['body' => $this->template, 'headers' => []];
75 81
 		}
76
-		else return ['body' => $this->template, 'headers' => []];	
77 82
 	}
78 83
 
79 84
 	//Load the TSS rules either from a file or as a string
@@ -87,10 +92,14 @@  discard block
 block discarded – undo
87 92
 			$key = $this->tss . $template->getPrefix() . $this->baseDir;
88 93
 			//Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet
89 94
 			$rules = $this->cache->load($key, filemtime($this->tss));
90
-			if (!$rules) return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse());
91
-			else return $rules;
95
+			if (!$rules) {
96
+				return $this->cache->write($key, (new Sheet(file_get_contents($this->tss), $this->baseDir, $template->getPrefix()))->parse());
97
+			} else {
98
+				return $rules;
99
+			}
100
+		} else {
101
+			return (new Sheet($this->tss, $this->baseDir, $template->getPrefix()))->parse();
92 102
 		}
93
-		else return (new Sheet($this->tss, $this->baseDir, $template->getPrefix()))->parse();
94 103
 	}
95 104
 
96 105
 	private function getContentProperty($data, $locale, &$headers) {
@@ -99,7 +108,9 @@  discard block
 block discarded – undo
99 108
 		$formatter->register(new Formatter\Date($locale));
100 109
 		$formatter->register(new Formatter\StringFormatter());
101 110
 		
102
-		foreach ($this->formatters as $format) $formatter->register($format);
111
+		foreach ($this->formatters as $format) {
112
+			$formatter->register($format);
113
+		}
103 114
 
104 115
 		$basicProperties = new Property\Content($data, $headers, $formatter);
105 116
 
@@ -111,9 +122,13 @@  discard block
 block discarded – undo
111 122
 	}
112 123
 
113 124
 	private function getLocale() {
114
-		if (is_array($this->locale)) return $this->locale;
115
-		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);
116
-		else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true);
125
+		if (is_array($this->locale)) {
126
+			return $this->locale;
127
+		} else if (strlen($this->locale) > 0) {
128
+			return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true);
129
+		} else {
130
+			return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true);
131
+		}
117 132
 	}
118 133
 
119 134
 	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/Repeat.php 3 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -8,6 +8,9 @@  discard block
 block discarded – undo
8 8
 class Repeat implements \Transphporm\Property {
9 9
 	private $data;
10 10
 
11
+	/**
12
+	 * @param \Transphporm\Hook\DataFunction $data
13
+	 */
11 14
 	public function __construct($data) {
12 15
 		$this->data = $data;
13 16
 	}
@@ -35,6 +38,9 @@  discard block
 block discarded – undo
35 38
 		return false;
36 39
 	}
37 40
 
41
+	/**
42
+	 * @param \Transphporm\Hook\Rule $rule
43
+	 */
38 44
 	private function createHook($newRules, $rule) {
39 45
 		$hook = new \Transphporm\Hook\Rule($newRules, $rule->getPseudoMatcher(), $this->data);
40 46
 		foreach ($rule->getProperties() as $name => $property) $hook->registerProperty($name, $property);
Please login to merge, or discard this 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
 		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.
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.