| Conditions | 10 |
| Paths | 10 |
| Total Lines | 54 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 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 |
||
| 56 | public function process(): void |
||
| 57 | { |
||
| 58 | // Remove any URLs which have already been processed |
||
| 59 | if ($this->ProcessedURLs) { |
||
|
|
|||
| 60 | $this->URLsToProcess = array_diff_key( |
||
| 61 | $this->URLsToProcess, |
||
| 62 | $this->ProcessedURLs |
||
| 63 | ); |
||
| 64 | } |
||
| 65 | |||
| 66 | $chunkSize = $this->getChunkSize(); |
||
| 67 | $count = 0; |
||
| 68 | |||
| 69 | // Generate static cache for all live pages |
||
| 70 | foreach ($this->URLsToProcess as $url => $priority) { |
||
| 71 | $count += 1; |
||
| 72 | |||
| 73 | if ($chunkSize > 0 && $count > $chunkSize) { |
||
| 74 | return; |
||
| 75 | } |
||
| 76 | |||
| 77 | $this->processUrl($url, $priority); |
||
| 78 | } |
||
| 79 | |||
| 80 | if (count($this->URLsToProcess) === 0) { |
||
| 81 | $trimSlashes = function ($value) { |
||
| 82 | return trim($value, '/'); |
||
| 83 | }; |
||
| 84 | |||
| 85 | // List of all URLs which have a static cache file |
||
| 86 | $this->publishedURLs = array_map($trimSlashes, Publisher::singleton()->getPublishedURLs()); |
||
| 87 | |||
| 88 | // List of all URLs which were published as a part of this job |
||
| 89 | $this->ProcessedURLs = array_map($trimSlashes, $this->ProcessedURLs); |
||
| 90 | |||
| 91 | // Determine stale URLs - those which were not published as a part of this job |
||
| 92 | // but still have a static cache file |
||
| 93 | $this->URLsToCleanUp = array_diff($this->publishedURLs, $this->ProcessedURLs); |
||
| 94 | |||
| 95 | foreach ($this->URLsToCleanUp as $staleURL) { |
||
| 96 | $purgeMeta = Publisher::singleton()->purgeURL($staleURL); |
||
| 97 | $purgeMeta = is_array($purgeMeta) ? $purgeMeta : []; |
||
| 98 | |||
| 99 | if (array_key_exists('success', $purgeMeta) && $purgeMeta['success']) { |
||
| 100 | unset($this->jobData->URLsToCleanUp[$staleURL]); |
||
| 101 | |||
| 102 | continue; |
||
| 103 | } |
||
| 104 | |||
| 105 | $this->handleFailedUrl($staleURL, $purgeMeta); |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 109 | $this->updateCompletedState(); |
||
| 110 | } |
||
| 165 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.