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

Nip_Form_Renderer_DisplayGroup   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 59
Duplicated Lines 13.56 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 8
loc 59
c 0
b 0
f 0
ccs 0
cts 25
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getElementAttribs() 0 3 1
A render() 0 10 1
A setGroup() 0 4 1
A getGroup() 0 3 1
A renderAttributes() 0 14 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
class Nip_Form_Renderer_DisplayGroup
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...
4
{
5
   
6
    /**
7
     * @var Nip_Form_DisplayGroup
8
     */
9
    protected $_group;
10
11
12
    /**
13
     * @return Nip_Form_Renderer_DisplayGroup
14
     */
15
    public function setGroup(Nip_Form_DisplayGroup $group)
16
    {
17
        $this->_group = $group;
18
        return $this;
19
    }
20
21
    /**
22
     * @return Nip_Form_Renderer_DisplayGroup|null
23
     */
24
    public function getGroup()
25
    {
26
        return $this->_group;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->_group returns the type Nip_Form_DisplayGroup which is incompatible with the documented return type Nip_Form_Renderer_DisplayGroup|null.
Loading history...
27
    }
28
    
29
    public function render()
30
    {
31
        $return = '<fieldset' . $this->renderAttributes() . '>';
32
        $return .= '<legend>' . $this->getGroup()->getLegend() . '</legend>';
0 ignored issues
show
Bug introduced by
The method getLegend() does not exist on Nip_Form_Renderer_DisplayGroup. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        $return .= '<legend>' . $this->getGroup()->/** @scrutinizer ignore-call */ getLegend() . '</legend>';

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
34
        $renderer = clone $this->getGroup()->getForm()->getRenderer();
0 ignored issues
show
Bug introduced by
The method getForm() does not exist on Nip_Form_Renderer_DisplayGroup. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
        $renderer = clone $this->getGroup()->/** @scrutinizer ignore-call */ getForm()->getRenderer();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
        $renderer->setElements($this->getGroup()->toArray());
0 ignored issues
show
Bug introduced by
The method toArray() does not exist on Nip_Form_Renderer_DisplayGroup. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
        $renderer->setElements($this->getGroup()->/** @scrutinizer ignore-call */ toArray());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
36
        $return .= $renderer->renderElements();
37
        $return .= '</fieldset>';
38
        return $return;
39
    }
40
    
41
    public function renderAttributes($overrides = array())
42
    {
43
        $attribs = $this->getGroup()->getAttribs();
0 ignored issues
show
Bug introduced by
The method getAttribs() does not exist on Nip_Form_Renderer_DisplayGroup. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
        $attribs = $this->getGroup()->/** @scrutinizer ignore-call */ getAttribs();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
        $elementAttribs = $this->getElementAttribs();
45
        $return = '';
46
        foreach ($attribs as $name => $value) {
47
            if (in_array($name, $elementAttribs)) {
48
                if (in_array($name, array_keys($overrides))) {
49
                    $value = $overrides[$name];
50
                }
51
                $return .= ' ' . $name . '="' . $value . '"';
52
            }
53
        }
54
        return $return;
55
    }
56
57
    public function getElementAttribs()
58
    {
59
        return array('id', 'style', 'class');
60
    }
61
}
62