Completed
Pull Request — master (#127)
by Matthew
17:36
created

ControllerTrait::render()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.576

Importance

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