TemplateFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
dl 0
loc 19
ccs 5
cts 5
cp 1
rs 10
c 1
b 0
f 1
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 2
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