MixTitle::handle()   C
last analyzed

Complexity

Conditions 14
Paths 5

Size

Total Lines 41
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 41
rs 6.2666
cc 14
nc 5
nop 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Transformers\Handlers;
11
12
use App\Domain\Transformers\OuvrageMixTrait;
13
use App\Domain\Utils\WikiTextUtil;
14
15
class MixTitle extends AbstractMixHandler
16
{
17
    use OuvrageMixTrait;
18
19
    /**
20
     * Add or extract subtitle like in second book.
21
     */
22
    public function handle()
23
    {
24
        if (!$this->book->hasParamValue('sous-titre')
25
            || !$this->origin->hasParamValue('titre')
26
            || !$this->book->hasParamValue('titre')
27
        ) {
28
            return;
29
        }
30
31
        // Skip pour éviter conflit entre 'sous-titre' et 'collection' ou 'titre volume'
32
        if ($this->origin->hasParamValue('titre volume')
33
            || $this->origin->hasParamValue('titre chapitre')
34
            || $this->origin->hasParamValue('titre tome')
35
            || $this->origin->hasParamValue('collection')
36
            || $this->origin->hasParamValue('nature ouvrage')
37
        ) {
38
            return;
39
        }
40
41
        // simple : titres identiques mais sous-titre manquant
42
        // même titre mais sous-titre manquant
43
        if (
44
            $this->stripAll($this->origin->getParam('titre'))
0 ignored issues
show
Bug introduced by
It seems like $this->origin->getParam('titre') can also be of type null; however, parameter $text of App\Domain\Transformers\...rs\MixTitle::stripAll() 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

44
            $this->stripAll(/** @scrutinizer ignore-type */ $this->origin->getParam('titre'))
Loading history...
45
            === $this->stripAll($this->book->getParam('titre'))
46
            && !$this->origin->hasParamValue('sous-titre')
47
        ) {
48
            $this->origin->setParam('sous-titre', $this->book->getParam('sous-titre'));
49
            $this->optiStatus->addSummaryLog('++sous-titre');
50
            $this->optiStatus->setMajor(true);
51
            $this->optiStatus->setNotCosmetic(true);
52
53
            return;
54
        }
55
56
        // compliqué : sous-titre inclus dans titre original => on copie titre/sous-titre de book
57
        // Exclusion wikification "titre=[[Fu : Bar]]" pour éviter => "titre=Fu|sous-titre=Bar"
58
        if ($this->charsFromBigTitle($this->origin) === $this->charsFromBigTitle($this->book)
59
            && !WikiTextUtil::isWikify($this->origin->getParam('titre') ?? '') && !$this->origin->hasParamValue('sous-titre')) {
60
            $this->origin->setParam('titre', $this->book->getParam('titre'));
61
            $this->origin->setParam('sous-titre', $this->book->getParam('sous-titre'));
62
            $this->optiStatus->addSummaryLog('>sous-titre');
63
        }
64
    }
65
}