FrontRender   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 4
c 2
b 0
f 2
lcom 1
cbo 4
dl 0
loc 64
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setParameters() 0 6 1
A render() 0 12 2
1
<?php
2
3
namespace Chris\Bundle\FrontRenderBundle\Render;
4
5
use Chris\Bundle\FrontRenderBundle\Event\BeforeRenderEvent;
6
use Chris\Bundle\FrontRenderBundle\Exception\FrontRenderException;
7
use Chris\Bundle\FrontRenderBundle\FrontRenderEvents;
8
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
9
use Symfony\Component\Templating\EngineInterface;
10
11
class FrontRender
12
{
13
    /**
14
     * @var EngineInterface $twig
15
     */
16
    protected $engine;
17
18
    /**
19
     * @var string $frontPath
20
     */
21
    protected $frontPath;
22
23
    /**
24
     * @var EventDispatcherInterface $dispatcher
25
     */
26
    protected $dispatcher;
27
28
    /**
29
     * @var array $parameters
30
     */
31
    protected $parameters = [];
32
33
    /**
34
     * @param EngineInterface          $engine
35
     * @param EventDispatcherInterface $dispatcher
36
     * @param string                   $frontPath
37
     */
38 8
    public function __construct(EngineInterface $engine, EventDispatcherInterface $dispatcher, $frontPath)
39
    {
40 8
        $this->engine     = $engine;
41 8
        $this->dispatcher = $dispatcher;
42 8
        $this->frontPath  = $frontPath;
43 8
    }
44
45
    /**
46
     * Set Parameters
47
     *
48
     * @param array $parameters
49
     *
50
     * @return $this
51
     */
52 4
    public function setParameters($parameters)
53
    {
54 4
        $this->parameters = $parameters;
55
56 4
        return $this;
57
    }
58
59
    /**
60
     * @return string
61
     */
62 8
    public function render()
63
    {
64 8
        $event = new BeforeRenderEvent($this->frontPath);
65 8
        $this->dispatcher->dispatch(FrontRenderEvents::BEFORE_RENDER, $event);
66
67 8
        $frontPath = $event->getFrontPath();
68 8
        if (empty($frontPath)) {
69 1
            throw new FrontRenderException('You need to configure a front path.');
70
        }
71
72 7
        return $this->engine->render($frontPath, $this->parameters);
73
    }
74
}
75