Passed
Branch dev3 (493baa)
by Dispositif
02:30
created

HumanDelayValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 15
c 1
b 0
f 1
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 16 2
A __construct() 0 5 1
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
11
namespace App\Application\OuvrageEdit\Validators;
12
13
14
use App\Application\OuvrageEdit\OuvrageEditWorker;
15
use App\Application\WikiBotConfig;
16
use Psr\Log\LoggerInterface;
17
18
class HumanDelayValidator implements ValidatorInterface
19
{
20
    /**
21
     * @var string
22
     */
23
    protected $title;
24
    /**
25
     * @var WikiBotConfig
26
     */
27
    protected $bot;
28
    /**
29
     * @var LoggerInterface
30
     */
31
    protected $log;
32
33
    public function __construct(string $title, WikiBotConfig $bot)
34
    {
35
        $this->title = $title;
36
        $this->bot = $bot;
37
        $this->log = $bot->getLogger();
38
    }
39
40
    public function validate(): bool
41
    {
42
        if ($this->bot->minutesSinceLastEdit($this->title) < 10) {
43
            // to improve : Gestion d'une repasse dans X jours
44
            $this->log->notice(
45
                sprintf(
46
                    "SKIP : édition humaine dans les dernières %s minutes.\n",
47
                    OuvrageEditWorker::DELAY_MINUTES_AFTER_HUMAN_EDIT
48
                )
49
            );
50
            sleep(60 * OuvrageEditWorker::DELAY_MINUTES_AFTER_HUMAN_EDIT); // hack: waiting cycles
51
52
            return false;
53
        }
54
55
        return true;
56
    }
57
}