Passed
Branch master (fd6b1a)
by Dispositif
03:51 queued 01:13
created

MixLireEnLigne::changeOptiStatus()   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 0
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\Domain\Transformers\Handlers;
12
13
use App\Domain\Models\Wiki\GoogleLivresTemplate;
14
use Exception;
15
16
/**
17
 * Complétion lire/présentation en ligne, si vide.
18
 * Passe Google Book en accès partiel en 'lire en ligne' (sondage)
19
 * @throws Exception
20
 */
21
class MixLireEnLigne extends AbstractMixHandler
22
{
23
    public function handle()
24
    {
25
        // si déjà lire/présentation en ligne => on touche à rien
26
        if ($this->origin->hasParamValue('lire en ligne')
27
            || $this->origin->hasParamValue('présentation en ligne')
28
        ) {
29
            return;
30
        }
31
32
        // completion basique
33
        $booklire = $this->book->getParam('lire en ligne');
34
        if ($booklire) {
35
            $this->origin->setParam('lire en ligne', $booklire);
36
            $this->changeOptiStatus();
37
38
            return;
39
        }
40
41
        $presentation = $this->book->getParam('présentation en ligne') ?? false;
42
        // Ajout du partial Google => mis en lire en ligne
43
        // plutôt que 'présentation en ligne' selon sondage
44
        if (!empty($presentation) && GoogleLivresTemplate::isGoogleBookValue($presentation)) {
45
            $this->origin->setParam('lire en ligne', $presentation);
46
            $this->changeOptiStatus();
47
        }
48
    }
49
50
    protected function changeOptiStatus(): void
51
    {
52
        $this->optiStatus->addSummaryLog('+lire en ligne');
53
        $this->optiStatus->setMajor(true);
54
        $this->optiStatus->setNotCosmetic(true);
55
    }
56
}