| Conditions | 8 |
| Paths | 98 |
| Total Lines | 52 |
| Code Lines | 34 |
| 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 |
||
| 28 | private function sendOuvrageErrorsOnTalkPage(array $rows, LoggerInterface $log = null): bool |
||
| 29 | { |
||
| 30 | if ($log === null) { |
||
| 31 | $log = new NullLogger(); |
||
| 32 | } |
||
| 33 | if (empty($rows[0]) || empty($rows[0]['page'])) { |
||
| 34 | return false; |
||
| 35 | } |
||
| 36 | $mainTitle = $rows[0]['page']; |
||
| 37 | $log->notice("** Send Error Message on talk page. Wait 3..."); |
||
| 38 | sleep(3); |
||
| 39 | |||
| 40 | // format wiki message |
||
| 41 | $errorList = ''; |
||
| 42 | foreach ($this->pageWorkStatus->errorWarning[$mainTitle] as $error) { |
||
| 43 | $errorList .= sprintf("* <span style=\"background:#FCDFE8\"><nowiki>%s</nowiki></span> \n", $error); |
||
| 44 | } |
||
| 45 | |||
| 46 | $diffStr = ''; |
||
| 47 | try { |
||
| 48 | // get last bot revision ID |
||
| 49 | $main = ServiceFactory::wikiPageAction($mainTitle, true); |
||
| 50 | if (getenv('BOT_NAME') === $main->getLastRevision()->getUser()) { |
||
| 51 | $id = $main->getLastRevision()->getId(); |
||
| 52 | $diffStr = sprintf( |
||
| 53 | ' ([https://fr.wikipedia.org/w/index.php?title=%s&diff=%s diff])', |
||
| 54 | str_replace(' ', '_', $mainTitle), |
||
| 55 | $id |
||
| 56 | ); |
||
| 57 | } |
||
| 58 | } catch (Throwable $e) { |
||
| 59 | unset($e); |
||
| 60 | } |
||
| 61 | |||
| 62 | $errorCategoryName = sprintf('Signalement %s', getenv('BOT_NAME')); |
||
| 63 | |||
| 64 | $errorMessage = file_get_contents(self::ERROR_MSG_TEMPLATE); |
||
|
1 ignored issue
–
show
|
|||
| 65 | $errorMessage = str_replace('##CATEGORY##', $errorCategoryName, $errorMessage); |
||
| 66 | $errorMessage = str_replace('##ERROR LIST##', trim($errorList), $errorMessage); |
||
| 67 | $errorMessage = str_replace('##ARTICLE##', $mainTitle, $errorMessage); |
||
| 68 | $errorMessage = str_replace('##DIFF##', $diffStr, $errorMessage); |
||
| 69 | |||
| 70 | // Edit wiki talk page |
||
| 71 | try { |
||
| 72 | $talkPage = ServiceFactory::wikiPageAction('Discussion:'.$mainTitle); |
||
| 73 | $editInfo = ServiceFactory::editInfo('🍄 Signalement erreur {ouvrage}', false, false, 5); // 💩 |
||
| 74 | |||
| 75 | return $talkPage->addToBottomOrCreatePage("\n".$errorMessage, $editInfo); |
||
| 76 | } catch (Throwable $e) { |
||
| 77 | $log->warning('Exception after addToBottomOrCreatePage() '.$e->getMessage()); |
||
| 78 | |||
| 79 | return false; |
||
| 80 | } |
||
| 83 |