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

ExternalTemplateHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 28
c 1
b 0
f 0
dl 0
loc 50
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 41 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
11
namespace App\Domain\WikiOptimizer\Handlers;
12
13
use Exception;
14
15
class ExternalTemplateHandler extends AbstractOuvrageHandler
16
{
17
    /**
18
     * TODO move+refac
19
     * TODO CommentaireBiblioTemplate  ExtraitTemplate
20
     * Probleme {{commentaire biblio}} <> {{commentaire biblio SRL}}
21
     * Generate supplementary templates from obsoletes params.
22
     * @throws Exception
23
     */
24
    public function handle()
25
    {
26
        // "extrait=bla" => {{citation bloc|bla}}
27
        if ($this->hasParamValue('extrait')) {
28
            $extrait = $this->getParam('extrait');
29
            // todo bug {{citation bloc}} si "=" ou "|" dans texte de citation
30
            // Legacy : use {{début citation}} ... {{fin citation}}
31
            if (preg_match('#[=|]#', $extrait) > 0) {
0 ignored issues
show
Bug introduced by
It seems like $extrait can also be of type null; however, parameter $subject of preg_match() 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

31
            if (preg_match('#[=|]#', /** @scrutinizer ignore-type */ $extrait) > 0) {
Loading history...
32
                $this->ouvrage->externalTemplates[] = (object)[
33
                    'template' => 'début citation',
34
                    '1' => '',
35
                    'raw' => '{{Début citation}}' . $extrait . '{{Fin citation}}',
36
                ];
37
                $this->addSummaryLog('{Début citation}');
38
                $this->optiStatus->setNotCosmetic(true);
39
            } else {
40
                // StdClass
41
                $this->ouvrage->externalTemplates[] = (object)[
42
                    'template' => 'citation bloc',
43
                    '1' => $extrait,
44
                    'raw' => '{{Citation bloc|' . $extrait . '}}',
45
                ];
46
                $this->addSummaryLog('{Citation bloc}');
47
                $this->optiStatus->setNotCosmetic(true);
48
            }
49
50
            $this->unsetParam('extrait');
51
            $this->optiStatus->setNotCosmetic(true);
52
        }
53
54
        // "commentaire=bla" => {{Commentaire biblio|1=bla}}
55
        if ($this->hasParamValue('commentaire')) {
56
            $commentaire = $this->getParam('commentaire');
57
            $this->ouvrage->externalTemplates[] = (object)[
58
                'template' => 'commentaire biblio',
59
                '1' => $commentaire,
60
                'raw' => '{{Commentaire biblio|' . $commentaire . '}}',
61
            ];
62
            $this->unsetParam('commentaire');
63
            $this->addSummaryLog('{commentaire}');
64
            $this->optiStatus->setNotCosmetic(true);
65
        }
66
    }
67
}