Passed
Push — master ( a766ea...cd664b )
by Dispositif
03:23
created

WikiTemplateFactory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 8
c 1
b 0
f 0
dl 0
loc 16
ccs 7
cts 7
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 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;
11
12
use App\Domain\Models\Wiki\AbstractWikiTemplate;
13
use App\Domain\Models\Wiki\ArticleTemplate;
14
use App\Domain\Models\Wiki\GoogleLivresTemplate;
15
use App\Domain\Models\Wiki\LienBriseTemplate;
16
use App\Domain\Models\Wiki\LienWebTemplate;
17
use App\Domain\Models\Wiki\OuvrageTemplate;
18
use Exception;
19
use LogicException;
20
21
/**
22
 * Class WikiTemplateFactory.
23
 */
24
abstract class WikiTemplateFactory
25
{
26
    /**
27
     *
28
     * @return AbstractWikiTemplate|null
29
     * @throws Exception
30
     */
31
    public static function create(string $templateName): ?AbstractWikiTemplate
32 75
    {
33
        return match (mb_strtolower($templateName)) {
34 75
            'ouvrage' => new OuvrageTemplate(),
35 75
            'article' => new ArticleTemplate(),
36 70
            'lien web' => new LienWebTemplate(),
37 8
            'lien brise', 'lien brisé' => new LienBriseTemplate(),
38 4
            'google livres', 'google books' => new GoogleLivresTemplate(),
39 4
            default => throw new LogicException('template "'.$templateName.'" unknown'),
40 4
        };
41
    }
42
}
43