Passed
Push — master ( 42303c...a9e041 )
by Dispositif
02:43
created

WebCleanAuthorsHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
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
namespace App\Domain\WikiOptimizer\Handlers;
11
12
use App\Domain\Models\Wiki\LienWebTemplate;
13
use App\Domain\Utils\WikiTextUtil;
14
15
class WebCleanAuthorsHandler implements OptimizeHandlerInterface
16
{
17
    /**
18
     * @var LienWebTemplate
19
     */
20
    protected $template;
21
22
    public function __construct(LienWebTemplate $template)
23
    {
24
        $this->template = $template;
25
    }
26
27
    public function handle()
28
    {
29
        if (in_array($this->template->getParam('auteur1'), ['Rédaction', 'La Rédaction'])) {
30
            $this->template->unsetParam('auteur1');
31
        }
32
        // doublon auteur - site  ou doublon auteur - périodique
33
        if ((WikiTextUtil::unWikify($this->template->getParam('auteur1') ?? '') === WikiTextUtil::unWikify(
34
                    $this->template->getParam('site') ?? ''
35
                ))
36
            || (WikiTextUtil::unWikify($this->template->getParam('auteur1') ?? '') === WikiTextUtil::unWikify(
37
                    $this->template->getParam('périodique') ?? ''
38
                ))
39
        ) {
40
            $this->template->unsetParam('auteur1');
41
        }
42
    }
43
}