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

WebCleanAuthorsHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 14 4
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
}