Passed
Push — master ( b3f7dd...feb615 )
by Dispositif
06:47
created

OptimizerFactory::fromTemplate()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
nc 4
nop 3
dl 0
loc 16
rs 10
c 1
b 0
f 0
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
namespace App\Domain;
11
12
use App\Domain\Models\Wiki\ArticleTemplate;
13
use App\Domain\Models\Wiki\LienWebTemplate;
14
use App\Domain\Models\Wiki\OuvrageTemplate;
15
use App\Domain\Models\Wiki\WikiTemplateInterface;
16
use Psr\Log\LoggerInterface;
17
18
/**
19
 * Class OptimizerFactory
20
 */
21
class OptimizerFactory
22
{
23
24
    public static function fromTemplate(
25
        WikiTemplateInterface $template,
26
        ?string $wikiPageTitle = null,
27
        ?LoggerInterface $log = null
28
    ): ?TemplateOptimizerInterface {
29
        if ($template instanceof OuvrageTemplate) {
30
            return new OuvrageOptimize($template, $wikiPageTitle, $log);
31
        }
32
        if ($template instanceof ArticleTemplate) {
33
            return new ArticleOptimizer($template, $wikiPageTitle, $log);
34
        }
35
        if ($template instanceof LienWebTemplate) {
36
            return new LienWebOptimizer($template, $wikiPageTitle, $log);
37
        }
38
39
        return null;
40
    }
41
}
42