Completed
Pull Request — master (#7631)
by John
22:50
created
lib/private/Template/SCSSCacher.php 2 patches
Indentation   +278 added lines, -278 removed lines patch added patch discarded remove patch
@@ -45,282 +45,282 @@
 block discarded – undo
45 45
 
46 46
 class SCSSCacher {
47 47
 
48
-	/** @var ILogger */
49
-	protected $logger;
50
-
51
-	/** @var IAppData */
52
-	protected $appData;
53
-
54
-	/** @var IURLGenerator */
55
-	protected $urlGenerator;
56
-
57
-	/** @var IConfig */
58
-	protected $config;
59
-
60
-	/** @var string */
61
-	protected $serverRoot;
62
-
63
-	/** @var ICache */
64
-	protected $depsCache;
65
-
66
-	/**
67
-	 * @param ILogger $logger
68
-	 * @param Factory $appDataFactory
69
-	 * @param IURLGenerator $urlGenerator
70
-	 * @param IConfig $config
71
-	 * @param \OC_Defaults $defaults
72
-	 * @param string $serverRoot
73
-	 * @param ICache $depsCache
74
-	 */
75
-	public function __construct(ILogger $logger,
76
-								Factory $appDataFactory,
77
-								IURLGenerator $urlGenerator,
78
-								IConfig $config,
79
-								\OC_Defaults $defaults,
80
-								$serverRoot,
81
-								ICache $depsCache) {
82
-		$this->logger = $logger;
83
-		$this->appData = $appDataFactory->get('css');
84
-		$this->urlGenerator = $urlGenerator;
85
-		$this->config = $config;
86
-		$this->defaults = $defaults;
87
-		$this->serverRoot = $serverRoot;
88
-		$this->depsCache = $depsCache;
89
-	}
90
-
91
-	/**
92
-	 * Process the caching process if needed
93
-	 * @param string $root Root path to the nextcloud installation
94
-	 * @param string $file
95
-	 * @param string $app The app name
96
-	 * @return boolean
97
-	 */
98
-	public function process($root, $file, $app) {
99
-		$path = explode('/', $root . '/' . $file);
100
-
101
-		$fileNameSCSS = array_pop($path);
102
-		$fileNameCSS = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS));
103
-
104
-		$path = implode('/', $path);
105
-		$webDir = $this->getWebDir($path, $app);
106
-
107
-		try {
108
-			$folder = $this->appData->getFolder($app);
109
-		} catch(NotFoundException $e) {
110
-			// creating css appdata folder
111
-			$folder = $this->appData->newFolder($app);
112
-		}
113
-
114
-
115
-		if(!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) {
116
-			return true;
117
-		}
118
-		return $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir);
119
-	}
120
-
121
-	/**
122
-	 * @param $appName
123
-	 * @param $fileName
124
-	 * @return ISimpleFile
125
-	 */
126
-	public function getCachedCSS($appName, $fileName) {
127
-		$folder = $this->appData->getFolder($appName);
128
-		return $folder->getFile($this->prependBaseurlPrefix($fileName));
129
-	}
130
-
131
-	/**
132
-	 * Check if the file is cached or not
133
-	 * @param string $fileNameCSS
134
-	 * @param ISimpleFolder $folder
135
-	 * @return boolean
136
-	 */
137
-	private function isCached($fileNameCSS, ISimpleFolder $folder) {
138
-		try {
139
-			$cachedFile = $folder->getFile($fileNameCSS);
140
-			if ($cachedFile->getSize() > 0) {
141
-				$depFileName = $fileNameCSS . '.deps';
142
-				$deps = $this->depsCache->get($folder->getName() . '-' . $depFileName);
143
-				if ($deps === null) {
144
-					$depFile = $folder->getFile($depFileName);
145
-					$deps = $depFile->getContent();
146
-					//Set to memcache for next run
147
-					$this->depsCache->set($folder->getName() . '-' . $depFileName, $deps);
148
-				}
149
-				$deps = json_decode($deps, true);
150
-
151
-				foreach ($deps as $file=>$mtime) {
152
-					if (!file_exists($file) || filemtime($file) > $mtime) {
153
-						return false;
154
-					}
155
-				}
156
-			}
157
-			return true;
158
-		} catch(NotFoundException $e) {
159
-			return false;
160
-		}
161
-	}
162
-
163
-	/**
164
-	 * Check if the variables file has changed
165
-	 * @return bool
166
-	 */
167
-	private function variablesChanged() {
168
-		$injectedVariables = $this->getInjectedVariables();
169
-		if($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) {
170
-			$this->resetCache();
171
-			$this->config->setAppValue('core', 'scss.variables', md5($injectedVariables));
172
-			return true;
173
-		}
174
-		return false;
175
-	}
176
-
177
-	/**
178
-	 * Cache the file with AppData
179
-	 * @param string $path
180
-	 * @param string $fileNameCSS
181
-	 * @param string $fileNameSCSS
182
-	 * @param ISimpleFolder $folder
183
-	 * @param string $webDir
184
-	 * @return boolean
185
-	 */
186
-	private function cache($path, $fileNameCSS, $fileNameSCSS, ISimpleFolder $folder, $webDir) {
187
-		$scss = new Compiler();
188
-		$scss->setImportPaths([
189
-			$path,
190
-			\OC::$SERVERROOT . '/core/css/',
191
-		]);
192
-		// Continue after throw
193
-		$scss->setIgnoreErrors(true);
194
-		if($this->config->getSystemValue('debug')) {
195
-			// Debug mode
196
-			$scss->setFormatter(Expanded::class);
197
-			$scss->setLineNumberStyle(Compiler::LINE_COMMENTS);
198
-		} else {
199
-			// Compression
200
-			$scss->setFormatter(Crunched::class);
201
-		}
202
-
203
-		try {
204
-			$cachedfile = $folder->getFile($fileNameCSS);
205
-		} catch(NotFoundException $e) {
206
-			$cachedfile = $folder->newFile($fileNameCSS);
207
-		}
208
-
209
-		$depFileName = $fileNameCSS . '.deps';
210
-		try {
211
-			$depFile = $folder->getFile($depFileName);
212
-		} catch (NotFoundException $e) {
213
-			$depFile = $folder->newFile($depFileName);
214
-		}
215
-
216
-		// Compile
217
-		try {
218
-			$compiledScss = $scss->compile(
219
-				'@import "variables.scss";' .
220
-				$this->getInjectedVariables() .
221
-				'@import "'.$fileNameSCSS.'";');
222
-		} catch(ParserException $e) {
223
-			$this->logger->error($e, ['app' => 'core']);
224
-			return false;
225
-		}
226
-
227
-		// Gzip file
228
-		try {
229
-			$gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz
230
-		} catch (NotFoundException $e) {
231
-			$gzipFile = $folder->newFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz
232
-		}
233
-
234
-		try {
235
-			$data = $this->rebaseUrls($compiledScss, $webDir);
236
-			$cachedfile->putContent($data);
237
-			$deps = json_encode($scss->getParsedFiles());
238
-			$depFile->putContent($deps);
239
-			$this->depsCache->set($folder->getName() . '-' . $depFileName, $deps);
240
-			$gzipFile->putContent(gzencode($data, 9));
241
-			$this->logger->debug($webDir.'/'.$fileNameSCSS.' compiled and successfully cached', ['app' => 'core']);
242
-			return true;
243
-		} catch(NotPermittedException $e) {
244
-			return false;
245
-		}
246
-	}
247
-
248
-	/**
249
-	 * Reset scss cache by deleting all generated css files
250
-	 * We need to regenerate all files when variables change
251
-	 */
252
-	private function resetCache() {
253
-		$appDirectory = $this->appData->getDirectoryListing();
254
-		if(empty($appDirectory)){
255
-			return;
256
-		}
257
-		foreach ($appDirectory as $folder) {
258
-			foreach ($folder->getDirectoryListing() as $file) {
259
-				if (substr($file->getName(), -3) === "css" || substr($file->getName(), -4) === "deps") {
260
-					$file->delete();
261
-				}
262
-			}
263
-		}
264
-	}
265
-
266
-	/**
267
-	 * @return string SCSS code for variables from OC_Defaults
268
-	 */
269
-	private function getInjectedVariables() {
270
-		$variables = '';
271
-		foreach ($this->defaults->getScssVariables() as $key => $value) {
272
-			$variables .= '$' . $key . ': ' . $value . ';';
273
-		}
274
-		return $variables;
275
-	}
276
-
277
-	/**
278
-	 * Add the correct uri prefix to make uri valid again
279
-	 * @param string $css
280
-	 * @param string $webDir
281
-	 * @return string
282
-	 */
283
-	private function rebaseUrls($css, $webDir) {
284
-		$re = '/url\([\'"]([\.\w?=\/-]*)[\'"]\)/x';
285
-		$subst = 'url(\''.$webDir.'/$1\')';
286
-		return preg_replace($re, $subst, $css);
287
-	}
288
-
289
-	/**
290
-	 * Return the cached css file uri
291
-	 * @param string $appName the app name
292
-	 * @param string $fileName
293
-	 * @return string
294
-	 */
295
-	public function getCachedSCSS($appName, $fileName) {
296
-		$tmpfileLoc = explode('/', $fileName);
297
-		$fileName = array_pop($tmpfileLoc);
298
-		$fileName = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileName));
299
-
300
-		return substr($this->urlGenerator->linkToRoute('core.Css.getCss', array('fileName' => $fileName, 'appName' => $appName)), strlen(\OC::$WEBROOT) + 1);
301
-	}
302
-
303
-	/**
304
-	 * Prepend hashed base url to the css file
305
-	 * @param $cssFile
306
-	 * @return string
307
-	 */
308
-	private function prependBaseurlPrefix($cssFile) {
309
-		$frontendController = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');
310
-		return substr(md5($this->urlGenerator->getBaseUrl() . $frontendController), 0, 8) . '-' . $cssFile;
311
-	}
312
-
313
-	/**
314
-	 * Get WebDir root
315
-	 * @param string $path the css file path
316
-	 * @param string $app the app name
317
-	 * @return string the webDir
318
-	 */
319
-	private function getWebDir($path, $app) {
320
-		// Detect if path is within an app path
321
-		if($appWebPath = \OC_App::getAppWebPath($app)) {
322
-			return substr($path, strpos($path, $appWebPath));
323
-		}
324
-		return substr($path, strlen($this->serverRoot));
325
-	}
48
+    /** @var ILogger */
49
+    protected $logger;
50
+
51
+    /** @var IAppData */
52
+    protected $appData;
53
+
54
+    /** @var IURLGenerator */
55
+    protected $urlGenerator;
56
+
57
+    /** @var IConfig */
58
+    protected $config;
59
+
60
+    /** @var string */
61
+    protected $serverRoot;
62
+
63
+    /** @var ICache */
64
+    protected $depsCache;
65
+
66
+    /**
67
+     * @param ILogger $logger
68
+     * @param Factory $appDataFactory
69
+     * @param IURLGenerator $urlGenerator
70
+     * @param IConfig $config
71
+     * @param \OC_Defaults $defaults
72
+     * @param string $serverRoot
73
+     * @param ICache $depsCache
74
+     */
75
+    public function __construct(ILogger $logger,
76
+                                Factory $appDataFactory,
77
+                                IURLGenerator $urlGenerator,
78
+                                IConfig $config,
79
+                                \OC_Defaults $defaults,
80
+                                $serverRoot,
81
+                                ICache $depsCache) {
82
+        $this->logger = $logger;
83
+        $this->appData = $appDataFactory->get('css');
84
+        $this->urlGenerator = $urlGenerator;
85
+        $this->config = $config;
86
+        $this->defaults = $defaults;
87
+        $this->serverRoot = $serverRoot;
88
+        $this->depsCache = $depsCache;
89
+    }
90
+
91
+    /**
92
+     * Process the caching process if needed
93
+     * @param string $root Root path to the nextcloud installation
94
+     * @param string $file
95
+     * @param string $app The app name
96
+     * @return boolean
97
+     */
98
+    public function process($root, $file, $app) {
99
+        $path = explode('/', $root . '/' . $file);
100
+
101
+        $fileNameSCSS = array_pop($path);
102
+        $fileNameCSS = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS));
103
+
104
+        $path = implode('/', $path);
105
+        $webDir = $this->getWebDir($path, $app);
106
+
107
+        try {
108
+            $folder = $this->appData->getFolder($app);
109
+        } catch(NotFoundException $e) {
110
+            // creating css appdata folder
111
+            $folder = $this->appData->newFolder($app);
112
+        }
113
+
114
+
115
+        if(!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) {
116
+            return true;
117
+        }
118
+        return $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir);
119
+    }
120
+
121
+    /**
122
+     * @param $appName
123
+     * @param $fileName
124
+     * @return ISimpleFile
125
+     */
126
+    public function getCachedCSS($appName, $fileName) {
127
+        $folder = $this->appData->getFolder($appName);
128
+        return $folder->getFile($this->prependBaseurlPrefix($fileName));
129
+    }
130
+
131
+    /**
132
+     * Check if the file is cached or not
133
+     * @param string $fileNameCSS
134
+     * @param ISimpleFolder $folder
135
+     * @return boolean
136
+     */
137
+    private function isCached($fileNameCSS, ISimpleFolder $folder) {
138
+        try {
139
+            $cachedFile = $folder->getFile($fileNameCSS);
140
+            if ($cachedFile->getSize() > 0) {
141
+                $depFileName = $fileNameCSS . '.deps';
142
+                $deps = $this->depsCache->get($folder->getName() . '-' . $depFileName);
143
+                if ($deps === null) {
144
+                    $depFile = $folder->getFile($depFileName);
145
+                    $deps = $depFile->getContent();
146
+                    //Set to memcache for next run
147
+                    $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps);
148
+                }
149
+                $deps = json_decode($deps, true);
150
+
151
+                foreach ($deps as $file=>$mtime) {
152
+                    if (!file_exists($file) || filemtime($file) > $mtime) {
153
+                        return false;
154
+                    }
155
+                }
156
+            }
157
+            return true;
158
+        } catch(NotFoundException $e) {
159
+            return false;
160
+        }
161
+    }
162
+
163
+    /**
164
+     * Check if the variables file has changed
165
+     * @return bool
166
+     */
167
+    private function variablesChanged() {
168
+        $injectedVariables = $this->getInjectedVariables();
169
+        if($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) {
170
+            $this->resetCache();
171
+            $this->config->setAppValue('core', 'scss.variables', md5($injectedVariables));
172
+            return true;
173
+        }
174
+        return false;
175
+    }
176
+
177
+    /**
178
+     * Cache the file with AppData
179
+     * @param string $path
180
+     * @param string $fileNameCSS
181
+     * @param string $fileNameSCSS
182
+     * @param ISimpleFolder $folder
183
+     * @param string $webDir
184
+     * @return boolean
185
+     */
186
+    private function cache($path, $fileNameCSS, $fileNameSCSS, ISimpleFolder $folder, $webDir) {
187
+        $scss = new Compiler();
188
+        $scss->setImportPaths([
189
+            $path,
190
+            \OC::$SERVERROOT . '/core/css/',
191
+        ]);
192
+        // Continue after throw
193
+        $scss->setIgnoreErrors(true);
194
+        if($this->config->getSystemValue('debug')) {
195
+            // Debug mode
196
+            $scss->setFormatter(Expanded::class);
197
+            $scss->setLineNumberStyle(Compiler::LINE_COMMENTS);
198
+        } else {
199
+            // Compression
200
+            $scss->setFormatter(Crunched::class);
201
+        }
202
+
203
+        try {
204
+            $cachedfile = $folder->getFile($fileNameCSS);
205
+        } catch(NotFoundException $e) {
206
+            $cachedfile = $folder->newFile($fileNameCSS);
207
+        }
208
+
209
+        $depFileName = $fileNameCSS . '.deps';
210
+        try {
211
+            $depFile = $folder->getFile($depFileName);
212
+        } catch (NotFoundException $e) {
213
+            $depFile = $folder->newFile($depFileName);
214
+        }
215
+
216
+        // Compile
217
+        try {
218
+            $compiledScss = $scss->compile(
219
+                '@import "variables.scss";' .
220
+                $this->getInjectedVariables() .
221
+                '@import "'.$fileNameSCSS.'";');
222
+        } catch(ParserException $e) {
223
+            $this->logger->error($e, ['app' => 'core']);
224
+            return false;
225
+        }
226
+
227
+        // Gzip file
228
+        try {
229
+            $gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz
230
+        } catch (NotFoundException $e) {
231
+            $gzipFile = $folder->newFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz
232
+        }
233
+
234
+        try {
235
+            $data = $this->rebaseUrls($compiledScss, $webDir);
236
+            $cachedfile->putContent($data);
237
+            $deps = json_encode($scss->getParsedFiles());
238
+            $depFile->putContent($deps);
239
+            $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps);
240
+            $gzipFile->putContent(gzencode($data, 9));
241
+            $this->logger->debug($webDir.'/'.$fileNameSCSS.' compiled and successfully cached', ['app' => 'core']);
242
+            return true;
243
+        } catch(NotPermittedException $e) {
244
+            return false;
245
+        }
246
+    }
247
+
248
+    /**
249
+     * Reset scss cache by deleting all generated css files
250
+     * We need to regenerate all files when variables change
251
+     */
252
+    private function resetCache() {
253
+        $appDirectory = $this->appData->getDirectoryListing();
254
+        if(empty($appDirectory)){
255
+            return;
256
+        }
257
+        foreach ($appDirectory as $folder) {
258
+            foreach ($folder->getDirectoryListing() as $file) {
259
+                if (substr($file->getName(), -3) === "css" || substr($file->getName(), -4) === "deps") {
260
+                    $file->delete();
261
+                }
262
+            }
263
+        }
264
+    }
265
+
266
+    /**
267
+     * @return string SCSS code for variables from OC_Defaults
268
+     */
269
+    private function getInjectedVariables() {
270
+        $variables = '';
271
+        foreach ($this->defaults->getScssVariables() as $key => $value) {
272
+            $variables .= '$' . $key . ': ' . $value . ';';
273
+        }
274
+        return $variables;
275
+    }
276
+
277
+    /**
278
+     * Add the correct uri prefix to make uri valid again
279
+     * @param string $css
280
+     * @param string $webDir
281
+     * @return string
282
+     */
283
+    private function rebaseUrls($css, $webDir) {
284
+        $re = '/url\([\'"]([\.\w?=\/-]*)[\'"]\)/x';
285
+        $subst = 'url(\''.$webDir.'/$1\')';
286
+        return preg_replace($re, $subst, $css);
287
+    }
288
+
289
+    /**
290
+     * Return the cached css file uri
291
+     * @param string $appName the app name
292
+     * @param string $fileName
293
+     * @return string
294
+     */
295
+    public function getCachedSCSS($appName, $fileName) {
296
+        $tmpfileLoc = explode('/', $fileName);
297
+        $fileName = array_pop($tmpfileLoc);
298
+        $fileName = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileName));
299
+
300
+        return substr($this->urlGenerator->linkToRoute('core.Css.getCss', array('fileName' => $fileName, 'appName' => $appName)), strlen(\OC::$WEBROOT) + 1);
301
+    }
302
+
303
+    /**
304
+     * Prepend hashed base url to the css file
305
+     * @param $cssFile
306
+     * @return string
307
+     */
308
+    private function prependBaseurlPrefix($cssFile) {
309
+        $frontendController = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');
310
+        return substr(md5($this->urlGenerator->getBaseUrl() . $frontendController), 0, 8) . '-' . $cssFile;
311
+    }
312
+
313
+    /**
314
+     * Get WebDir root
315
+     * @param string $path the css file path
316
+     * @param string $app the app name
317
+     * @return string the webDir
318
+     */
319
+    private function getWebDir($path, $app) {
320
+        // Detect if path is within an app path
321
+        if($appWebPath = \OC_App::getAppWebPath($app)) {
322
+            return substr($path, strpos($path, $appWebPath));
323
+        }
324
+        return substr($path, strlen($this->serverRoot));
325
+    }
326 326
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 * @return boolean
97 97
 	 */
