Passed
Push — master ( 10a888...e30075 )
by Matthew
06:51
created

ControllerTrait::render()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.3332

Importance

Changes 0
Metric Value
cc 3
eloc 5
c 0
b 0
f 0
nc 3
nop 2
dl 0
loc 8
ccs 4
cts 6
cp 0.6667
crap 3.3332
rs 10
1
<?php
2
3
namespace Dtc\QueueBundle\Controller;
4
5
use Dtc\QueueBundle\Exception\UnsupportedException;
6
use Symfony\Component\HttpFoundation\Response;
7
8
trait ControllerTrait
9
{
10 7
    protected function render($template, $params)
11
    {
12 7
        if ($this->container->has('templating')) {
13
            return new Response($this->container->get('templating')->render($template, $params));
14 7
        } elseif ($this->container->has('twig')) {
15 7
            return new Response($this->container->get('twig')->render($template, $params));
16
        }
17
        throw new \Exception('Need Twig Bundle or Templating component installed');
18
    }
19
20 1
    protected function validateJobTimingManager()
21
    {
22 1
        if ($this->container->hasParameter('dtc_queue.manager.job_timing')) {
23
            $this->validateManagerType('dtc_queue.manager.job_timing');
24 1
        } elseif ($this->container->hasParameter('dtc_queue.manager.job_timing')) {
25
            $this->validateManagerType('dtc_queue.manager.run');
26
        } else {
27 1
            $this->validateManagerType('dtc_queue.manager.job');
28
        }
29 1
    }
30
31 1
    protected function validateRunManager()
32
    {
33 1
        if ($this->container->hasParameter('dtc_queue.manager.job_timing')) {
34
            $this->validateManagerType('dtc_queue.manager.run');
35
        } else {
36 1
            $this->validateManagerType('dtc_queue.manager.job');
37
        }
38 1
    }
39
40
    /**
41
     * @param string $type
42
     */
43 5
    protected function validateManagerType($type)
44
    {
45 5
        $managerType = $this->container->getParameter($type);
46 5
        if ('mongodb' !== $managerType && 'orm' != $managerType && 'odm' != $managerType) {
47
            throw new UnsupportedException("Unsupported manager type: $managerType");
48
        }
49 5
    }
50
51 7
    protected function addCssJs(array &$params)
52
    {
53 7
        $params['css'] = $this->container->getParameter('dtc_grid.theme.css');
54 7
        $params['js'] = $this->container->getParameter('dtc_grid.theme.js');
55 7
        $jQuery = $this->container->getParameter('dtc_grid.jquery');
56 7
        array_unshift($params['js'], $jQuery['url']);
57 7
        $params['chartjs'] = $this->container->getParameter('dtc_queue.admin.chartjs');
58 7
    }
59
}
60