Completed
Push — master ( 43d6c5...49981b )
by Yuri
02:20
created

TemplateFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.2109

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 10
ccs 5
cts 8
cp 0.625
crap 2.2109
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Tamtamchik\SimpleFlash;
4
5
use Tamtamchik\SimpleFlash\Exceptions\FlashTemplateNotFoundException;
6
7
/**
8
 * Class TemplateFactory.
9
 */
10
class TemplateFactory
11
{
12
    /**
13
     * Return template from available list of templates.
14
     *
15
     * @param string $name - available templates: bootstrap3, bootstrap4, foundation5, foundation6, semantic2, uikit2
16
     *
17
     * @return TemplateInterface
18
     * @throws FlashTemplateNotFoundException
19
     */
20 82
    public static function create($name = Templates::BASE)
21
    {
22 82
        $class = __NAMESPACE__ . '\\Templates\\' . ucwords($name) . 'Template';
23
24 82
        if (class_exists($class)) {
25 80
            return new $class();
26
        }
27
28 2
        throw new FlashTemplateNotFoundException("Template \"{$name}\" not found!");
29
    }
30
}
31