Completed
Push — master ( 4317fb...b1ebb8 )
by Matthew
04:36 queued 02:27
created

ControllerTrait::addCssJs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Dtc\QueueBundle\Controller;
4
5
use Dtc\QueueBundle\Exception\UnsupportedException;
6
7
trait ControllerTrait
8
{
9 View Code Duplication
    protected function validateJobTimingManager()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
    {
11
        if ($this->container->hasParameter('dtc_queue.job_timing_manager')) {
12
            $this->validateManagerType('dtc_queue.job_timing_manager');
13
        } elseif ($this->container->hasParameter('dtc_queue.job_timing_manager')) {
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.run_manager');
15
        } else {
16
            $this->validateManagerType('dtc_queue.default_manager');
17
        }
18
    }
19
20
    protected function validateRunManager()
21
    {
22
        if ($this->container->hasParameter('dtc_queue.job_timing_manager')) {
23
            $this->validateManagerType('dtc_queue.run_manager');
24
        } else {
25
            $this->validateManagerType('dtc_queue.default_manager');
26
        }
27
    }
28
29
    protected function validateManagerType($type)
30
    {
31
        $managerType = $this->container->getParameter($type);
32
        if ('mongodb' !== $managerType && 'orm' != $managerType && 'odm' != $managerType) {
33
            throw new UnsupportedException("Unsupported manager type: $managerType");
34
        }
35
    }
36
37
    protected function addCssJs(array &$params)
38
    {
39
        $params['css'] = $this->container->getParameter('dtc_grid.theme.css');
40
        $params['js'] = $this->container->getParameter('dtc_grid.theme.js');
41
        $jQuery = $this->container->getParameter('dtc_grid.jquery');
42
        array_unshift($params['js'], $jQuery['url']);
43
        $params['chartjs'] = $this->container->getParameter('dtc_queue.admin.chartjs');
44
    }
45
}
46