Completed
Push — develop ( eb5f8c...2537a4 )
by
unknown
13:09
created

RequiredMarkInFormLabel   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 16
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 3
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013-2016 Cross Solution (http://cross-solution.de)
7
 * @author cbleek
8
 * @license   MIT
9
 */
10
11
namespace Core\Form\View\Helper;
12
13
14
use Zend\Form\View\Helper\FormLabel;
15
use Zend\Form\ElementInterface;
16
use Zend\Form\Exception;
17
18
class RequiredMarkInFormLabel extends FormLabel{
19
    public function __invoke(ElementInterface $element = null, $labelContent = null, $position = null)
20
    {
21
        // Set $required to a default of true | existing elements required-value
22
        $required = ($element->hasAttribute('required') ? true : false);
0 ignored issues
show
Bug introduced by
It seems like $element is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
23
24
        if (true === $required) {
25
            $labelContent = sprintf(
26
                '%s<span class="required-mark">*</span>',
27
                $labelContent
28
            );
29
        }
30
31
        return $this->openTag() . $labelContent . $this->closeTag();
32
    }
33
}