Completed
Push — master ( ad129c...1d4a66 )
by Filipe
16:47
created

Checkbox::getAttributes()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 10
cts 10
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 0
crap 4
1
<?php
2
3
/**
4
 * This file is part of slick/form package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Form\Renderer;
11
use Slick\Form\InputInterface;
12
13
/**
14
 * HTML Checkbox input renderer
15
 *
16
 * @package Slick\Form\Renderer
17
 * @author  Filipe Silva <[email protected]>
18
 */
19
class Checkbox extends Div
20
{
21
22
    /**
23
     * @var InputInterface
24
     */
25
    protected $element;
26
27
    /**
28
     * @var string The template file to use in the rendering
29
     */
30
    public $template = 'form-inputs/checkbox.twig';
31
32
    /**
33
     * Returns the elements's label attributes as a string
34
     *
35
     * @return string
36
     */
37 2 View Code Duplication
    public function getLabelAttributes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
    {
39 2
        $result = [];
40 2
        $label = $this->element->getLabel();
41 2
        foreach ($label->getAttributes() as $attribute => $value) {
42 2
            if (null === $value) {
43 2
                $result[] = $attribute;
44 2
                continue;
45
            }
46
47 2
            $result[] = "{$attribute}=\"{$value}\"";
48 1
        }
49 2
        return implode(' ', $result);
50
    }
51
52
    /**
53
     * Returns the elements's attributes as a string
54
     *
55
     * @return string
56
     */
57 2
    public function getAttributes()
58
    {
59 2
        $result = [];
60 2
        foreach ($this->element->getAttributes() as $attribute => $value) {
61 2
            if (null === $value) {
62 2
                $result[] = $attribute;
63 2
                continue;
64
            }
65 2
            if ($attribute == 'name') continue;
66 2
            $result[] = "{$attribute}=\"{$value}\"";
67 1
        }
68 2
        return implode(' ', $result);
69
    }
70
}