Completed
Push — master ( 23e35e...f8660b )
by Tom
01:53
created
src/Rule.php 3 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -21,6 +21,10 @@
 block discarded – undo
21 21
 	const D = 86400;
22 22
 
23 23
 
24
+	/**
25
+	 * @param string $query
26
+	 * @param integer $depth
27
+	 */
24 28
 	public function __construct($query, $pseudo, $depth, $index, $file, $line, array $properties = []) {
25 29
 		$this->query = $query;
26 30
 		$this->pseudo = $pseudo;
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 
49 49
 		$offset = $this->getUpdateFrequency();
50 50
 
51
-		if ($time > $this->lastRun + $offset) return true;
51
+		if ($time > $this->lastRun+$offset) return true;
52 52
 		else return false;
53 53
 	}
54 54
 
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
 		$num = (int) $frequency;
71 71
 		$unit = strtoupper(trim(str_replace($num, '', $frequency)));
72 72
 		if ($frequency == 'always') return 0;
73
-		else if ($frequency == 'never') return self::D*3650; //Not quite never, in 10 years will cause issues on 32 bit PHP builds re 2038 problem
73
+		else if ($frequency == 'never') return self::D * 3650; //Not quite never, in 10 years will cause issues on 32 bit PHP builds re 2038 problem
74 74
 
75
-		return $num * constant(self::class . '::' . $unit);
75
+		return $num * constant(self::class.'::'.$unit);
76 76
 	}
77 77
 }
Please login to merge, or discard this patch.
Braces   +24 added lines, -9 removed lines patch added patch discarded remove patch
@@ -44,33 +44,48 @@
 block discarded – undo
44 44
 	}
45 45
 
46 46
 	private function timeFrequency($frequency, $time = null) {
47
-		if ($time === null) $time = time();
47
+		if ($time === null) {
48
+			$time = time();
49
+		}
48 50
 
49 51
 		$offset = $this->getUpdateFrequency();
50 52
 
51
-		if ($time > $this->lastRun + $offset) return true;
52
-		else return false;
53
+		if ($time > $this->lastRun + $offset) {
54
+			return true;
55
+		} else {
56
+			return false;
57
+		}
53 58
 	}
54 59
 
55 60
 	public function shouldRun($time = null) {
56 61
 		if (isset($this->properties['update-frequency']) && $this->lastRun !== 0) {
57 62
 			$frequency = $this->properties['update-frequency']->read();
58 63
 			$static = ['always' => true, 'never' => false];
59
-			if (isset($static[$frequency])) return $static[$frequency];
60
-			else return $this->timeFrequency($frequency, $time);
64
+			if (isset($static[$frequency])) {
65
+				return $static[$frequency];
66
+			} else {
67
+				return $this->timeFrequency($frequency, $time);
68
+			}
69
+		} else {
70
+			return true;
61 71
 		}
62
-		else return true;
63 72
 	}
64 73
 
65 74
 	public function getUpdateFrequency() {
66 75
 		$frequency = isset($this->properties['update-frequency']) ? $this->properties['update-frequency']->read() : false;
67 76
 
68
-		if (empty($frequency)) return 0;
77
+		if (empty($frequency)) {
78
+			return 0;
79
+		}
69 80
 
70 81
 		$num = (int) $frequency;
71 82
 		$unit = strtoupper(trim(str_replace($num, '', $frequency)));
72
-		if ($frequency == 'always') return 0;
73
-		else if ($frequency == 'never') return self::D*3650; //Not quite never, in 10 years will cause issues on 32 bit PHP builds re 2038 problem
83
+		if ($frequency == 'always') {
84
+			return 0;
85
+		} else if ($frequency == 'never') {
86
+			return self::D*3650;
87
+		}
88
+		//Not quite never, in 10 years will cause issues on 32 bit PHP builds re 2038 problem
74 89
 
75 90
 		return $num * constant(self::class . '::' . $unit);
76 91
 	}
Please login to merge, or discard this patch.
src/SheetLoader.php 3 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -7,17 +7,17 @@  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 $sheet;
12
-    private $time;
13
-    private $import = [];
14
-
15
-    public function __construct(Cache $cache, FilePath $filePath, $tss, $time) {
16
-        $this->cache = $cache;
17
-        $this->filePath = $filePath;
18
-        $this->tss = $tss;
19
-        $this->time = $time;
20
-    }
10
+	private $cache;
11
+	private $sheet;
12
+	private $time;
13
+	private $import = [];
14
+
15
+	public function __construct(Cache $cache, FilePath $filePath, $tss, $time) {
16
+		$this->cache = $cache;
17
+		$this->filePath = $filePath;
18
+		$this->tss = $tss;
19
+		$this->time = $time;
20
+	}
21 21
 
22 22
 	private function getRulesFromCache($file) {
23 23
 		$key = $file;
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 		return dirname(realpath($file));
72 72
 	}
73 73
 	//write the sheet to cache
74
-    public function write($file, $rules, $imports = []) {
74
+	public function write($file, $rules, $imports = []) {
75 75
 
76 76
 		if (is_file($file)) {
77 77
 			$key = $this->getCacheKey($file);
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 			$this->cache->write($file, ['rules' => $rules, 'import' => $imports, 'minFreq' => $this->getMinUpdateFreq($rules), 'ctime' => time()]);
81 81
 		}
82 82
 		return $rules;
83
-    }
83
+	}
84 84
 
