Text::create()   B
last analyzed

Complexity

Conditions 8
Paths 16

Size

Total Lines 34

Duplication

Lines 34
Ratio 100 %

Importance

Changes 0
Metric Value
dl 34
loc 34
rs 8.1315
c 0
b 0
f 0
cc 8
nc 16
nop 0
1
<?php
2
3
namespace Faulancer\Form\Type\Base;
4
5
use Faulancer\Form\Type\AbstractType;
6
7
/**
8
 * Class Text
9
 *
10
 * @package Faulancer\Form\Type\Base
11
 * @author Florian Knapp <[email protected]>
12
 */
13 View Code Duplication
class Text extends AbstractType
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
16
    /** @var string */
17
    protected $inputType = 'input';
18
19
    /** @var string */
20
    protected $element = '';
21
22
    /**
23
     * @return self
24
     */
25
    public function create()
26
    {
27
        parent::create();
28
29
        $output = '<' . $this->inputType . ' ';
30
31
        foreach ($this->definition['attributes'] as $attr => $value) {
32
33
            if (!empty($this->getValue()) && $attr === 'value') {
34
                continue;
35
            }
36
37
            if ($attr === 'type' && !empty($this->getType())) {
38
                continue;
39
            }
40
41
            $output .= $attr . '="' . $value . '" ';
42
43
        }
44
45
        if (!empty($this->getValue())) {
46
            $output .= ' value="' . $this->getValue() . '"';
47
        }
48
49
        if (!empty($this->getType())) {
50
            $output .= ' type="' . $this->getType() . '"';
51
        }
52
53
        $output .= ' />';
54
55
        $this->element = $output;
56
57
        return $this;
58
    }
59
60
}