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

CitationsAllCompletedValidator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 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
}