Test Failed
Push — master ( a58c94...1bcec0 )
by Brent
03:26
created

TemplateEngineFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B getByType() 0 24 5
1
<?php
2
3
namespace Brendt\Stitcher\Factory;
4
5
use Brendt\Stitcher\Exception\UnknownEngineException;
6
use Brendt\Stitcher\Template\smarty\SmartyEngine;
7
use Brendt\Stitcher\Template\TemplateEngine;
8
use Brendt\Stitcher\Template\twig\TwigEngine;
9
10
class TemplateEngineFactory {
11
12
    const SMARTY_ENGINE = 'smarty';
13
14
    const TWIG_ENGINE = 'twig';
15
16
    private $engines;
17
18
    /**
19
     * @param $type
20
     *
21
     * @return TemplateEngine
22
     * @throws UnknownEngineException
23
     */
24
    public function getByType($type) {
25
        if (isset($this->engines[$type])) {
26
            return $this->engines[$type];
27
        }
28
29
        switch ($type) {
30
            case self::TWIG_ENGINE:
31
                $engine = new TwigEngine();
32
33
                break;
34
            case self::SMARTY_ENGINE:
35
                $engine = new SmartyEngine();
36
37
                break;
38
            default:
39
                throw new UnknownEngineException();
40
        }
41
42
        if ($engine) {
43
            $this->engines[$type] = $engine;
44
        }
45
46
        return $engine;
47
    }
48
49
}
50