Completed
Push — master ( 598d1e...bd7f98 )
by Tom
02:16
created
src/SheetLoader/TSSFile.php 1 patch
Braces   +22 added lines, -8 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
 
@@ -45,10 +47,14 @@  discard block
 block discarded – undo
45 47
 
46 48
 		$rules = $this->getRulesFromCache($this->fileName, $data);
47 49
 		//Nothing was cached or the TSS file has changed, update is required
48
-		if (empty($rules)) return true;
50
+		if (empty($rules)) {
51
+			return true;
52
+		}
49 53
 
50 54
 		//Find the sheet's minimum update-frequency, if it hasn't passed then no updates are required
51
-		if ($rules['ctime']+$rules['minFreq'] <= $this->time) return true;
55
+		if ($rules['ctime']+$rules['minFreq'] <= $this->time) {
56
+			return true;
57
+		}
52 58
 
53 59
 		return false;
54 60
 	}
@@ -60,15 +66,19 @@  discard block
 block discarded – undo
60 66
 			$x= $parser->parseTokens($this->cacheKey)[0];
61 67
 			$this->cacheName = $x . $this->tss;
62 68
 			return $x;
69
+		} else {
70
+			return '';
63 71
 		}
64
-		else return '';
65 72
 	}
66 73
 
67 74
 	public function getRules($cssToXpath, $valueParser, $sheetLoader, $indexStart) {
68 75
 		$rules = $this->getRulesFromCache($this->fileName)['rules'];
69 76
 		$this->filePath->addPath(dirname(realpath($this->fileName)));
70
-		if (empty($rules)) $tss = file_get_contents($this->fileName);
71
-		else return $rules;
77
+		if (empty($rules)) {
78
+			$tss = file_get_contents($this->fileName);
79
+		} else {
80
+			return $rules;
81
+		}
72 82
 
73 83
 		return $tss == null ? [] : (new \Transphporm\Parser\Sheet($tss, $cssToXpath, $valueParser, $this->filePath, $sheetLoader))->parse($indexStart);
74 84
 	}
@@ -76,7 +86,9 @@  discard block
 block discarded – undo
76 86
 	//write the sheet to cache
77 87
     public function write($rules, $imports = []) {
78 88
 		$existing = $this->cache->load($this->fileName, filemtime($this->fileName));
79
-		if (isset($existing['import']) && empty($imports)) $imports = $existing['import'];
89
+		if (isset($existing['import']) && empty($imports)) {
90
+			$imports = $existing['import'];
91
+		}
80 92
 		$this->cache->write($this->cacheName, ['rules' => $rules, 'import' => $imports, 'minFreq' => $this->getMinUpdateFreq($rules), 'ctime' => $this->time, 'cacheKey' => $this->cacheKey]);
81 93
 
82 94
 		return $rules;
@@ -88,7 +100,9 @@  discard block
 block discarded – undo
88 100
 
89 101
 		foreach ($rules as $rule) {
90 102
 			$ruleFreq = $rule->getUpdateFrequency();
91
-			if ($ruleFreq < $min) $min = $ruleFreq;
103
+			if ($ruleFreq < $min) {
104
+				$min = $ruleFreq;
105
+			}
92 106
 		}
93 107
 
94 108
 		return $min;
Please login to merge, or discard this patch.
src/Rule.php 1 patch
Braces   +26 added lines, -10 removed lines patch added patch discarded remove patch
@@ -44,36 +44,52 @@
 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;
69
-		else return $this->calcUpdateFrequency($frequency);
77
+		if (empty($frequency)) {
78
+			return 0;
79
+		} else {
80
+			return $this->calcUpdateFrequency($frequency);
81
+		}
70 82
 	}
71 83
 
72 84
 	private function calcUpdateFrequency($frequency) {
73 85
 		$num = (int) $frequency;
74 86
 		$unit = strtoupper(trim(str_replace($num, '', $frequency)));
75
-		if ($frequency == 'always') return 0;
76
-		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
87
+		if ($frequency == 'always') {
88
+			return 0;
89
+		} else if ($frequency == 'never') {
90
+			return self::D*3650;
91
+		}
92
+		//Not quite never, in 10 years will cause issues on 32 bit PHP builds re 2038 problem
77 93
 
78 94
 		return $num * constant(self::class . '::' . $unit);
79 95
 	}
Please login to merge, or discard this patch.