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

ControllerTrait   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 39
Duplicated Lines 25.64 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 1
dl 10
loc 39
ccs 0
cts 33
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A validateJobTimingManager() 10 10 3
A validateRunManager() 0 8 2
A validateManagerType() 0 7 4
A addCssJs() 0 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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