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

LocationHandler   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 20
c 1
b 0
f 0
dl 0
loc 43
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 23 5
A __construct() 0 4 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\InfrastructurePorts\PageListInterface;
13
use App\Domain\Models\Wiki\OuvrageTemplate;
14
use App\Domain\Utils\TextUtil;
15
use App\Domain\Utils\WikiTextUtil;
16
use App\Domain\WikiOptimizer\OptiStatus;
17
use Exception;
18
19
class LocationHandler extends AbstractOuvrageHandler
20
{
21
    public const TRANSLATE_CITY_FR = __DIR__ . '/../../resources/traduction_ville.csv';
22
23
    /**
24
     * @var PageListInterface
25
     */
26
    protected $pageListManager;
27
28
    public function __construct(OuvrageTemplate $ouvrage, OptiStatus $summary, PageListInterface $pageListManager)
29
    {
30
        parent::__construct($ouvrage, $summary);
31
        $this->pageListManager = $pageListManager;
32
    }
33
34
    /**
35
     * Todo: injection dep.
36
     * Todo : "[s. l.]" sans lieu "s.l.n.d." sans lieu ni date.
37
     * @throws Exception
38
     */
39
    public function handle()
40
    {
41
        $location = $this->getParam('lieu');
42
        if (empty($location)) {
43
            return;
44
        }
45
46
        // typo and unwikify
47
        $memo = $location;
48
        $location = WikiTextUtil::unWikify($location);
49
        $location = TextUtil::mb_ucfirst($location);
50
        if ($memo !== $location) {
51
            $this->setParam('lieu', $location);
52
            $this->addSummaryLog('±lieu');
53
            $this->optiStatus->setNotCosmetic(true);
54
        }
55
56
        // translation : "London"->"Londres"
57
        $row = $this->pageListManager->findCSVline(self::TRANSLATE_CITY_FR, $location);
0 ignored issues
show
Bug introduced by
The method findCSVline() does not exist on App\Domain\InfrastructurePorts\PageListInterface. It seems like you code against a sub-type of App\Domain\InfrastructurePorts\PageListInterface such as App\Infrastructure\FileManager. ( Ignorable by Annotation )

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

57
        /** @scrutinizer ignore-call */ 
58
        $row = $this->pageListManager->findCSVline(self::TRANSLATE_CITY_FR, $location);
Loading history...
58
        if ($row !== [] && !empty($row[1])) {
59
            $this->setParam('lieu', $row[1]);
60
            $this->addSummaryLog('lieu francisé');
61
            $this->notCosmetic = true;
0 ignored issues
show
Bug Best Practice introduced by
The property notCosmetic does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
62
        }
63
    }
64
}