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

Checkbox   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 26.92 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 14
loc 52
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getLabelAttributes() 14 14 3
A getAttributes() 0 13 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
/**
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
}