Passed
Push — master ( 003724...f241d1 )
by Brent
02:47
created

TemplateEngineFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getByType() 0 10 3
A getDefault() 0 3 1
1
<?php
2
3
namespace Brendt\Stitcher\Factory;
4
5
use Brendt\Stitcher\Exception\UnknownEngineException;
6
use Brendt\Stitcher\Template\TemplateEngine;
7
use Symfony\Component\DependencyInjection\ContainerInterface;
8
9
class TemplateEngineFactory
10
{
11
    const SMARTY_ENGINE = 'smarty';
12
    const TWIG_ENGINE = 'twig';
13
14
    /**
15
     * @var ContainerInterface
16
     */
17
    private $container;
18
19
    /**
20
     * @var string
21
     */
22
    private $templateEngine;
23
24
    /**
25
     * TemplateEngineFactory constructor.
26
     *
27
     * @param ContainerInterface $container
28
     * @param string             $templateEngine
29
     */
30
    public function __construct(ContainerInterface $container, string $templateEngine) {
31
        $this->container = $container;
32
        $this->templateEngine = $templateEngine;
33
    }
34
35
    /**
36
     * @param $type
37
     *
38
     * @return mixed
39
     *
40
     * @throws UnknownEngineException
41
     */
42
    public function getByType($type) : TemplateEngine {
43
        switch ($type) {
44
            case self::TWIG_ENGINE:
45
                return $this->container->get('service.twig');
46
            case self::SMARTY_ENGINE:
47
                return $this->container->get('service.smarty');
48
            default:
49
                throw new UnknownEngineException();
50
        }
51
    }
52
53
    /**
54
     * @return TemplateEngine
55
     */
56
    public function getDefault() : TemplateEngine {
57
        return $this->getByType($this->templateEngine);
58
    }
59
60
}
61