Passed
Branch master (ee24dc)
by Dispositif
03:19 queued 39s
created

LangParamHandler::setLangParam()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 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
11
namespace App\Domain\WikiOptimizer\Handlers;
12
13
14
use App\Domain\Enums\Language;
15
use App\Domain\WikiOptimizer\OuvrageOptimize;
16
17
class LangParamHandler extends AbstractOuvrageHandler
18
{
19
    protected $langParam = 'langue';
20
21
    public function setLangParam(string $langParam = 'langue'): LangParamHandler
22
    {
23
        $this->langParam = $langParam;
24
        return $this;
25
    }
26
27
    public function handle()
28
    {
29
        $lang = $this->ouvrage->getParam($this->langParam) ?? null;
30
31
        if ($lang) {
32
            $lang2 = Language::all2wiki($lang);
33
34
            // strip "langue originale=fr"
35
            if (
36
                'langue originale' === $this->langParam
37
                && OuvrageOptimize::WIKI_LANGUAGE === $lang2
38
                && (
39
                    !$this->ouvrage->getParam('langue')
40
                    || $this->ouvrage->getParam('langue') === $lang2
41
                )
42
            ) {
43
                $this->ouvrage->unsetParam('langue originale');
44
                $this->optiStatus->addSummaryLog('-langue originale');
45
            }
46
47
            if ($lang2 && $lang !== $lang2) {
48
                $this->ouvrage->setParam($this->langParam, $lang2);
49
                if (OuvrageOptimize::WIKI_LANGUAGE !== $lang2) {
50
                    $this->optiStatus->addSummaryLog('±' . $this->langParam);
51
                }
52
            }
53
        }
54
    }
55
}