Completed
Pull Request — master (#30)
by Matthew
48:21 queued 02:09
created

ControllerTrait::validateManagerType()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4.128

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 5
cp 0.8
rs 9.2
c 0
b 0
f 0
cc 4
eloc 4
nc 2
nop 1
crap 4.128
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