@@ -73,17 +73,17 @@ discard block |
||
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 |
||
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 |
||
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,15 +147,15 @@ discard block |
||
147 | 147 | */ |
148 | 148 | protected function getCache() { |
149 | 149 | |
150 | - if ( $this->cache === null ) { |
|
151 | - $this->cache = ObjectCache::getInstance( $this->getCacheType() ); |
|
150 | + if ($this->cache === null) { |
|
151 | + $this->cache = ObjectCache::getInstance($this->getCacheType()); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | return $this->cache; |
155 | 155 | } |
156 | 156 | |
157 | 157 | private function getCacheType() { |
158 | - return array_key_exists( 'egScssCacheType', $GLOBALS ) ? $GLOBALS[ 'egScssCacheType' ] : -1; |
|
158 | + return array_key_exists('egScssCacheType', $GLOBALS) ? $GLOBALS['egScssCacheType'] : -1; |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * |
164 | 164 | * @param BagOStuff $cache |
165 | 165 | */ |
166 | - public function setCache( BagOStuff $cache ) { |
|
166 | + public function setCache(BagOStuff $cache) { |
|
167 | 167 | $this->cache = $cache; |
168 | 168 | } |
169 | 169 | |
@@ -172,18 +172,18 @@ discard block |
||
172 | 172 | * |
173 | 173 | * @return string |
174 | 174 | */ |
175 | - protected function getCacheKey( ResourceLoaderContext $context ) { |
|
175 | + protected function getCacheKey(ResourceLoaderContext $context) { |
|
176 | 176 | |
177 | - if ( $this->cacheKey === null ) { |
|
177 | + if ($this->cacheKey === null) { |
|
178 | 178 | |
179 | - $styles = serialize( $this->styles ); |
|
179 | + $styles = serialize($this->styles); |
|
180 | 180 | |
181 | 181 | $vars = $this->variables; |
182 | - ksort( $vars ); |
|
183 | - $vars = serialize( $vars ); |
|
182 | + ksort($vars); |
|
183 | + $vars = serialize($vars); |
|
184 | 184 | |
185 | 185 | // have to hash the module config, else it may become too long |
186 | - $configHash = md5( $styles . $vars ); |
|
186 | + $configHash = md5($styles . $vars); |
|
187 | 187 | |
188 | 188 | $this->cacheKey = wfMemcKey( |
189 | 189 | 'ext', |
@@ -201,11 +201,11 @@ discard block |
||
201 | 201 | * |
202 | 202 | * @return bool |
203 | 203 | */ |
204 | - protected function isCacheOutdated( $cacheStoreTime ) { |
|
204 | + protected function isCacheOutdated($cacheStoreTime) { |
|
205 | 205 | |
206 | - foreach ( $this->cacheTriggers as $triggerFile ) { |
|
206 | + foreach ($this->cacheTriggers as $triggerFile) { |
|
207 | 207 | |
208 | - if ( $triggerFile !== null && $cacheStoreTime < filemtime( $triggerFile ) ) { |
|
208 | + if ($triggerFile !== null && $cacheStoreTime < filemtime($triggerFile)) { |
|
209 | 209 | return true; |
210 | 210 | } |
211 | 211 | |
@@ -217,18 +217,18 @@ discard block |
||
217 | 217 | /** |
218 | 218 | * @param ResourceLoaderContext $context |
219 | 219 | */ |
220 | - protected function compileStyles( ResourceLoaderContext $context ) { |
|
220 | + protected function compileStyles(ResourceLoaderContext $context) { |
|
221 | 221 | |
222 | 222 | $scss = new Compiler(); |
223 | - $scss->setImportPaths( $this->getLocalPath( '' ) ); |
|
223 | + $scss->setImportPaths($this->getLocalPath('')); |
|
224 | 224 | |
225 | 225 | // Allows inlining of arbitrary files regardless of extension, .css in particular |
226 | 226 | $scss->addImportPath( |
227 | 227 | |
228 | 228 | // addImportPath is declared as requiring a string param, but actually also understand callables |
229 | 229 | /** @scrutinizer ignore-type */ |
230 | - function ( $path ) { |
|
231 | - if ( file_exists( $path ) ) { |
|
230 | + function($path) { |
|
231 | + if (file_exists($path)) { |
|
232 | 232 | return $path; |
233 | 233 | } |
234 | 234 | return null; |
@@ -240,27 +240,27 @@ discard block |
||
240 | 240 | |
241 | 241 | $imports = $this->getStyleFilesList(); |
242 | 242 | |
243 | - foreach ( $imports as $key => $import ) { |
|
244 | - $path = str_replace( [ '\\', '"' ], [ '\\\\', '\\"' ], $import ); |
|
245 | - $imports[ $key ] = '@import "' . $path . '";'; |
|
243 | + foreach ($imports as $key => $import) { |
|
244 | + $path = str_replace(['\\', '"'], ['\\\\', '\\"'], $import); |
|
245 | + $imports[$key] = '@import "' . $path . '";'; |
|
246 | 246 | } |
247 | 247 | |
248 | - $scss->setVariables( $this->variables ); |
|
248 | + $scss->setVariables($this->variables); |
|
249 | 249 | |
250 | - $style = $scss->compile( implode( $imports ) ); |
|
250 | + $style = $scss->compile(implode($imports)); |
|
251 | 251 | |
252 | - if ( $this->getFlip( $context ) ) { |
|
253 | - $style = CSSJanus::transform( $style, true, false ); |
|
252 | + if ($this->getFlip($context)) { |
|
253 | + $style = CSSJanus::transform($style, true, false); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | $this->styleText = $style; |
257 | 257 | |
258 | - $this->updateCache( $context ); |
|
258 | + $this->updateCache($context); |
|
259 | 259 | |
260 | - } catch ( Exception $e ) { |
|
260 | + } catch (Exception $e) { |
|
261 | 261 | |
262 | - $this->purgeCache( $context ); |
|
263 | - wfDebug( $e->getMessage() ); |
|
262 | + $this->purgeCache($context); |
|
263 | + wfDebug($e->getMessage()); |
|
264 | 264 | $this->styleText = '/* SCSS compile error: ' . $e->getMessage() . '*/'; |
265 | 265 | } |
266 | 266 | |
@@ -269,19 +269,19 @@ discard block |
||
269 | 269 | /** |
270 | 270 | * @param ResourceLoaderContext $context |
271 | 271 | */ |
272 | - protected function updateCache( ResourceLoaderContext $context ) { |
|
272 | + protected function updateCache(ResourceLoaderContext $context) { |
|
273 | 273 | |
274 | 274 | $this->getCache()->set( |
275 | - $this->getCacheKey( $context ), |
|
276 | - [ 'styles' => $this->styleText, 'storetime' => time() ] |
|
275 | + $this->getCacheKey($context), |
|
276 | + ['styles' => $this->styleText, 'storetime' => time()] |
|
277 | 277 | ); |
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
281 | 281 | * @param ResourceLoaderContext $context |
282 | 282 | */ |
283 | - protected function purgeCache( ResourceLoaderContext $context ) { |
|
284 | - $this->getCache()->delete( $this->getCacheKey( $context ) ); |
|
283 | + protected function purgeCache(ResourceLoaderContext $context) { |
|
284 | + $this->getCache()->delete($this->getCacheKey($context)); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
@@ -295,12 +295,12 @@ discard block |
||
295 | 295 | * @return array |
296 | 296 | */ |
297 | 297 | protected function getStyleFilesList() { |
298 | - $styles = self::collateFilePathListByOption( $this->styles, 'position', 'main' ); |
|
298 | + $styles = self::collateFilePathListByOption($this->styles, 'position', 'main'); |
|
299 | 299 | $imports = []; |
300 | 300 | |
301 | - foreach ( $this->styleModulePositions as $position ) { |
|
302 | - if ( isset( $styles[ $position ] ) ) { |
|
303 | - $imports = array_merge( $imports, $styles[ $position ] ); |
|
301 | + foreach ($this->styleModulePositions as $position) { |
|
302 | + if (isset($styles[$position])) { |
|
303 | + $imports = array_merge($imports, $styles[$position]); |
|
304 | 304 | } |
305 | 305 | } |
306 | 306 |