Completed
Push — master ( a0fa0b...06252b )
by Tom
02:58
created
src/Formatter/Date.php 1 patch
Braces   +16 added lines, -6 removed lines patch added patch discarded remove patch
@@ -44,8 +44,11 @@  discard block
 block discarded – undo
44 44
 
45 45
 		$diffDays = $diff->invert === 1 ? $diff->days : 0- $diff->days;
46 46
 
47
-		if ($diffDays !== 0) return $this->dayOffset($diffDays);
48
-		else return $this->timeOffset($diff);
47
+		if ($diffDays !== 0) {
48
+			return $this->dayOffset($diffDays);
49
+		} else {
50
+			return $this->timeOffset($diff);
51
+		}
49 52
 	}
50 53
 
51 54
 	/** Calculates offset in hours/minutes/seconds */
@@ -80,15 +83,22 @@  discard block
 block discarded – undo
80 83
 			[-365, -28, $strings['future'], 28, 'months'],
81 84
 			[-999999, -365, $strings['future'], 365, 'years'],
82 85
 		];
83
-		if (isset($strings['day_before_yesterday'])) array_unshift($ranges, [2, 2, $strings['day_before_yesterday'], 1, '']);
84
-		if (isset($strings['day_after_tomorrow'])) array_unshift($ranges, [-2, -2, $strings['day_after_tomorrow'], 1, '']);
86
+		if (isset($strings['day_before_yesterday'])) {
87
+			array_unshift($ranges, [2, 2, $strings['day_before_yesterday'], 1, '']);
88
+		}
89
+		if (isset($strings['day_after_tomorrow'])) {
90
+			array_unshift($ranges, [-2, -2, $strings['day_after_tomorrow'], 1, '']);
91
+		}
85 92
 		return $ranges;
86 93
 	}
87 94
 
88 95
 	/** Converts "week" to "weeks", "month" to "months" etc when plural is required using language from $locale */
89 96
 	private function getPlural($strings, $num, $interval) {
90
-		if ($interval !== '') return $num == 1 ? $strings[$interval . '_singular'] : $strings[$interval . '_plural'];
91
-		else return '';
97
+		if ($interval !== '') {
98
+			return $num == 1 ? $strings[$interval . '_singular'] : $strings[$interval . '_plural'];
99
+		} else {
100
+			return '';
101
+		}
92 102
 	}
93 103
 
94 104
 	/** Calculates offset in days/weeks/month/years */
Please login to merge, or discard this patch.
src/Formatter/Number.php 1 patch
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,10 @@
 block discarded – undo
13 13
 
14 14
 	public function currency($num) {
15 15
 		$num = $this->decimal($num, $this->locale['currency_decimals']);
16
-		if ($this->locale['currency_position'] === 'before') return $this->locale['currency'] . $num;
17
-		else return $num . $this->locale['currency'];
16
+		if ($this->locale['currency_position'] === 'before') {
17
+			return $this->locale['currency'] . $num;
18
+		} else {
19
+			return $num . $this->locale['currency'];
20
+		}
18 21
 	}
19 22
 }
20 23
\ No newline at end of file
Please login to merge, or discard this patch.
src/Template.php 1 patch
Braces   +14 added lines, -5 removed lines patch added patch discarded remove patch
@@ -33,14 +33,18 @@  discard block
 block discarded – undo
33 33
 	/** Loops through all assigned hooks, runs the Xpath query and calls the hook */
34 34
 	private function processHooks() {
35 35
 		foreach ($this->hooks as list($query, $hook)) {
36
-			foreach ($this->xpath->query($query) as $element) $hook->run($element);
36
+			foreach ($this->xpath->query($query) as $element) {
37
+				$hook->run($element);
38
+			}
37 39
 		}
38 40
 	}
39 41
 
40 42
 	/** Prints out the current DomDocument as HTML */
41 43
 	private function printDocument(\DomDocument $doc) {
42 44
 		$output = '';
43
-		foreach ($doc->documentElement->childNodes as $node) $output .= $doc->saveXML($node, LIBXML_NOEMPTYTAG);
45
+		foreach ($doc->documentElement->childNodes as $node) {
46
+			$output .= $doc->saveXML($node, LIBXML_NOEMPTYTAG);
47
+		}
44 48
 		return $output;
45 49
 	}
46 50
 
@@ -52,13 +56,18 @@  discard block
 block discarded – undo
52 56
 		//Generate the document by taking only the childnodes of the template, ignoring the <template> and </template> tags
53 57
 		//TODO: Is there a faster way of doing this without string manipulation on the output or this loop through childnodes?
54 58
 		 //Either return a whole DomDocument or return the output HTML
55
-		if ($document) return $this->document;
59
+		if ($document) {
60
+			return $this->document;
61
+		}
56 62
 
57 63
 
58 64
 		$output = ($this->document->doctype) ? $this->document->saveXml($this->document->doctype) . "\n" : '';
59 65
 
60
-		if ($this->document->documentElement->tagName !== 'template') $output .= $this->document->saveXml($this->document->documentElement, LIBXML_NOEMPTYTAG);
61
-		else $output = $this->printDocument($this->document);
66
+		if ($this->document->documentElement->tagName !== 'template') {
67
+			$output .= $this->document->saveXml($this->document->documentElement, LIBXML_NOEMPTYTAG);
68
+		} else {
69
+			$output = $this->printDocument($this->document);
70
+		}
62 71
 