98 98
 	public function process($root, $file, $app) {
99
-		$path = explode('/', $root . '/' . $file);
99
+		$path = explode('/', $root.'/'.$file);
100 100
 
101 101
 		$fileNameSCSS = array_pop($path);
102 102
 		$fileNameCSS = $this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS));
@@ -106,13 +106,13 @@  discard block
 block discarded – undo
106 106
 
107 107
 		try {
108 108
 			$folder = $this->appData->getFolder($app);
109
-		} catch(NotFoundException $e) {
109
+		} catch (NotFoundException $e) {
110 110
 			// creating css appdata folder
111 111
 			$folder = $this->appData->newFolder($app);
112 112
 		}
113 113
 
114 114
 
115
-		if(!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) {
115
+		if (!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) {
116 116
 			return true;
117 117
 		}
118 118
 		return $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir);
@@ -138,13 +138,13 @@  discard block
 block discarded – undo
138 138
 		try {
139 139
 			$cachedFile = $folder->getFile($fileNameCSS);
140 140
 			if ($cachedFile->getSize() > 0) {
141
-				$depFileName = $fileNameCSS . '.deps';
142
-				$deps = $this->depsCache->get($folder->getName() . '-' . $depFileName);
141
+				$depFileName = $fileNameCSS.'.deps';
142
+				$deps = $this->depsCache->get($folder->getName().'-'.$depFileName);
143 143
 				if ($deps === null) {
144 144
 					$depFile = $folder->getFile($depFileName);
145 145
 					$deps = $depFile->getContent();
146 146
 					//Set to memcache for next run
147
-					$this->depsCache->set($folder->getName() . '-' . $depFileName, $deps);
147
+					$this->depsCache->set($folder->getName().'-'.$depFileName, $deps);
148 148
 				}
149 149
 				$deps = json_decode($deps, true);
150 150
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 				}
156 156
 			}