85 85
 	public function processRules($template, \Transphporm\Config $config) {
86 86
 		$rules = $this->getRules($this->tss, $config->getCssToXpath(), $config->getValueParser());
@@ -97,12 +97,12 @@  discard block
 block discarded – undo
97 97
 	//Load the TSS
98 98
 	public function getRules($tss, $cssToXpath, $valueParser) {
99 99
 		if (is_file($tss)) {
100
-    		//$rules = $this->cache->load($tss);
101
-    		$rules = $this->getRulesFromCache($tss)['rules'];
100
+			//$rules = $this->cache->load($tss);
101
+			$rules = $this->getRulesFromCache($tss)['rules'];
102 102
 			$this->filePath->addPath(dirname(realpath($tss)));
103 103
 			if (empty($rules)) $tss = file_get_contents($tss);
104 104
 			else return $rules;
105
-    	}
105
+		}
106 106
 		return $tss == null ? [] : (new Parser\Sheet($tss, $cssToXpath, $valueParser, $this->filePath, $this))->parse();
107 107
 	}
108 108
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -129,6 +129,6 @@
 block discarded – undo
129 129
 
130 130
 
131 131
 	private function sortPseudo($a, $b) {
132
-		return count($a->pseudo) < count($b->pseudo)  ? -1  :1;
132
+		return count($a->pseudo) < count($b->pseudo) ? -1 : 1;
133 133
 	}
134 134
 }
Please login to merge, or discard this patch.
Braces   +34 added lines, -12 removed lines patch added patch discarded remove patch
@@ -29,7 +29,9 @@  discard block
 block discarded – undo
29 29
 		if ($rules) {
30 30
 			foreach ($rules['import'] as $file) {
31 31
 				//Check that the import file hasn't been changed since the cache was written
32
-				if (filemtime($file) > $rules['ctime']) return false;
32
+				if (filemtime($file) > $rules['ctime']) {
33
+					return false;
34
+				}
33 35
 			}
34 36
 		}
35 37
 
@@ -41,10 +43,14 @@  discard block
 block discarded – undo
41 43
 	//	 1. If all update-frequencies  haven't expired
42 44
 	//   2. If the data hasn't changed since the last run
43 45
 	public function updateRequired($data) {
44
-		if (!is_file($this->tss)) return true;
46
+		if (!is_file($this->tss)) {
47
+			return true;
48
+		}
45 49
 		$rules = $this->getRulesFromCache($this->tss);
46 50
 		//Nothing was cached or the TSS file has changed, update is required
47
-		if (empty($rules)) return true;
51
+		if (empty($rules)) {
52
+			return true;
53
+		}
48 54
 
49 55
 		//TOD: use `getMinUpdateFreq' to determne whether the rules need to be executed again
50 56
 
@@ -57,7 +63,9 @@  discard block
 block discarded – undo
57 63
 
58 64
 		foreach ($rules as $rule) {
59 65
 			$ruleFreq = $rule->getUpdateFrequency();
60
-			if ($ruleFreq < $min) $min = $ruleFreq;
66
+			if ($ruleFreq < $min) {
67
+				$min = $ruleFreq;
68
+			}
61 69
 		}
62 70
 
63 71
 		return $min;
@@ -76,7 +84,9 @@  discard block
 block discarded – undo
76 84
 		if (is_file($file)) {
77 85
 			$key = $this->getCacheKey($file);
78 86
 			$existing = $this->cache->load($key, filemtime($file));
79
-			if (isset($existing['import']) && empty($imports)) $imports = $existing['import'];
87
+			if (isset($existing['import']) && empty($imports)) {
88
+				$imports = $existing['import'];
89
+			}
80 90
 			$this->cache->write($file, ['rules' => $rules, 'import' => $imports, 'minFreq' => $this->getMinUpdateFreq($rules), 'ctime' => time()]);
81 91
 		}
82 92
 		return $rules;
@@ -88,10 +98,14 @@  discard block
 block discarded – undo
88 98
 		usort($rules, [$this, 'sortRules']);
89 99
 
90 100
 		foreach ($rules as $rule) {
91
-			if ($rule->shouldRun($this->time)) $this->executeTssRule($rule, $template, $config);
101
+			if ($rule->shouldRun($this->time)) {
102
+				$this->executeTssRule($rule, $template, $config);
103
+			}
92 104
 		}
93 105
 
94
-		if (is_file($this->tss)) $this->write($this->tss, $rules, $this->import);
106
+		if (is_file($this->tss)) {
107
+			$this->write($this->tss, $rules, $this->import);
108
+		}
95 109
 	}
96 110
 
97 111
 	//Load the TSS
@@ -100,8 +114,11 @@  discard block
 block discarded – undo
100 114
     		//$rules = $this->cache->load($tss);
101 115
     		$rules = $this->getRulesFromCache($tss)['rules'];
102 116
 			$this->filePath->addPath(dirname(realpath($tss)));
103
-			if (empty($rules)) $tss = file_get_contents($tss);
104
-			else return $rules;
117
+			if (empty($rules)) {
118
+				$tss = file_get_contents($tss);
119
+			} else {
120
+				return $rules;
121
+			}
105 122
     	}
106 123
 		return $tss == null ? [] : (new Parser\Sheet($tss, $cssToXpath, $valueParser, $this->filePath, $this))->parse();
107 124
 	}
@@ -119,10 +136,15 @@  discard block
 block discarded – undo
119 136
 
120 137
 	private function sortRules($a, $b) {
121 138
 		//If they have the same depth, compare on index
122
-		if ($a->query === $b->query) return $this->sortPseudo($a, $b);
139
+		if ($a->query === $b->query) {
140
+			return $this->sortPseudo($a, $b);
141
+		}
123 142
 
124
-		if ($a->depth === $b->depth) $property = 'index';
125
-		else $property = 'depth';
143
+		if ($a->depth === $b->depth) {
144
+			$property = 'index';
145
+		} else {
146
+			$property = 'depth';
147
+		}
126 148
 
127 149
 		return ($a->$property < $b->$property) ? -1 : 1;
128 150
 	}
Please login to merge, or discard this patch.