| Conditions | 18 |
| Paths | 1315 |
| Total Lines | 74 |
| Code Lines | 47 |
| 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 |
||
| 205 | sleep(10); |
||
| 206 | |||
| 207 | $bnfOuvrage = (new BnfFromIsbnHandler($isbn, $isbn10, $this->logger))->handle(); |
||
| 208 | $this->completeOuvrage($bnfOuvrage); // todo move to BnfFromIsbnHandler ? |
||
| 209 | |||
| 210 | if ($bnfOuvrage instanceof OuvrageTemplate) { |
||
| 211 | $wdOuvrage = (new WikidataSearchHandler($bnfOuvrage, $this->wikidataAdapter, $this->page))->handle(); |
||
| 212 | $this->completeOuvrage($wdOuvrage); |
||
| 213 | } |
||
| 214 | |||
| 215 | if ((new GoogleRequestValidator($this->ouvrage, $bnfOuvrage))->validate()) { |
||
| 216 | $googleOuvrage = (new GoogleBooksHandler($isbn, $this->logger))->handle(); |
||
| 217 | $this->completeOuvrage($googleOuvrage); |
||
| 218 | } |
||
| 219 | |||
| 220 | if (!isset($bnfOuvrage) && !isset($googleOuvrage)) { |
||
| 221 | $openLibraryOuvrage = (new OpenLibraryHandler($isbn, $this->logger))->handle(); |
||
| 222 | $this->completeOuvrage($openLibraryOuvrage); |
||
| 223 | } |
||
| 224 | } |
||
| 225 | |||
| 226 | protected function completeOuvrage(?OuvrageTemplate $onlineOuvrage): void |
||
| 227 | { |
||
| 228 | if (!$onlineOuvrage instanceof OuvrageTemplate) { |
||
| 229 | return; |
||
| 230 | } |
||
| 231 | $this->logger->info($onlineOuvrage->serialize(true)); |
||
| 232 | $optimizer = OptimizerFactory::fromTemplate($onlineOuvrage, $this->page, $this->logger); |
||
| 233 | $onlineOptimized = ($optimizer)->doTasks()->getOptiTemplate(); |
||
| 234 | |||
| 235 | $completer = new OuvrageComplete($this->ouvrage, $onlineOptimized, $this->logger); |
||
| 236 | $this->ouvrage = $completer->getResult(); |
||
| 237 | |||
| 238 | // todo move that optimizing in OuvrageComplete ? |
||
| 239 | $optimizer = OptimizerFactory::fromTemplate($this->ouvrage, $this->page, $this->logger); |
||
| 240 | $this->ouvrage = $optimizer->doTasks()->getOptiTemplate(); |
||
| 241 | |||
| 242 | $this->logger->info('Summary', $completer->getSummaryLog()); |
||
| 243 | |||
| 244 | if ($completer->major) { |
||
| 245 | $this->citationWorkStatus->minorFlag = false; |
||
| 246 | } |
||
| 247 | $this->citationWorkStatus->notCosmetic = ($completer->notCosmetic || $this->citationWorkStatus->notCosmetic); |
||
| 248 | $this->summaryLog = array_merge($this->getSummaryLog(), $completer->getSummaryLog()); |
||
| 249 | unset($optimizer); |
||
| 250 | unset($completer); |
||
| 251 | } |
||
| 252 | |||
| 253 | protected function sendCompleted() |
||
| 254 | { |
||
| 255 | $this->pageOuvrage |
||
| 256 | ->setOpti($this->serializeFinalOpti()) |
||
| 257 | ->setOptidate(new DateTime()) |
||
| 258 | ->setModifs(mb_substr(implode(',', $this->getSummaryLog()), 0, 250)) |
||
| 259 | ->setNotcosmetic(($this->citationWorkStatus->notCosmetic) ? 1 : 0) |
||
| 260 | ->setMajor(($this->citationWorkStatus->minorFlag) ? 0 : 1) |
||
| 261 | ->setIsbn(substr($this->ouvrage->getParam('isbn'), 0, 19)) |
||
| 262 | ->setVersion(WikiBotConfig::VERSION ?? null); |
||
| 263 | |||
| 264 | $result = $this->queueAdapter->sendCompletedData($this->pageOuvrage); |
||
| 265 | $this->logger->debug($result ? 'OK DB' : 'erreur sendCompletedData()'); |
||
| 266 | } |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Final serialization of the completed OuvrageTemplate. |
||
| 270 | */ |
||
| 271 | protected function serializeFinalOpti(): string |
||
| 272 | { |
||
| 273 | // // Améliore style compact : plus espacé |
||
| 274 | // if ('|' === $this->ouvrage->userSeparator) { |
||
| 275 | // $this->ouvrage->userSeparator = ' |'; |
||
| 276 | // } |
||
| 277 | $finalOpti = $this->ouvrage->serialize(true); |
||
| 278 | $finalOpti = Normalizer::normalize($finalOpti); |
||
| 279 | if (empty($finalOpti) || !is_string($finalOpti)) { |
||
| 286 |