| Conditions | 10 |
| Paths | 192 |
| Total Lines | 42 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 36 | public function generateSummary(): string |
||
| 37 | { |
||
| 38 | // Start summary with "WikiBotConfig" when using botFlag, else "*" |
||
| 39 | $prefix = ($this->botFlag) ? 'bot ' : ''; //🧐 🤖 |
||
| 40 | // add "/!\" when errorWarning |
||
| 41 | $prefix .= (empty($this->errorWarning)) ? '' : ' ⚠️'; |
||
| 42 | $prefix .= (empty($this->featured_article)) ? '' : ' ☆'; // AdQ, BA |
||
| 43 | |||
| 44 | // basic modifs |
||
| 45 | $citeSummary = implode(' ', $this->citationSummary); |
||
| 46 | // replace by list of modifs to verify by humans |
||
| 47 | if (!empty($this->importantSummary)) { |
||
| 48 | $citeSummary = implode(', ', $this->importantSummary); |
||
| 49 | } |
||
| 50 | |||
| 51 | $summary = sprintf( |
||
| 52 | '%s [%s] %s %sx : %s', |
||
| 53 | trim($prefix), |
||
| 54 | str_replace('v', '', $this->citationVersion), |
||
| 55 | trim(self::TASK_NAME), |
||
| 56 | $this->nbRows, |
||
| 57 | $citeSummary |
||
| 58 | ); |
||
| 59 | |||
| 60 | if (!empty($this->importantSummary)) { |
||
| 61 | $summary .= '...'; |
||
| 62 | } |
||
| 63 | |||
| 64 | // shrink long summary if no important details to verify |
||
| 65 | if (empty($this->importantSummary)) { |
||
| 66 | $length = strlen($summary); |
||
| 67 | $summary = mb_substr($summary, 0, 80); |
||
| 68 | $summary .= ($length > strlen($summary)) ? '…' : ''; |
||
| 69 | } |
||
| 70 | |||
| 71 | // Luck message |
||
| 72 | if (!$this->luckyState && (new DateTime())->format('H:i') === '11:11') { |
||
| 73 | $this->luckyState = true; |
||
|
1 ignored issue
–
show
|
|||
| 74 | $summary .= self::LUCKY_MESSAGE; |
||
|
1 ignored issue
–
show
|
|||
| 75 | } |
||
| 76 | |||
| 77 | return $summary; |
||
| 78 | } |
||
| 81 |