Test Failed
Push — master ( a5a28b...999969 )
by Marcin
02:51
created

Input::setStyles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * Grandstream-XMLApp
4
 *
5
 * Copyright (c) 2017 pudelek.org.pl
6
 *
7
 * @license MIT License (MIT)
8
 *
9
 * For the full copyright and license information, please view source file
10
 * that is bundled with this package in the file LICENSE
11
 *
12
 * @author  Marcin Pudełek <[email protected]>
13
 */
14
15
namespace mrcnpdlk\Grandstream\XMLApp\Application\Model;
16
17
use mrcnpdlk\Grandstream\XMLApp\MyXML;
18
19
/**
20
 * Class Input
21
 *
22
 * @package mrcnpdlk\Grandstream\XMLApp\Application\Model
23
 */
24
class Input implements ModelInterface
25
{
26
    const TYPE_TEXT     = 'text';
27
    const TYPE_PASSWORD = 'password';
28
    const TYPE_HIDDEN   = 'hidden';
29
    const TYPE_RADIO    = 'radio';
30
    const TYPE_CHECKBOX = 'checkbox';
31
32
    const DATATYPE_INT    = 'int';
33
    const DATATYPE_STRING = 'string';
34
35
    /**
36
     * @var string
37
     */
38
    private $sName;
39
    /**
40
     * @var string
41
     */
42
    private $sValue;
43
    /**
44
     * @var string
45
     */
46
    private $sType;
47
    /**
48
     * @var string
49
     */
50
    private $sDataType;
51
    /**
52
     * @var integer
53
     */
54
    private $iMaxLength;
55
    /**
56
     * @var \mrcnpdlk\Grandstream\XMLApp\Application\Model\Styles
57
     */
58
    private $oStyles;
59
    /**
60
     * Only for Radio
61
     *
62
     * @var string
63
     */
64
    private $sGroupName;
65
    /**
66
     * Only for Radio
67
     *
68
     * @var boolean
69
     */
70
    private $isSelected;
71
    /**
72
     * Only for Radio & CheckBox
73
     *
74
     * @var string
75
     */
76
    private $sLabel;
77
78
    /**
79
     * Input constructor.
80
     *
81
     * @param string      $sName
82
     * @param string|null $sValue
83
     * @param string      $sType
84
     */
85
    public function __construct(string $sName, string $sValue = null, string $sType = Input::TYPE_TEXT)
86
    {
87
        $this->sName  = $sName;
88
        $this->sValue = $sValue;
89
        $this->sType  = $sType;
90
        $this->setDataType();
91
    }
92
93
    /**
94
     * @param string $sDataType
95
     *
96
     * @return \mrcnpdlk\Grandstream\XMLApp\Application\Model\Input
97
     */
98
    public function setDataType(string $sDataType = Input::DATATYPE_STRING)
99
    {
100
        $this->sDataType = $sDataType;
101
102
        return $this;
103
    }
104
105
    /**
106
     * @param int $iMaxLength
107
     *
108
     * @return \mrcnpdlk\Grandstream\XMLApp\Application\Model\Input
109
     */
110
    public function setMaxLength(int $iMaxLength)
111
    {
112
        $this->iMaxLength = $iMaxLength;
113
114
        return $this;
115
    }
116
117
    /**
118
     * @param \mrcnpdlk\Grandstream\XMLApp\Application\Model\Styles $oStyles
119
     *
120
     * @return \mrcnpdlk\Grandstream\XMLApp\Application\Model\Input
121
     */
122
    public function setStyles(Styles $oStyles)
123
    {
124
        $this->oStyles = $oStyles;
125
126
        return $this;
127
    }
128
129
    /**
130
     * @param string $sGroupName
131
     *
132
     * @return \mrcnpdlk\Grandstream\XMLApp\Application\Model\Input
133
     */
134
    public function setGroupName(string $sGroupName)
135
    {
136
        $this->sGroupName = $sGroupName;
137
138
        return $this;
139
    }
140
141
    /**
142
     * @param string $sLabel
143
     *
144
     * @return \mrcnpdlk\Grandstream\XMLApp\Application\Model\Input
145
     */
146
    public function setLabel(string $sLabel)
147
    {
148
        $this->sLabel = $sLabel;
149
150
        return $this;
151
152
    }
153
154
    /**
155
     * @param bool $isSelected
156
     *
157
     * @return \mrcnpdlk\Grandstream\XMLApp\Application\Model\Input
158
     */
159
    public function setSelected(bool $isSelected = true)
160
    {
161
        $this->isSelected = $isSelected;
162
163
        return $this;
164
    }
165
166
    /**
167
     * @return \mrcnpdlk\Grandstream\XMLApp\MyXML
168
     */
169
    public function getXml(): MyXML
170
    {
171
        $oXml = new MyXML('input');
172
        $oXml->asObject()->addAttribute('name', $this->sName);
173
        $oXml->asObject()->addAttribute('value', $this->sValue);
174
        $oXml->asObject()->addAttribute('type', $this->sType);
175
        if ($this->oStyles) {
176
            $oXml->insertChild($this->oStyles->getXml());
0 ignored issues
show
Documentation introduced by
$this->oStyles->getXml() is of type object<mrcnpdlk\Grandstream\XMLApp\MyXML>, but the function expects a object<SimpleXMLElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
177
        }
178
179
180
        return $oXml;
181
    }
182
}