Passed
Pull Request — master (#18)
by Jeroen De
02:04
created
src/ResourceLoaderSCSSModule.php 1 patch
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -73,17 +73,17 @@  discard block
 block discarded – undo
73 73
 	 * @param string|null $localBasePath
74 74
 	 * @param string|null $remoteBasePath
75 75
 	 */
76
-	public function __construct( $options = [], $localBasePath = null, $remoteBasePath = null ) {
76
+	public function __construct($options = [], $localBasePath = null, $remoteBasePath = null) {
77 77
 
78
-		parent::__construct( $options, $localBasePath, $remoteBasePath );
78
+		parent::__construct($options, $localBasePath, $remoteBasePath);
79 79
 
80
-		$this->applyOptions( $options );
80
+		$this->applyOptions($options);
81 81
 	}
82 82
 
83 83
 	/**
84 84
 	 * @param mixed[] $options
85 85
 	 */
86
-	protected function applyOptions( $options ) {
86
+	protected function applyOptions($options) {
87 87
 
88 88
 		$mapConfigToLocalVar = [
89 89
 			'variables'      => 'variables',
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
 			'cacheTriggers' => 'cacheTriggers',
92 92
 		];
93 93
 
94
-		foreach ( $mapConfigToLocalVar as $config => $local ) {
95
-			if ( isset( $options[ $config ] ) ) {
96
-				$this->$local = $options[ $config ];
94
+		foreach ($mapConfigToLocalVar as $config => $local) {
95
+			if (isset($options[$config])) {
96
+				$this->$local = $options[$config];
97 97
 			}
98 98
 		}
99 99
 	}
@@ -105,40 +105,40 @@  discard block
 block discarded – undo
105 105
 	 *
106 106
 	 * @return array
107 107
 	 */
108
-	public function getStyles( ResourceLoaderContext $context ) {
108
+	public function getStyles(ResourceLoaderContext $context) {
109 109
 
110
-		if ( $this->styleText === null ) {
110
+		if ($this->styleText === null) {
111 111
 
112
-			$this->retrieveStylesFromCache( $context );
112
+			$this->retrieveStylesFromCache($context);
113 113
 
114
-			if ( $this->styleText === null ) {
115
-				$this->compileStyles( $context );
114
+			if ($this->styleText === null) {
115
+				$this->compileStyles($context);
116 116
 			}
117 117
 		}
118 118
 
119
-		return [ 'all' => $this->styleText ];
119
+		return ['all' => $this->styleText];
120 120
 	}
121 121
 
122 122
 	/**
123 123
 	 * @param ResourceLoaderContext $context
124 124
 	 */
125
-	protected function retrieveStylesFromCache( ResourceLoaderContext $context ) {
125
+	protected function retrieveStylesFromCache(ResourceLoaderContext $context) {
126 126
 
127 127
 		// Try for cache hit
128
-		$cacheKey = $this->getCacheKey( $context );
129
-		$cacheResult = $this->getCache()->get( $cacheKey );
128
+		$cacheKey = $this->getCacheKey($context);
129
+		$cacheResult = $this->getCache()->get($cacheKey);
130 130
 
131
-		if ( is_array( $cacheResult ) ) {
131
+		if (is_array($cacheResult)) {
132 132
 
133
-			if ( $this->isCacheOutdated( $cacheResult[ 'storetime' ] ) ) {
134
-				wfDebug( "SCSS: Cache miss for {$this->getName()}: Cache outdated.\n", 'private' );
133
+			if ($this->isCacheOutdated($cacheResult['storetime'])) {
134
+				wfDebug("SCSS: Cache miss for {$this->getName()}: Cache outdated.\n", 'private');
135 135
 			} else {
136
-				$this->styleText = $cacheResult[ 'styles' ];
137
-				wfDebug( "SCSS: Cache hit for {$this->getName()}: Got styles from cache.\n", 'private' );
136
+				$this->styleText = $cacheResult['styles'];
137
+				wfDebug("SCSS: Cache hit for {$this->getName()}: Got styles from cache.\n", 'private');
138 138
 			}
139 139
 
140 140
 		} else {
141
-			wfDebug( "SCSS: Cache miss for {$this->getName()}: Styles not found in cache.\n", 'private' );
141
+			wfDebug("SCSS: Cache miss for {$this->getName()}: Styles not found in cache.\n", 'private');
142 142
 		}
143 143
 	}
144 144
 
@@ -147,8 +147,8 @@  discard block
 block discarded – undo
147 147
 	 */
148 148
 	protected function getCache() {
149 149
 
150
-		if ( $this->cache === null ) {
151
-			$this->cache = ObjectCache::getInstance( $GLOBALS[ 'egScssCacheType' ] );
150
+		if ($this->cache === null) {
151
+			$this->cache = ObjectCache::getInstance($GLOBALS['egScssCacheType']);
152 152
 		}
153 153
 
154 154
 		return $this->cache;
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 *
160 160
 	 * @param BagOStuff $cache
161 161
 	 */
162
-	public function setCache( BagOStuff $cache ) {
162
+	public function setCache(BagOStuff $cache) {
163 163
 		$this->cache = $cache;
164 164
 	}
165 165
 
@@ -168,18 +168,18 @@  discard block
 block discarded – undo
168 168
 	 *
169 169
 	 * @return string
170 170
 	 */
171
-	protected function getCacheKey( ResourceLoaderContext $context ) {
171
+	protected function getCacheKey(ResourceLoaderContext $context) {
172 172
 
173
-		if ( $this->cacheKey === null ) {
173
+		if ($this->cacheKey === null) {
174 174
 
175
-			$styles = serialize( $this->styles );
175
+			$styles = serialize($this->styles);
176 176
 
177 177
 			$vars = $this->variables;
178
-			ksort( $vars );
179
-			$vars = serialize( $vars );
178
+			ksort($vars);
179
+			$vars = serialize($vars);
180 180
 
181 181
 			// have to hash the module config, else it may become too long
182
-			$configHash = md5( $styles . $vars );
182
+			$configHash = md5($styles . $vars);
183 183
 
184 184
 			$this->cacheKey = wfMemcKey(
185 185
 				'ext',
@@ -197,11 +197,11 @@  discard block
 block discarded – undo
197 197
 	 *
198 198
 	 * @return bool
199 199
 	 */
200
-	protected function isCacheOutdated( $cacheStoreTime ) {
200
+	protected function isCacheOutdated($cacheStoreTime) {
201 201
 
202
-		foreach ( $this->cacheTriggers as $triggerFile ) {
202
+		foreach ($this->cacheTriggers as $triggerFile) {
203 203
 
204
-			if ( $triggerFile !== null && $cacheStoreTime < filemtime( $triggerFile ) ) {
204
+			if ($triggerFile !== null && $cacheStoreTime < filemtime($triggerFile)) {
205 205
 				return true;
206 206
 			}
207 207
 
@@ -213,18 +213,18 @@  discard block
 block discarded – undo
213 213
 	/**
214 214
 	 * @param ResourceLoaderContext $context
215 215
 	 */
216
-	protected function compileStyles( ResourceLoaderContext $context ) {
216
+	protected function compileStyles(ResourceLoaderContext $context) {
217 217
 
218 218
 		$scss = new Compiler();
219
-		$scss->setImportPaths( $this->getLocalPath( '' ) );
219
+		$scss->setImportPaths($this->getLocalPath(''));
220 220
 
221 221
 		// Allows inlining of arbitrary files regardless of extension, .css in particular
222 222
 		$scss->addImportPath(
223 223
 
224 224
 			// addImportPath is declared as requiring a string param, but actually also understand callables
225 225
 			/** @scrutinizer ignore-type */
226
-			function ( $path ) {
227
-				if ( file_exists( $path ) ) {
226
+			function($path) {
227
+				if (file_exists($path)) {
228 228
 					return $path;
229 229
 				}
230 230
 				return null;
@@ -236,27 +236,27 @@  discard block
 block discarded – undo
236 236
 
237 237
 			$imports = $this->getStyleFilesList();
238 238
 
239
-			foreach ( $imports as $key => $import ) {
240
-				$path = str_replace( [ '\\', '"' ], [ '\\\\', '\\"' ], $import );
241
-				$imports[ $key ] = '@import "' . $path . '";';
239
+			foreach ($imports as $key => $import) {
240
+				$path = str_replace(['\\', '"'], ['\\\\', '\\"'], $import);
241
+				$imports[$key] = '@import "' . $path . '";';
242 242
 			}
243 243
 
244
-			$scss->setVariables( $this->variables );
244
+			$scss->setVariables($this->variables);
245 245
 
246
-			$style = $scss->compile( implode( $imports ) );
246
+			$style = $scss->compile(implode($imports));
247 247
 
248
-			if ( $this->getFlip( $context ) ) {
249
-				$style = CSSJanus::transform( $style, true, false );
248
+			if ($this->getFlip($context)) {
249
+				$style = CSSJanus::transform($style, true, false);
250 250
 			}
251 251
 
252 252
 			$this->styleText = $style;
253 253
 
254
-			$this->updateCache( $context );
254
+			$this->updateCache($context);
255 255
 
256
-		} catch ( Exception $e ) {
256
+		} catch (Exception $e) {
257 257
 
258
-			$this->purgeCache( $context );
259
-			wfDebug( $e->getMessage() );
258
+			$this->purgeCache($context);
259
+			wfDebug($e->getMessage());
260 260
 			$this->styleText = '/* SCSS compile error: ' . $e->getMessage() . '*/';
261 261
 		}
262 262
 
@@ -265,19 +265,19 @@  discard block
 block discarded – undo
265 265
 	/**
266 266
 	 * @param ResourceLoaderContext $context
267 267
 	 */
268
-	protected function updateCache( ResourceLoaderContext $context ) {
268
+	protected function updateCache(ResourceLoaderContext $context) {
269 269
 
270 270
 		$this->getCache()->set(
271
-			$this->getCacheKey( $context ),
272
-			[ 'styles' => $this->styleText, 'storetime' => time() ]
271
+			$this->getCacheKey($context),
272
+			['styles' => $this->styleText, 'storetime' => time()]
273 273
 		);
274 274
 	}
275 275
 
276 276
 	/**
277 277
 	 * @param ResourceLoaderContext $context
278 278
 	 */
279
-	protected function purgeCache( ResourceLoaderContext $context ) {
280
-		$this->getCache()->delete( $this->getCacheKey( $context ) );
279
+	protected function purgeCache(ResourceLoaderContext $context) {
280
+		$this->getCache()->delete($this->getCacheKey($context));
281 281
 	}
282 282
 
283 283
 	/**
@@ -291,12 +291,12 @@  discard block
 block discarded – undo
291 291
 	 * @return array
292 292
 	 */
293 293
 	protected function getStyleFilesList() {
294
-		$styles = self::collateFilePathListByOption( $this->styles, 'position', 'main' );
294
+		$styles = self::collateFilePathListByOption($this->styles, 'position', 'main');
295 295
 		$imports = [];
296 296
 
297
-		foreach ( $this->styleModulePositions as $position ) {
298
-			if ( isset( $styles[ $position ] ) ) {
299
-				$imports = array_merge( $imports, $styles[ $position ] );
297
+		foreach ($this->styleModulePositions as $position) {
298
+			if (isset($styles[$position])) {
299
+				$imports = array_merge($imports, $styles[$position]);
300 300
 			}
301 301
 		}
302 302
 
Please login to merge, or discard this patch.