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

CitationsAllCompletedValidator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isCitationCompleted() 0 11 4
A __construct() 0 4 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
14
class CitationsAllCompletedValidator implements ValidatorInterface
15
{
16
    /**
17
     * @var array
18
     */
19
    protected $citationCollection;
20
    /**
21
     * @var DbAdapterInterface
22
     */
23
    protected $db;
24
25
    public function __construct(array $citationCollection, DbAdapterInterface $db)
26
    {
27
        $this->citationCollection = $citationCollection;
28
        $this->db = $db;
29
    }
30
31
    public function validate(): bool
32
    {
33
        foreach ($this->citationCollection as $citation) {
34
            if (!$this->isCitationCompleted($citation)) {
35
                $this->log->warning("SKIP : Amélioration incomplet de l'article. sleep 10min");
0 ignored issues
show
Bug Best Practice introduced by
The property log does not exist on App\Application\OuvrageE...nsAllCompletedValidator. Did you maybe forget to declare it?
Loading history...
36
                sleep(600); // todo move/event
37
38
                return false;
39
            }
40
        }
41
        return true;
42
    }
43
44
    protected function isCitationCompleted(array $pageOuvrage): bool
45
    {
46
        // hack temporaire pour éviter articles dont CompleteProcess incomplet
47
        if (
48
            empty($pageOuvrage['opti'])
49
            || empty($pageOuvrage['optidate'])
50
            || $pageOuvrage['optidate'] < $this->db->getOptiValidDate()
51
        ) {
52
            return false;
53
        }
54
        return true;
55
    }
56
}