ControllerTrait::render()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.3332

Importance

Changes 0
Metric Value
cc 3
eloc 5
c 0
b 0
f 0
nc 3
nop 2
dl 0
loc 8
ccs 4
cts 6
cp 0.6667
crap 3.3332
rs 10
1
<?php
2
3
namespace Dtc\QueueBundle\Controller;
4
5
use Dtc\QueueBundle\Exception\UnsupportedException;
6
use Symfony\Component\HttpFoundation\Response;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\Response was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
trait ControllerTrait
9
{
10 7
    protected function render($template, $params)
11
    {
12 7
        if ($this->container->has('templating')) {
13
            return new Response($this->container->get('templating')->render($template, $params));
14 7
        } elseif ($this->container->has('twig')) {
15 7
            return new Response($this->container->get('twig')->render($template, $params));
16
        }
17
        throw new \Exception('Need Twig Bundle or Templating component installed');
18
    }
19
20 1
    protected function validateJobTimingManager()
21
    {
22 1
        if ($this->container->hasParameter('dtc_queue.manager.job_timing') &&
23 1
            $this->container->getParameter('dtc_queue.manager.job_timing')) {
24
            $this->validateManagerType('dtc_queue.manager.job_timing');
25 1
        } elseif ($this->container->hasParameter('dtc_queue.manager.run') &&
26 1
                  $this->container->hasParameter('dtc_queue.manager.run')) {
27
            $this->validateManagerType('dtc_queue.manager.run');
28
        } else {
29 1
            $this->validateManagerType('dtc_queue.manager.job');
30
        }
31 1
    }
32
33 1
    protected function validateRunManager()
34
    {
35 1
        if ($this->container->hasParameter('dtc_queue.manager.job_timing') &&
36 1
            $this->container->getParameter('dtc_queue.manager.job_timing')) {
37
            $this->validateManagerType('dtc_queue.manager.run');
38
        } else {
39 1
            $this->validateManagerType('dtc_queue.manager.job');
40
        }
41 1
    }
42
43
    /**
44
     * @param string $type
45
     */
46 5
    protected function validateManagerType($type)
47
    {
48 5
        $managerType = $this->container->getParameter($type);
49 5
        if ('mongodb' !== $managerType && 'orm' != $managerType && 'odm' != $managerType) {
50
            throw new UnsupportedException("Unsupported manager type: $managerType");
51
        }
52 5
    }
53
54 7
    protected function addCssJs(array &$params)
55
    {
56 7
        $params['css'] = $this->container->getParameter('dtc_grid.theme.css');
57 7
        $params['js'] = $this->container->getParameter('dtc_grid.theme.js');
58 7
        $jQuery = $this->container->getParameter('dtc_grid.jquery');
59 7
        array_unshift($params['js'], $jQuery['url']);
60 7
        $params['chartjs'] = $this->container->getParameter('dtc_queue.admin.chartjs');
61 7
    }
62
}
63