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

ControllerTrait::validateJobTimingManager()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.1406

Importance

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