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

ControllerTrait   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 79.31%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 24
c 1
b 1
f 0
dl 0
loc 50
ccs 23
cts 29
cp 0.7931
rs 10
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 8 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
{
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