Passed
Push — master ( 27d925...adfd7e )
by Dispositif
02:31
created

BotWorkerTrait::getSummaryText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
/*
3
 * This file is part of dispositif/wikibot application (@github)
4
 * 2019-2023 © Philippe M./Irønie  <[email protected]>
5
 * For the full copyright and MIT license information, view the license file.
6
 */
7
8
declare(strict_types=1);
9
10
namespace App\Application\Traits;
11
12
use App\Application\WikiBotConfig;
13
use Codedungeon\PHPCliColors\Color;
14
use Mediawiki\Api\UsageException;
15
16
trait BotWorkerTrait
17
{
18
    /**
19
     * @throws UsageException
20
     */
21
    protected function checkAllowedNowEdition(string $title, string $text): bool
22
    {
23
        $this->bot->checkStopOnTalkpage(true);
24
25
        if (WikiBotConfig::isEditionTemporaryRestrictedOnWiki($text)) {
26
            echo "SKIP : protection/3R/travaux.\n";
27
28
            return false;
29
        }
30
        if ($this->bot->minutesSinceLastEdit($title) < static::MINUTES_DELAY_AFTER_LAST_HUMAN_EDIT) {
0 ignored issues
show
Bug introduced by
The constant App\Application\Traits\B...Y_AFTER_LAST_HUMAN_EDIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
31
            echo sprintf(
32
                "SKIP : édition humaine dans les dernières %s minutes\n",
33
                static::MINUTES_DELAY_AFTER_LAST_HUMAN_EDIT
34
            );
35
36
            return false;
37
        }
38
        if (static::SKIP_ADQ && preg_match('#{{ ?En-tête label ?\| ?AdQ#i', $text)) {
0 ignored issues
show
Bug introduced by
The constant App\Application\Traits\BotWorkerTrait::SKIP_ADQ was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
39
            echo "SKIP : AdQ.\n"; // BA ??
40
41
            return false;
42
        }
43
44
        return true;
45
    }
46
47
    protected function printTitle(string $title): void
48
    {
49
        echo "---------------------\n";
50
        echo date('d-m-Y H:i:s') . ' ' . Color::BG_CYAN . "  $title " . Color::NORMAL . "\n";
51
    }
52
53
    protected function canProcessTitleArticle(string $title, ?string $text): bool
54
    {
55
        if (empty($text)) {
56
            echo "Skip : page vide\n";
57
            $this->memorizeAndSaveAnalyzedTitle($title);
0 ignored issues
show
Bug introduced by
It seems like memorizeAndSaveAnalyzedTitle() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
            $this->/** @scrutinizer ignore-call */ 
58
                   memorizeAndSaveAnalyzedTitle($title);
Loading history...
58
59
            return false;
60
        }
61
        if (static::SKIP_LASTEDIT_BY_BOT && $this->pageAction->getLastEditor() === getenv('BOT_NAME')) {
0 ignored issues
show
Bug introduced by
The constant App\Application\Traits\B...t::SKIP_LASTEDIT_BY_BOT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
62
            echo "Skip : bot est le dernier éditeur\n";
63
            $this->memorizeAndSaveAnalyzedTitle($title);
64
65
            return false;
66
        }
67
        if (!$this->checkAllowedNowEdition($title, $text)) {
68
            return false;
69
        }
70
71
        return true;
72
    }
73
74
    protected function isSomethingToChange(?string $text, ?string $newText): bool
75
    {
76
        if (empty($newText)) {
77
            echo "Skip: vide\n";
78
79
            return false;
80
        }
81
        if ($newText === $text) {
82
            echo "Skip: pas de changement\n";
83
84
            return false;
85
        }
86
87
        return true;
88
    }
89
}