63 72
 		//repair empty tags. Browsers break on <script /> and <div /> so can't avoid LIBXML_NOEMPTYTAG but they also break on <base></base> so repair them
64 73
 		$output = str_replace(['></img>', '></br>', '></meta>', '></base>', '></link>', '></hr>', '></input>'], ' />', $output);
Please login to merge, or discard this patch.
src/Cache.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,8 @@
 block discarded – undo
20 20
 	public function load($key, $modified = 0) {
21 21
 		if (isset($this->cache[$key]) && $this->cache[$key]['timestamp'] >= $modified) {
22 22
 			return $this->cache[$key]['content'];
23
+		} else {
24
+			return false;
23 25
 		}
24
-		else return false;
25 26
 	}
26 27
 }
27 28
\ No newline at end of file
Please login to merge, or discard this patch.
src/Rule.php 1 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/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 1 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/PropertyBuilder.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,9 @@
 block discarded – undo
20 20
 		$formatter->register(new Formatter\Date($locale));
21 21
 		$formatter->register(new Formatter\StringFormatter());
22 22
 		
23
-		foreach ($formatters as $format) $formatter->register($format);
23
+		foreach ($formatters as $format) {
24
+			$formatter->register($format);
25
+		}
24 26
 
25 27
 		$this->builder->registerProperty('content', new Property\Content($data, $headers, $formatter));
26 28
 		$this->builder->registerProperty('repeat', new Property\Repeat($data));
Please login to merge, or discard this patch.
src/Builder.php 1 patch
Braces   +22 added lines, -9 removed lines patch added patch discarded remove patch
@@ -52,7 +52,9 @@  discard block
 block discarded – undo
52 52
 	private function processRules($template, $data) {
53 53
 		$valueParser = new Parser\Value($data);
54 54
 		foreach ($this->getRules($template, $valueParser) as $rule) {
55
-			if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $data, $valueParser);			
55
+			if ($rule->shouldRun($this->time)) {
56
+				$this->executeTssRule($rule, $template, $data, $valueParser);
57
+			}
56 58
 		}
57 59
 	}
58 60
 
@@ -66,7 +68,9 @@  discard block
 block discarded – undo
66 68
 	private function executeTssRule($rule, $template, $data, $valueParser) {
67 69
 		$rule->touch();
68 70
 		$hook = new Hook\PropertyHook($rule->properties, new Hook\PseudoMatcher($rule->pseudo, $data), $valueParser);
69
-		foreach ($this->registeredProperties as $name => $property) $hook->registerProperty($name, $property);
71
+		foreach ($this->registeredProperties as $name => $property) {
72
+			$hook->registerProperty($name, $property);
73
+		}
70 74
 		$template->addHook($rule->query, $hook);
71 75
 	}
72 76
 
@@ -75,8 +79,9 @@  discard block
 block discarded – undo
75 79
 		if (trim($this->template)[0] !== '<') {			
76 80
 			$xml = $this->cache->load($this->template, filemtime($this->template));
77 81
 			return $xml ? $xml : ['body' => file_get_contents($this->template), 'headers' => []];
82
+		} else {
83
+			return ['body' => $this->template, 'headers' => []];
78 84
 		}
79
-		else return ['body' => $this->template, 'headers' => []];	
80 85
 	}
81 86
 
82 87
 	//Load the TSS rules either from a file or as a string
@@ -90,10 +95,14 @@  discard block
 block discarded – undo
90 95
 			$key = $this->tss . $template->getPrefix() . $this->baseDir;
91 96
 			//Try to load the cached rules, if not set in the cache (or expired) parse the supplied sheet
92 97
 			$rules = $this->cache->load($key, filemtime($this->tss));
93
-			if (!$rules) return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse());
94
-			else return $rules;
98
+			if (!$rules) {
99
+				return $this->cache->write($key, (new Parser\Sheet(file_get_contents($this->tss), $this->baseDir, $valueParser, $template->getPrefix()))->parse());
100
+			} else {
101
+				return $rules;
102
+			}
103
+		} else {
104
+			return (new Parser\Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse();
95 105
 		}
96
-		else return (new Parser\Sheet($this->tss, $this->baseDir, $valueParser, $template->getPrefix()))->parse();
97 106
 	}
98 107
 
99 108
 	public function setCache(\ArrayAccess $cache) {
@@ -101,9 +110,13 @@  discard block
 block discarded – undo
101 110
 	}
102 111
 
103 112
 	private function getLocale() {
104
-		if (is_array($this->locale)) return $this->locale;
105
-		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);
106
-		else return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true);
113
+		if (is_array($this->locale)) {
114
+			return $this->locale;
115
+		} else if (strlen($this->locale) > 0) {
116
+			return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . $this->locale . '.json'), true);
117
+		} else {
118
+			return json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'Formatter' . DIRECTORY_SEPARATOR . 'Locale' . DIRECTORY_SEPARATOR . 'enGB.json'), true);
119
+		}
107 120
 	}
108 121
 
109 122
 	public function registerProperty($name, Property $property) {
Please login to merge, or discard this patch.