| Total Complexity | 6 |
| Total Lines | 62 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | class ErrorReport |
||
| 13 | { |
||
| 14 | const BOTNAME = 'ZiziBot'; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Liste les erreurs reportées. |
||
| 18 | * 0 => "|editor=JT Staley, MP Bryant, N Pfennig, and JG Holt, eds. <!--PARAMETRE 'editor' N'EXISTE PAS -->" |
||
| 19 | * 1 => "|editor=DR Boone and RW Castenholz, eds. <!--PARAMETRE 'editor' N'EXISTE PAS -->" |
||
| 20 | * |
||
| 21 | * @param string $text |
||
| 22 | * |
||
| 23 | * @return array|null |
||
| 24 | */ |
||
| 25 | public function getReport(string $text): ?array |
||
| 26 | { |
||
| 27 | if (preg_match_all( |
||
| 28 | '#\\* <span style="background:\#FCDFE8"><nowiki>([^\n]+)</nowiki></span>\n#', |
||
| 29 | $text, |
||
| 30 | $matches |
||
| 31 | ) > 0 |
||
| 32 | ) { |
||
| 33 | return $matches[1]; |
||
| 34 | } |
||
| 35 | |||
| 36 | return null; |
||
| 37 | } |
||
| 38 | |||
| 39 | public function countErrorInText(array $errors, string $text): int |
||
| 40 | { |
||
| 41 | $found = 0; |
||
| 42 | foreach ($errors as $error) { |
||
| 43 | if (mb_strpos($text, $error) !== false) { |
||
| 44 | $found++; |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | return $found; |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Delete the previous bot errorReporting message from text. |
||
| 53 | * |
||
| 54 | * @param string $text |
||
| 55 | * |
||
| 56 | * @return string |
||
| 57 | */ |
||
| 58 | public function deleteAllReports(string $text): string |
||
| 74 | } |
||
| 75 | |||
| 76 | } |
||
| 77 |