| Conditions | 10 |
| Paths | 25 |
| Total Lines | 36 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 78 | public function doClear(): void |
||
| 79 | { |
||
| 80 | if (empty($this->cachesToClear)) { |
||
| 81 | return; |
||
| 82 | } |
||
| 83 | |||
| 84 | if (!count($this->cacheTypes)) { |
||
| 85 | $this->initialiseCacheTypeMap(); |
||
| 86 | } |
||
| 87 | foreach ($this->cachesToClear as $type) { |
||
| 88 | foreach ($this->cacheTypes as $cacheType => $files) { |
||
| 89 | if (0 !== mb_strpos($cacheType, $type)) { |
||
| 90 | continue; |
||
| 91 | } |
||
| 92 | foreach ($files as $file) { |
||
| 93 | if (is_dir($file)) { |
||
| 94 | // Do not delete the folder itself, but all files in it. |
||
| 95 | // Otherwise Symfony somehow can't create the folder anymore. |
||
| 96 | $file = new FilesystemIterator($file); |
||
| 97 | } |
||
| 98 | // This silently ignores non existing files. |
||
| 99 | $this->fileSystem->remove($file); |
||
| 100 | } |
||
| 101 | $this->logger->notice(sprintf('Cache cleared: %s', $cacheType)); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | if (function_exists('opcache_reset') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN)) { |
||
| 105 | // This is a brute force clear of _all_ the cached files |
||
| 106 | // because simply clearing the files in $this->cachesToClear isn't enough. |
||
| 107 | // Perhaps if we could discern exactly which files to invalidate, we could |
||
| 108 | // take a more precise approach with @opcache_invalidate($file, true). |
||
| 109 | @opcache_reset(); |
||
|
|
|||
| 110 | $this->logger->notice('OPCache cleared!'); |
||
| 111 | } |
||
| 112 | // the cache must be warmed after deleting files |
||
| 113 | $this->warmer->warmUp($this->cacheDir); |
||
| 114 | } |
||
| 158 |
If you suppress an error, we recommend checking for the error condition explicitly: