Completed
Push — master ( 02819f...5052b0 )
by Gabriel
03:56
created

Nip_Form_DisplayGroup::getForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
use Nip\Collections\Collection;
4
use Nip\Form\AbstractForm;
5
use Nip\Form\Elements\AbstractElement;
6
7
/**
8
 * Class Nip_Form_DisplayGroup
9
 */
10
class Nip_Form_DisplayGroup extends Collection
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
{
12
    use \Nip\Form\Utility\HasAttributesTrait;
13
14
    /**
15
     * @var Nip_Form
16
     */
17
    protected $_form;
18
19
    protected $renderer;
20
21
    /**
22
     * @return Nip_Form|null
23
     */
24
    public function getForm()
25
    {
26
        return $this->_form;
27
    }
28
29
    /**
30
     * @param  AbstractForm $form
31
     * @return Nip_Form_DisplayGroup
32
     */
33 1
    public function setForm(AbstractForm $form)
34
    {
35 1
        $this->_form = $form;
0 ignored issues
show
Documentation Bug introduced by
$form is of type object<Nip\Form\AbstractForm>, but the property $_form was declared to be of type object<Nip_Form>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
36
37 1
        return $this;
38
    }
39
40
    /**
41
     * @param AbstractElement $element
42
     * @return $this
43
     */
44 1
    public function addElement(AbstractElement $element)
45
    {
46 1
        $this[$element->getUniqueId()] = $element;
47
48 1
        return $this;
49
    }
50
51
    /**
52
     * @param string $legend
53
     * @return Nip_Form_DisplayGroup
54
     */
55 1
    public function setLegend($legend)
56
    {
57 1
        return $this->setAttrib('legend', (string)$legend);
58
    }
59
60
    /**
61
     * @return mixed|null
62
     */
63
    public function getLegend()
64
    {
65
        return $this->getAttrib('legend');
66
    }
67
68
    /**
69
     * @return mixed
70
     */
71
    public function render()
72
    {
73
        return $this->getRenderer()->render();
74
    }
75
76
    /**
77
     * @return Nip_Form_Renderer_DisplayGroup
78
     */
79
    public function getRenderer()
80
    {
81
        if (!$this->renderer) {
82
            $this->renderer = $this->getNewRenderer();
83
        }
84
85
        return $this->renderer;
86
    }
87
88
    /**
89
     * @param string $type
90
     * @return Nip_Form_Renderer_DisplayGroup
91
     */
92
    public function getNewRenderer($type = 'basic')
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
93
    {
94
        $name = 'Nip_Form_Renderer_DisplayGroup';
95
        /** @var Nip_Form_Renderer_DisplayGroup $renderer */
96
        $renderer = new $name();
97
        $renderer->setGroup($this);
98
99
        return $renderer;
100
    }
101
}
102