Completed
Push — master ( 9e4d7b...c3f58e )
by Gabriel
03:57 queued 11s
created

HasRendererTrait::renderElement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Nip\Form\Elements\Traits;
4
5
use Nip\Form\Renderer\Elements\AbstractElementRenderer;
6
7
/**
8
 * Trait HasRendererTrait
9
 * @package Nip\Form\Elements\Traits
10
 */
11
trait HasRendererTrait
12
{
13
    protected $_isRendered = false;
14
15
    /**
16
     * @param boolean $isRendered
17
     * @return $this
18
     */
19 8
    public function setRendered($isRendered)
20
    {
21 8
        $this->_isRendered = (bool)$isRendered;
22
23 8
        return $this;
24
    }
25
26
    /**
27
     * @return bool
28
     */
29 1
    public function isRendered()
30
    {
31 1
        return (bool)$this->_isRendered;
32
    }
33
34
    /**
35
     * @return bool
36
     */
37 1
    public function hasCustomRenderer()
38
    {
39 1
        return false;
40
    }
41
42
    /**
43
     * @return mixed
44
     */
45 5
    public function render()
46
    {
47 5
        return $this->getRenderer()->render($this);
0 ignored issues
show
Unused Code introduced by
The call to Nip\Form\Renderer\Elemen...ementRenderer::render() has too many arguments starting with $this. ( Ignorable by Annotation )

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

47
        return $this->getRenderer()->/** @scrutinizer ignore-call */ render($this);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
48
    }
49
50
    /**
51
     * @return AbstractElementRenderer
52
     */
53 6
    public function getRenderer()
54
    {
55 6
        return $this->getForm()->getRenderer()->getElementRenderer($this);
0 ignored issues
show
Bug introduced by
It seems like getForm() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

55
        return $this->/** @scrutinizer ignore-call */ getForm()->getRenderer()->getElementRenderer($this);
Loading history...
56
    }
57
58
    /**
59
     * @return mixed
60
     */
61 1
    public function renderElement()
62
    {
63 1
        return $this->getRenderer()->renderElement();
64
    }
65
66
    /**
67
     * @return mixed
68
     */
69 1
    public function renderErrors()
70
    {
71 1
        return $this->getRenderer()->renderErrors();
72
    }
73
74
    /**
75
     * @param null|string|array $extraClasses
76
     * @return mixed
77
     */
78 2
    public function renderLabel($extraClasses = null)
79
    {
80 2
        return $this->getRenderer()->renderLabel($extraClasses);
81
    }
82
83
    /**
84
     * @param bool $value
85
     */
86
    public function setRenderLabel(bool $value)
87
    {
88
        $this->setOption('render_label', $value);
0 ignored issues
show
Bug introduced by
It seems like setOption() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

88
        $this->/** @scrutinizer ignore-call */ 
89
               setOption('render_label', $value);
Loading history...
89
    }
90
91
    /**
92
     * @return bool
93
     */
94 2
    public function isRenderLabel()
95
    {
96 2
        return $this->getOption('render_label') !== false;
0 ignored issues
show
Bug introduced by
It seems like getOption() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

96
        return $this->/** @scrutinizer ignore-call */ getOption('render_label') !== false;
Loading history...
97
    }
98
}
99