Passed
Branch master (fd6b1a)
by Dispositif
03:51 queued 01:13
created

OuvrageMixTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A stripAll() 0 6 1
A charsFromBigTitle() 0 5 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\Transformers;
11
12
use App\Domain\Models\Wiki\OuvrageTemplate;
13
use App\Domain\Utils\TextUtil;
14
use Normalizer;
15
16
trait OuvrageMixTrait
17
{
18
    /**
19
     * "L'élan & la Biche" => "lelanlabiche".
20
     */
21
    private function stripAll(string $text): string
22
    {
23
        $text = str_replace([' and ', ' et ', '&'], '', $text);
24
        $text = str_replace(' ', '', $text);
25
26
        return mb_strtolower(TextUtil::stripPunctuation(TextUtil::stripAccents($text)));
27
    }
28
29
    private function charsFromBigTitle(OuvrageTemplate $ouvrage): string
30
    {
31
        $text = $ouvrage->getParam('titre').$ouvrage->getParam('sous-titre');
32
33
        return $this->stripAll(Normalizer::normalize($text));
34
    }
35
}