TemplateFactory::create()   A
last analyzed

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 see in Templates class.
16
     *
17
     * @return TemplateInterface
18
     * @throws FlashTemplateNotFoundException
19
     */
20 61
    public static function create(string $name = Templates::BASE): TemplateInterface
21
    {
22 61
        $class = __NAMESPACE__ . '\\Templates\\' . ucwords($name) . 'Template';
23
24 61
        if (class_exists($class)) {
25 60
            return new $class();
26
        }
27
28 1
        throw new FlashTemplateNotFoundException("Template \"{$name}\" not found!");
29
    }
30
}
31