Completed
Pull Request — master (#127)
by Matthew
16:03
created

ControllerTrait   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 24
dl 0
loc 49
ccs 20
cts 24
cp 0.8333
rs 10
c 1
b 1
f 0
wmc 13

5 Methods

Rating   Name   Duplication   Size   Complexity  
A validateRunManager() 0 6 2
A addCssJs() 0 7 1
A validateJobTimingManager() 0 8 3
A render() 0 7 3
A validateManagerType() 0 5 4
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