Passed
Branch master (35b4f7)
by Dispositif
03:50 queued 01:17
created

WikiTextValidator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 5
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 Psr\Log\LoggerInterface;
16
17
class WikiTextValidator implements ValidatorInterface
18
{
19
    /** @var string|null */
20
    protected $wikiText;
21
    /**
22
     * @var string
23
     */
24
    protected $oldWikiText;
25
    /**
26
     * @var LoggerInterface
27
     */
28
    protected $log;
29
    /**
30
     * @var string
31
     */
32
    protected $title;
33
    /**
34
     * @var DbAdapterInterface
35
     */
36
    protected $db;
37
38
    public function __construct(?string $wikiText, string $oldWikiText, LoggerInterface $logger, string $title, DbAdapterInterface $db)
39
    {
40
        $this->wikiText = $wikiText;
41
        $this->oldWikiText = $oldWikiText;
42
        $this->log = $logger;
43
        $this->title = $title;
44
        $this->db = $db;
45
    }
46
47
    public function validate(): bool
48
    {
49
        if ($this->wikiText === '' || $this->wikiText === '0') {
50
            $this->log->warning("Empty wikitext...");
51
52
            return false;
53
        }
54
        if ($this->wikiText === $this->oldWikiText) {
55
            $this->log->debug("Rien à changer...");
56
            $this->db->skipArticle($this->title);
57
58
            return false;
59
        }
60
61
        return true;
62
    }
63
}