157 157
 			return true;
158
-		} catch(NotFoundException $e) {
158
+		} catch (NotFoundException $e) {
159 159
 			return false;
160 160
 		}
161 161
 	}
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 	 */
167 167
 	private function variablesChanged() {
168 168
 		$injectedVariables = $this->getInjectedVariables();
169
-		if($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) {
169
+		if ($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) {
170 170
 			$this->resetCache();
171 171
 			$this->config->setAppValue('core', 'scss.variables', md5($injectedVariables));
172 172
 			return true;
@@ -187,11 +187,11 @@  discard block
 block discarded – undo
187 187
 		$scss = new Compiler();
188 188
 		$scss->setImportPaths([
189 189
 			$path,
190
-			\OC::$SERVERROOT . '/core/css/',
190
+			\OC::$SERVERROOT.'/core/css/',
191 191
 		]);
192 192
 		// Continue after throw
193 193
 		$scss->setIgnoreErrors(true);
194
-		if($this->config->getSystemValue('debug')) {
194
+		if ($this->config->getSystemValue('debug')) {
195 195
 			// Debug mode
196 196
 			$scss->setFormatter(Expanded::class);
197 197
 			$scss->setLineNumberStyle(Compiler::LINE_COMMENTS);
@@ -202,11 +202,11 @@  discard block
 block discarded – undo
202 202
 
203 203
 		try {
204 204
 			$cachedfile = $folder->getFile($fileNameCSS);
205
-		} catch(NotFoundException $e) {
205
+		} catch (NotFoundException $e) {
206 206
 			$cachedfile = $folder->newFile($fileNameCSS);
207 207
 		}
208 208
 
209
-		$depFileName = $fileNameCSS . '.deps';
209
+		$depFileName = $fileNameCSS.'.deps';
210 210
 		try {
211 211
 			$depFile = $folder->getFile($depFileName);
212 212
 		} catch (NotFoundException $e) {
@@ -216,19 +216,19 @@  discard block
 block discarded – undo
216 216
 		// Compile
217 217
 		try {
218 218
 			$compiledScss = $scss->compile(
219
-				'@import "variables.scss";' .
220
-				$this->getInjectedVariables() .
219
+				'@import "variables.scss";'.
220
+				$this->getInjectedVariables().
221 221
 				'@import "'.$fileNameSCSS.'";');
222
-		} catch(ParserException $e) {
222
+		} catch (ParserException $e) {
223 223
 			$this->logger->error($e, ['app' => 'core']);
224 224
 			return false;
225 225
 		}
226 226
 
227 227
 		// Gzip file
228 228
 		try {
229
-			$gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz
229
+			$gzipFile = $folder->getFile($fileNameCSS.'.gzip'); # Safari doesn't like .gz
230 230
 		} catch (NotFoundException $e) {
231
-			$gzipFile = $folder->newFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz
231
+			$gzipFile = $folder->newFile($fileNameCSS.'.gzip'); # Safari doesn't like .gz
232 232
 		}
233 233
 
234 234
 		try {
@@ -236,11 +236,11 @@  discard block
 block discarded – undo
236 236
 			$cachedfile->putContent($data);
237 237
 			$deps = json_encode($scss->getParsedFiles());
238 238
 			$depFile->putContent($deps);
239
-			$this->depsCache->set($folder->getName() . '-' . $depFileName, $deps);
239
+			$this->depsCache->set($folder->getName().'-'.$depFileName, $deps);
240 240
 			$gzipFile->putContent(gzencode($data, 9));
241 241
 			$this->logger->debug($webDir.'/'.$fileNameSCSS.' compiled and successfully cached', ['app' => 'core']);
242 242
 			return true;
243
-		} catch(NotPermittedException $e) {
243
+		} catch (NotPermittedException $e) {
244 244
 			return false;
245 245
 		}
246 246
 	}
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	 */
252 252
 	private function resetCache() {
253 253
 		$appDirectory = $this->appData->getDirectoryListing();
254
-		if(empty($appDirectory)){
254
+		if (empty($appDirectory)) {
255 255
 			return;
256 256
 		}
257 257
 		foreach ($appDirectory as $folder) {
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 	private function getInjectedVariables() {
270 270
 		$variables = '';
271 271
 		foreach ($this->defaults->getScssVariables() as $key => $value) {
272
-			$variables .= '$' . $key . ': ' . $value . ';';
272
+			$variables .= '$'.$key.': '.$value.';';
273 273
 		}
274 274
 		return $variables;
275 275
 	}
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 	 */
308 308
 	private function prependBaseurlPrefix($cssFile) {
309 309
 		$frontendController = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');
310
-		return substr(md5($this->urlGenerator->getBaseUrl() . $frontendController), 0, 8) . '-' . $cssFile;
310
+		return substr(md5($this->urlGenerator->getBaseUrl().$frontendController), 0, 8).'-'.$cssFile;
311 311
 	}
312 312
 
313 313
 	/**
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
 	 */
319 319
 	private function getWebDir($path, $app) {
320 320
 		// Detect if path is within an app path
321
-		if($appWebPath = \OC_App::getAppWebPath($app)) {
321
+		if ($appWebPath = \OC_App::getAppWebPath($app)) {
322 322
 			return substr($path, strpos($path, $appWebPath));
323 323
 		}
324 324
 		return substr($path, strlen($this->serverRoot));
Please login to merge, or discard this patch.