| Conditions | 10 |
| Paths | 10 |
| Total Lines | 61 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 57 | public function process(): void |
||
| 58 | { |
||
| 59 | // Remove any URLs which have already been processed |
||
| 60 | if ($this->ProcessedURLs) { |
||
|
|
|||
| 61 | $this->URLsToProcess = array_diff_key( |
||
| 62 | $this->URLsToProcess, |
||
| 63 | $this->ProcessedURLs |
||
| 64 | ); |
||
| 65 | } |
||
| 66 | |||
| 67 | $chunkSize = $this->getChunkSize(); |
||
| 68 | $count = 0; |
||
| 69 | |||
| 70 | // Generate static cache for all live pages |
||
| 71 | foreach ($this->URLsToProcess as $url => $priority) { |
||
| 72 | $count += 1; |
||
| 73 | |||
| 74 | if ($chunkSize > 0 && $count > $chunkSize) { |
||
| 75 | return; |
||
| 76 | } |
||
| 77 | |||
| 78 | $this->processUrl($url, $priority); |
||
| 79 | } |
||
| 80 | |||
| 81 | if (count($this->URLsToProcess) === 0) { |
||
| 82 | $trimSlashes = function ($value) { |
||
| 83 | $value = trim($value, '/'); |
||
| 84 | |||
| 85 | // We want to trim the schema from the beginning as they map to the same place |
||
| 86 | // anyway. |
||
| 87 | $value = ltrim($value, 'http://'); |
||
| 88 | $value = ltrim($value, 'https://'); |
||
| 89 | |||
| 90 | return $value; |
||
| 91 | }; |
||
| 92 | |||
| 93 | // List of all URLs which have a static cache file |
||
| 94 | $this->publishedURLs = array_map($trimSlashes, Publisher::singleton()->getPublishedURLs()); |
||
| 95 | |||
| 96 | // List of all URLs which were published as a part of this job |
||
| 97 | $this->ProcessedURLs = array_map($trimSlashes, $this->ProcessedURLs); |
||
| 98 | |||
| 99 | // Determine stale URLs - those which were not published as a part of this job |
||
| 100 | // but still have a static cache file |
||
| 101 | $this->URLsToCleanUp = array_diff($this->publishedURLs, $this->ProcessedURLs); |
||
| 102 | |||
| 103 | foreach ($this->URLsToCleanUp as $staleURL) { |
||
| 104 | $purgeMeta = Publisher::singleton()->purgeURL($staleURL); |
||
| 105 | $purgeMeta = is_array($purgeMeta) ? $purgeMeta : []; |
||
| 106 | |||
| 107 | if (array_key_exists('success', $purgeMeta) && $purgeMeta['success']) { |
||
| 108 | unset($this->jobData->URLsToCleanUp[$staleURL]); |
||
| 109 | |||
| 110 | continue; |
||
| 111 | } |
||
| 112 | |||
| 113 | $this->handleFailedUrl($staleURL, $purgeMeta); |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 117 | $this->updateCompletedState(); |
||
| 118 | } |
||
| 173 |
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.