Passed
Branch dev3 (ae391d)
by Dispositif
02:29
created

ArticleRestrictedValidator   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 14
c 1
b 0
f 1
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A validate() 0 11 2
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\InfrastructurePorts\DbAdapterInterface;
15
use App\Application\WikiBotConfig;
16
use App\Application\WikiPageAction;
17
use Psr\Log\LoggerInterface;
18
19
class ArticleRestrictedValidator implements ValidatorInterface
20
{
21
    /**
22
     * @var DbAdapterInterface
23
     */
24
    protected $db;
25
    /**
26
     * @var LoggerInterface
27
     */
28
    protected $log;
29
    /**
30
     * @var string
31
     */
32
    protected $title;
33
    /**
34
     * @var WikiPageAction
35
     */
36
    protected $wikiPageAction;
37
38
    public function __construct(string $title, LoggerInterface $logger, DbAdapterInterface $db, WikiPageAction $wikiPageAction)
39
    {
40
        $this->title = $title;
41
        $this->log = $logger;
42
        $this->db = $db;
43
        $this->wikiPageAction = $wikiPageAction;
44
    }
45
46
    public function validate(): bool
47
    {
48
        if (WikiBotConfig::isEditionTemporaryRestrictedOnWiki($this->wikiPageAction->getText())) {
49
            // new feature ? Gestion d'une repasse dans X jours
50
            $this->log->info("SKIP : protection/3R/travaux.\n");
51
            $this->db->skipArticle($this->title);
52
53
            return false;
54
        }
55
56
        return true;
57
    }
58
}