Completed
Pull Request — master (#97)
by
unknown
06:51
created

TComponentView   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 20
lcom 1
cbo 1
dl 0
loc 55
c 2
b 1
f 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getViewData() 0 6 1
A getRenderSection() 0 4 1
A setRenderSection() 0 5 1
1
<?php
2
namespace Nayjest\Grids\Components\Base;
3
4
trait TComponentView
5
{
6
    use TRenderable {
7
        TRenderable::getTemplate as private getTemplateInternal;
8
    }
9
10
    protected $render_section;
11
12
    /**
13
     * Returns variables for usage inside view template.
14
     *
15
     * @return array
16
     */
17
    protected function getViewData()
18
    {
19
        return $this->grid->getViewData() + [
0 ignored issues
show
Bug introduced by
The property grid 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...
20
            'component' => $this
21
        ];
22
    }
23
24
    /**
25
     * Returns name of view template.
26
     *
27
     * @return string
28
     */
29
    public function getTemplate()
30
    {
31
        $grid_tpl = $this->grid->getConfig()->getTemplate();
32
        return str_replace('*.',"$grid_tpl.", $this->template);
33
    }
34
35
    /**
36
     * Returns name of section in parent component
37
     * where this component must be rendered.
38
     *
39
     * @return string|null
40
     */
41
    public function getRenderSection()
42
    {
43
        return $this->render_section;
44
    }
45
46
    /**
47
     * Sets name of section in parent component
48
     * where this component must be rendered.
49
     *
50
     * @param string|null $sectionName
51
     * @return $this
52
     */
53
    public function setRenderSection($sectionName)
54
    {
55
        $this->render_section = $sectionName;
56
        return $this;
57
    }
58
}
59