Passed
Push — master ( 2d0039...fd6b1a )
by Dispositif
02:43
created

OuvrageMix   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 20
c 0
b 0
f 0
dl 0
loc 59
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSummaryLog() 0 3 1
A __construct() 0 5 1
A getResult() 0 5 1
A complete() 0 14 2
A getOptiStatus() 0 3 1
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\Domain\Transformers;
11
12
use App\Domain\Models\Wiki\OuvrageTemplate;
13
use App\Domain\Transformers\Handlers\OuvrageMixComposite;
14
use App\Domain\Transformers\Validator\SameBookValidator;
15
use App\Domain\WikiOptimizer\OptiStatus;
16
use Psr\Log\LoggerInterface;
17
use Psr\Log\NullLogger;
18
19
class OuvrageMix
20
{
21
    use OuvrageMixTrait;
22
23
    /**
24
     * @var OptiStatus
25
     */
26
    protected $optiStatus;
27
    /**
28
     * @var OuvrageTemplate
29
     */
30
    private $origin;
31
    /**
32
     * @var OuvrageTemplate
33
     */
34
    private $book;
35
    /**
36
     * @var LoggerInterface|NullLogger
37
     */
38
    private $log;
39
40
    public function __construct(OuvrageTemplate $origin, OuvrageTemplate $book, ?LoggerInterface $log = null)
41
    {
42
        $this->origin = clone $origin;
43
        $this->book = $book;
44
        $this->log = $log ?? new NullLogger();
45
    }
46
47
    public function getSummaryLog(): array
48
    {
49
        return $this->optiStatus->getSummary();
50
    }
51
52
    public function getResult(): OuvrageTemplate
53
    {
54
        $this->complete();
55
56
        return $this->origin;
57
    }
58
59
    private function complete(): bool
60
    {
61
        $this->optiStatus = new OptiStatus();
62
63
        if (!(new SameBookValidator($this->origin, $this->book))->validate()) {
64
            $this->log->info('not same book');
65
66
            return false;
67
        }
68
69
        (new OuvrageMixComposite($this->origin, $this->book, $this->log, $this->optiStatus))
70
            ->handle();
71
72
        return true;
73
    }
74
75
    public function getOptiStatus(): OptiStatus
76
    {
77
        return $this->optiStatus;
78
    }
79
}
80