| Conditions | 10 |
| Paths | 12 |
| Total Lines | 54 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 61 | public function process() |
||
| 62 | { |
||
| 63 | // Remove any URLs which have already been processed |
||
| 64 | if ($this->jobData->ProcessedURLs) { |
||
| 65 | $this->jobData->URLsToProcess = array_diff_key( |
||
| 66 | $this->jobData->URLsToProcess, |
||
| 67 | $this->jobData->ProcessedURLs |
||
| 68 | ); |
||
| 69 | } |
||
| 70 | |||
| 71 | $chunkSize = $this->getChunkSize(); |
||
| 72 | |||
| 73 | // generate static cache for all live pages |
||
| 74 | $count = 0; |
||
| 75 | foreach ($this->jobData->URLsToProcess as $url => $priority) { |
||
| 76 | $count += 1; |
||
| 77 | if ($chunkSize > 0 && $count > $chunkSize) { |
||
| 78 | break; |
||
| 79 | } |
||
| 80 | |||
| 81 | $this->processUrl($url, $priority); |
||
| 82 | } |
||
| 83 | |||
| 84 | // cleanup unused static cache files |
||
| 85 | if (count($this->jobData->URLsToProcess) === 0) { |
||
| 86 | $trimSlashes = function ($value) { |
||
| 87 | return trim($value, '/'); |
||
| 88 | }; |
||
| 89 | |||
| 90 | // list of all URLs which have a static cache file |
||
| 91 | $this->jobData->publishedURLs = array_map($trimSlashes, Publisher::singleton()->getPublishedURLs()); |
||
| 92 | |||
| 93 | // list of all URLs which were published as a part of this job |
||
| 94 | $this->jobData->ProcessedURLs = array_map($trimSlashes, $this->jobData->ProcessedURLs); |
||
| 95 | |||
| 96 | // determine stale URLs - those which were not published as a part of this job |
||
| 97 | //but still have a static cache file |
||
| 98 | $this->jobData->URLsToCleanUp = array_diff($this->jobData->publishedURLs, $this->jobData->ProcessedURLs); |
||
| 99 | |||
| 100 | foreach ($this->jobData->URLsToCleanUp as $staleURL) { |
||
| 101 | $purgeMeta = Publisher::singleton()->purgeURL($staleURL); |
||
| 102 | $purgeMeta = (is_array($purgeMeta)) ? $purgeMeta : []; |
||
| 103 | |||
| 104 | if (array_key_exists('success', $purgeMeta) && $purgeMeta['success']) { |
||
| 105 | unset($this->jobData->URLsToCleanUp[$staleURL]); |
||
| 106 | |||
| 107 | continue; |
||
| 108 | } |
||
| 109 | |||
| 110 | $this->handleFailedUrl($staleURL, $purgeMeta); |
||
| 111 | } |
||
| 112 | }; |
||
| 113 | |||
| 114 | $this->updateCompletedState(); |
||
| 115 | } |
||
| 170 |