Completed
Pull Request — master (#30)
by Matthew
23:29 queued 08:10
created

ControllerTrait   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 1
dl 0
loc 42
ccs 20
cts 24
cp 0.8333
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A validateManagerType() 0 7 4
A addCssJs() 0 8 1
A validateRunManager() 0 8 2
A validateJobTimingManager() 0 10 3
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')) {
0 ignored issues
show
Bug introduced by
The property container does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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.job_timing_manager')) {
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