Passed
Branch dev (b7aeac)
by Dispositif
03:10
created

BiblioTemplateTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSpanInitial() 0 15 3
A anneeOrDateSerialize() 0 9 3
1
<?php
2
/**
3
 * This file is part of dispositif/wikibot application (@github)
4
 * 2019/2020 © Philippe M. <[email protected]>
5
 * For the full copyright and MIT license information, please view the license file.
6
 */
7
8
declare(strict_types=1);
9
10
11
namespace App\Domain\Models\Wiki;
12
13
/**
14
 * Trait BiblioTemplateTrait
15
 */
16
trait BiblioTemplateTrait
17
{
18
    /**
19
     * Pas de serialization année vide si date non vide.
20
     *
21
     * @param string $serial
22
     *
23
     * @return string
24
     */
25
    private function anneeOrDateSerialize(string $serial): string
26
    {
27
        if (preg_match("#\|[\n ]*année=[\n ]*\|#", $serial) > 0
28
            && preg_match("#\|[\n ]*date=#", $serial) > 0
29
        ) {
30
            $serial = preg_replace("#\|[\n ]*année=[\n ]*#", '', $serial);
31
        }
32
33
        return $serial;
34
    }
35
36
    /**
37
     * Détermine l'id d'ancrage <span> de l'ouvrage.
38
     * Utilisable par titre#ancrage ou {{harvsp}}.
39
     * Voir http://fr.wikipedia.org/wiki/Modèle:Module_biblio/span_initial.
40
     */
41
    public function getSpanInitial(): string
42
    {
43
        // Identifiant paramétré
44
        if (!empty($this->getParam('id'))) {
1 ignored issue
show
Bug introduced by
It seems like getParam() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

44
        if (!empty($this->/** @scrutinizer ignore-call */ getParam('id'))) {
Loading history...
45
            return $this->getParam('id');
46
        }
47
48
        // Identifiant déduit : auteur1,2,3,4,année
49
        $id = '';
50
        for ($i = 1; $i < 4; ++$i) {
51
            $id .= ($this->getParam('nom'.$i)) ?? $this->getParam('auteur'.$i) ?? '';
52
        }
53
        $id .= $this->getParam('année') ?? '';
54
55
        return $id;
56
    }
57
58
}
59