Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 46 | class SCSSCacher { |
||
| 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 \OC_Defaults */ |
||
| 61 | private $defaults; |
||
| 62 | |||
| 63 | /** @var string */ |
||
| 64 | protected $serverRoot; |
||
| 65 | |||
| 66 | /** @var ICache */ |
||
| 67 | protected $depsCache; |
||
| 68 | |||
| 69 | /** @var null|string */ |
||
| 70 | private $injectedVariables; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @param ILogger $logger |
||
| 74 | * @param Factory $appDataFactory |
||
| 75 | * @param IURLGenerator $urlGenerator |
||
| 76 | * @param IConfig $config |
||
| 77 | * @param \OC_Defaults $defaults |
||
| 78 | * @param string $serverRoot |
||
| 79 | * @param ICache $depsCache |
||
| 80 | */ |
||
| 81 | public function __construct(ILogger $logger, |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Process the caching process if needed |
||
| 99 | * |
||
| 100 | * @param string $root Root path to the nextcloud installation |
||
| 101 | * @param string $file |
||
| 102 | * @param string $app The app name |
||
| 103 | * @return boolean |
||
| 104 | * @throws NotPermittedException |
||
| 105 | */ |
||
| 106 | public function process(string $root, string $file, string $app): bool { |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @param $appName |
||
| 131 | * @param $fileName |
||
| 132 | * @return ISimpleFile |
||
| 133 | */ |
||
| 134 | public function getCachedCSS(string $appName, string $fileName): ISimpleFile { |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Check if the file is cached or not |
||
| 141 | * @param string $fileNameCSS |
||
| 142 | * @param ISimpleFolder $folder |
||
| 143 | * @return boolean |
||
| 144 | */ |
||
| 145 | private function isCached(string $fileNameCSS, ISimpleFolder $folder) { |
||
| 146 | try { |
||
| 147 | $cachedFile = $folder->getFile($fileNameCSS); |
||
| 148 | if ($cachedFile->getSize() > 0) { |
||
| 149 | $depFileName = $fileNameCSS . '.deps'; |
||
| 150 | $deps = $this->depsCache->get($folder->getName() . '-' . $depFileName); |
||
| 151 | if ($deps === null) { |
||
| 152 | $depFile = $folder->getFile($depFileName); |
||
| 153 | $deps = $depFile->getContent(); |
||
| 154 | //Set to memcache for next run |
||
| 155 | $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps); |
||
| 156 | } |
||
| 157 | $deps = json_decode($deps, true); |
||
| 158 | |||
| 159 | View Code Duplication | foreach ((array)$deps as $file=>$mtime) { |
|
| 160 | if (!file_exists($file) || filemtime($file) > $mtime) { |
||
| 161 | return false; |
||
| 162 | } |
||
| 163 | } |
||
| 164 | return true; |
||
| 165 | } |
||
| 166 | return false; |
||
| 167 | } catch(NotFoundException $e) { |
||
| 168 | return false; |
||
| 169 | } |
||
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Check if the variables file has changed |
||
| 174 | * @return bool |
||
| 175 | */ |
||
| 176 | private function variablesChanged(): bool { |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Cache the file with AppData |
||
| 188 | * |
||
| 189 | * @param string $path |
||
| 190 | * @param string $fileNameCSS |
||
| 191 | * @param string $fileNameSCSS |
||
| 192 | * @param ISimpleFolder $folder |
||
| 193 | * @param string $webDir |
||
| 194 | * @return boolean |
||
| 195 | * @throws NotPermittedException |
||
| 196 | */ |
||
| 197 | private function cache(string $path, string $fileNameCSS, string $fileNameSCSS, ISimpleFolder $folder, string $webDir) { |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Reset scss cache by deleting all generated css files |
||
| 262 | * We need to regenerate all files when variables change |
||
| 263 | */ |
||
| 264 | public function resetCache() { |
||
| 274 | |||
| 275 | /** |
||
| 276 | * @return string SCSS code for variables from OC_Defaults |
||
| 277 | */ |
||
| 278 | private function getInjectedVariables(): string { |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Add the correct uri prefix to make uri valid again |
||
| 301 | * @param string $css |
||
| 302 | * @param string $webDir |
||
| 303 | * @return string |
||
| 304 | */ |
||
| 305 | private function rebaseUrls(string $css, string $webDir): string { |
||
| 310 | |||
| 311 | /** |
||
| 312 | * Return the cached css file uri |
||
| 313 | * @param string $appName the app name |
||
| 314 | * @param string $fileName |
||
| 315 | * @return string |
||
| 316 | */ |
||
| 317 | View Code Duplication | public function getCachedSCSS(string $appName, string $fileName): string { |
|
| 324 | |||
| 325 | /** |
||
| 326 | * Prepend hashed base url to the css file |
||
| 327 | * @param string$cssFile |
||
| 328 | * @return string |
||
| 329 | */ |
||
| 330 | private function prependBaseurlPrefix(string $cssFile): string { |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Get WebDir root |
||
| 337 | * @param string $path the css file path |
||
| 338 | * @param string $appName the app name |
||
| 339 | * @param string $serverRoot the server root path |
||
| 340 | * @param string $webRoot the nextcloud installation root path |
||
| 341 | * @return string the webDir |
||
| 342 | */ |
||
| 343 | private function getWebDir(string $path, string $appName, string $serverRoot, string $webRoot): string { |
||
| 353 | } |
||
| 354 |
Scrutinizer analyzes your
composer.json/composer.lockfile if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.