Completed
Push — master ( 8431a9...0bccd4 )
by Gabriel
04:28
created

Nip_Form_Renderer_Button_Abstract   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 13
eloc 27
c 1
b 0
f 0
dl 0
loc 92
ccs 0
cts 33
cp 0
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setRenderer() 0 5 1
A render() 0 6 1
A renderAttributes() 0 19 5
A renderItem() 0 5 1
A getRenderer() 0 3 1
A setItem() 0 5 1
A generateItem() 0 3 1
A getItem() 0 3 1
A getItemAttribs() 0 3 1
1
<?php
2
3
use Nip\Form\Renderer\AbstractRenderer;
4
5
/**
6
 * Class Nip_Form_Renderer_Button_Abstract
7
 */
8
abstract class Nip_Form_Renderer_Button_Abstract
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...
9
{
10
    protected $_renderer;
11
12
    protected $_button;
13
14
    /**
15
     * @param AbstractRenderer $renderer
16
     * @return $this
17
     */
18
    public function setRenderer(AbstractRenderer $renderer)
19
    {
20
        $this->_renderer = $renderer;
21
22
        return $this;
23
    }
24
25
    /**
26
     * @return AbstractRenderer
27
     */
28
    public function getRenderer()
29
    {
30
        return $this->_renderer;
31
    }
32
33
    /**
34
     * @param Nip_Form_Button_Abstract $item
35
     * @return $this
36
     */
37
    public function setItem(Nip_Form_Button_Abstract $item)
38
    {
39
        $this->_item = $item;
0 ignored issues
show
Bug Best Practice introduced by
The property _item does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
40
41
        return $this;
42
    }
43
44
    /**
45
     * @return Nip_Form_Button_Abstract
46
     */
47
    public function getItem()
48
    {
49
        return $this->_item;
50
    }
51
52
53
    public function render()
54
    {
55
        $return = '';
56
        $return .= $this->renderItem();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->renderItem() targeting Nip_Form_Renderer_Button_Abstract::renderItem() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
57
58
        return $return;
59
    }
60
61
    public function renderItem()
62
    {
63
        $return = $this->generateItem();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $return is correct as $this->generateItem() targeting Nip_Form_Renderer_Button_Abstract::generateItem() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
64
65
        return $return;
66
    }
67
68
    public function generateItem()
69
    {
70
        return;
71
    }
72
73
    public function renderAttributes($overrides = [])
74
    {
75
        $attribs = $this->getItem()->getAttribs();
76
        if (!isset($attribs['title'])) {
77
            $attribs['title'] = $this->getItem()->getLabel();
78
        }
79
        $itemAttribs = $this->getItemAttribs();
80
        $return = '';
81
        foreach ($attribs as $name => $value) {
82
            if (in_array($name, $itemAttribs)) {
83
                if (in_array($name, array_keys($overrides))) {
84
                    $value = $overrides[$name];
85
                }
86
87
                $return .= ' '.$name.'="'.$value.'"';
88
            }
89
        }
90
91
        return $return;
92
    }
93
94
    /**
95
     * @return array
96
     */
97
    public function getItemAttribs()
98
    {
99
        return ['id', 'name', 'style', 'class', 'title', 'read_only', 'disabled'];
100
    }
101
}
102