Passed
Branch dev3 (6039a0)
by Dispositif
02:46
created

LangParamHandler   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 19
c 1
b 0
f 0
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setLangParam() 0 4 1
B handle() 0 24 9
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
}