Passed
Push — master ( 309757...35b4f7 )
by Dispositif
02:30
created

CitationsAllCompletedValidator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 19
c 1
b 0
f 0
dl 0
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isCitationCompleted() 0 11 4
A __construct() 0 5 1
A validate() 0 11 3
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\OuvrageEdit\Validators;
11
12
use App\Application\InfrastructurePorts\DbAdapterInterface;
13
use Psr\Log\LoggerInterface;
14
15
class CitationsAllCompletedValidator implements ValidatorInterface
16
{
17
    /**
18
     * @var array
19
     */
20
    protected $citationCollection;
21
    /**
22
     * @var DbAdapterInterface
23
     */
24
    protected $db;
25
    /**
26
     * @var LoggerInterface
27
     */
28
    protected $log;
29
30
    public function __construct(array $citationCollection, LoggerInterface $log, DbAdapterInterface $db)
31
    {
32
        $this->citationCollection = $citationCollection;
33
        $this->log = $log;
34
        $this->db = $db;
35
    }
36
37
    public function validate(): bool
38
    {
39
        foreach ($this->citationCollection as $citation) {
40
            if (!$this->isCitationCompleted($citation)) {
41
                $this->log->warning("SKIP : Amélioration incomplet de l'article. sleep 10min");
42
                sleep(600); // todo move/event
43
44
                return false;
45
            }
46
        }
47
        return true;
48
    }
49
50
    protected function isCitationCompleted(array $pageOuvrage): bool
51
    {
52
        // hack temporaire pour éviter articles dont CompleteProcess incomplet
53
        if (
54
            empty($pageOuvrage['opti'])
55
            || empty($pageOuvrage['optidate'])
56
            || $pageOuvrage['optidate'] < $this->db->getOptiValidDate()
57
        ) {
58
            return false;
59
        }
60
        return true;
61
    }
62
}