Passed
Push — master ( 4d8734...991786 )
by Matthew
09:35 queued 06:44
created

ControllerTrait   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 82.61%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 40
ccs 19
cts 23
cp 0.8261
rs 10
c 0
b 0
f 0
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A validateRunManager() 0 6 2
A addCssJs() 0 7 1
A validateJobTimingManager() 0 8 3
A validateManagerType() 0 5 4
1
<?php
2
3
namespace Dtc\QueueBundle\Controller;
4
5
use Dtc\QueueBundle\Exception\UnsupportedException;
6
7
trait ControllerTrait
8
{
9 1
    protected function validateJobTimingManager()
10
    {
11 1
        if ($this->container->hasParameter('dtc_queue.manager.job_timing')) {
12
            $this->validateManagerType('dtc_queue.manager.job_timing');
13 1
        } elseif ($this->container->hasParameter('dtc_queue.manager.job_timing')) {
14
            $this->validateManagerType('dtc_queue.manager.run');
15
        } else {
16 1
            $this->validateManagerType('dtc_queue.manager.job');
17
        }
18 1
    }
19
20 1
    protected function validateRunManager()
21
    {
22 1
        if ($this->container->hasParameter('dtc_queue.manager.job_timing')) {
23
            $this->validateManagerType('dtc_queue.manager.run');
24
        } else {
25 1
            $this->validateManagerType('dtc_queue.manager.job');
26
        }
27 1
    }
28
29
    /**
30
     * @param string $type
31
     */
32 5
    protected function validateManagerType($type)
33
    {
34 5
        $managerType = $this->container->getParameter($type);
35 5
        if ('mongodb' !== $managerType && 'orm' != $managerType && 'odm' != $managerType) {
36
            throw new UnsupportedException("Unsupported manager type: $managerType");
37
        }
38 5
    }
39
40 7
    protected function addCssJs(array &$params)
41
    {
42 7
        $params['css'] = $this->container->getParameter('dtc_grid.theme.css');
43 7
        $params['js'] = $this->container->getParameter('dtc_grid.theme.js');
44 7
        $jQuery = $this->container->getParameter('dtc_grid.jquery');
45 7
        array_unshift($params['js'], $jQuery['url']);
46 7
        $params['chartjs'] = $this->container->getParameter('dtc_queue.admin.chartjs');
47 7
    }
48
}
49