TwigBlockGridColumn   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
eloc 19
c 2
b 0
f 1
dl 0
loc 51
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A getBlockName() 0 3 1
A getTemplate() 0 3 1
A format() 0 9 2
1
<?php
2
3
namespace Dtc\GridBundle\Grid\Column;
4
5
use Dtc\GridBundle\Grid\Source\GridSourceInterface;
6
use Twig_Template;
0 ignored issues
show
Bug introduced by
The type Twig_Template 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
class TwigBlockGridColumn extends AbstractGridColumn
9
{
10
    protected $template;
11
    protected $blockName;
12
    protected $env = [];
13
14
    /**
15
     * Block name.
16
     *
17
     * @param string $field
18
     * @param string $label
19
     * @param string $blockName
20
     */
21
    public function __construct($field, $label, Twig_Template $template, array $env, $blockName = null)
22
    {
23
        $this->field = $field;
24
        $this->label = $label;
25
        $this->template = $template;
26
        $this->blockName = $blockName;
27
        $this->env = $env;
28
29
        if (!$this->blockName) {
30
            $this->blockName = $field;
31
        }
32
    }
33
34
    /**
35
     * @return $template
0 ignored issues
show
Documentation Bug introduced by
The doc comment $template at position 0 could not be parsed: Unknown type name '$template' at position 0 in $template.
Loading history...
36
     */
37
    public function getTemplate()
38
    {
39
        return $this->template;
40
    }
41
42
    /**
43
     * @return $blockName
0 ignored issues
show
Documentation Bug introduced by
The doc comment $blockName at position 0 could not be parsed: Unknown type name '$blockName' at position 0 in $blockName.
Loading history...
44
     */
45
    public function getBlockName()
46
    {
47
        return $this->blockName;
48
    }
49
50
    public function format($object, GridSourceInterface $gridSource)
51
    {
52
        if ($this->template->hasBlock($this->blockName, [])) {
53
            $this->env['obj'] = $object;
54
            $this->env['source'] = $gridSource;
55
56
            return $this->template->renderBlock($this->blockName, $this->env);
57
        } else {
58
            return 'No Template';
59
        }
60
    }
61
}
62