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

ControllerTrait   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 24
c 1
b 1
f 0
dl 0
loc 50
ccs 20
cts 24
cp 0.8333
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 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