Passed
Push — master ( 33798c...96726b )
by Yuri
03:51
created

TemplateFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
c 1
b 0
f 1
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 123
    public static function create($name = Templates::BASE)
21
    {
22 123
        $class = __NAMESPACE__ . '\\Templates\\' . ucwords($name) . 'Template';
23
24 123
        if (class_exists($class)) {
25 120
            return new $class();
26
        }
27
28 3
        throw new FlashTemplateNotFoundException("Template \"{$name}\" not found!");
29
    }
30
}
31