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

DateHandler   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 14
c 1
b 0
f 0
dl 0
loc 32
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 16 5
A moveDate2Year() 0 6 3
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\Utils\WikiTextUtil;
15
use Exception;
16
17
class DateHandler extends AbstractOuvrageHandler
18
{
19
    public function handle()
20
    {
21
        // dewikification
22
        $params = ['date', 'année', 'mois', 'jour'];
23
        foreach ($params as $param) {
24
            if (
25
                $this->ouvrage->hasParamValue($param)
26
                && WikiTextUtil::isWikify(' ' . $this->ouvrage->getParam($param))
27
            ) {
28
                $this->ouvrage->setParam($param, WikiTextUtil::unWikify($this->ouvrage->getParam($param)));
0 ignored issues
show
Bug introduced by
It seems like $this->ouvrage->getParam($param) can also be of type null; however, parameter $text of App\Domain\Utils\WikiTextUtil::unWikify() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
                $this->ouvrage->setParam($param, WikiTextUtil::unWikify(/** @scrutinizer ignore-type */ $this->ouvrage->getParam($param)));
Loading history...
29
            }
30
        }
31
32
        try {
33
            $this->moveDate2Year();
34
        } catch (Exception $e) {
35
            // nothing (log?)
36
        }
37
    }
38
39
    /**
40
     * Date->année (nécessaire pour OuvrageComplete).
41
     * @throws Exception
42
     */
43
    protected function moveDate2Year()
44
    {
45
        $date = $this->ouvrage->getParam('date') ?? false;
46
        if ($date && preg_match('#^-?[12]\d\d\d$#', $date)) {
47
            $this->ouvrage->setParam('année', $date);
48
            $this->ouvrage->unsetParam('date');
49
            //$this->log('>année');
50
        }
51
    }
52
}