Passed
Push — master ( 36f7a9...5c48d5 )
by Alex
04:11
created

TEntityTypeShapeType::getIsExpanded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace AlgoWeb\ODataMetadata\MetadataV3\edmx;
4
5
use AlgoWeb\ODataMetadata\IsOK;
6
7
/**
8
 * Class representing TEntityTypeShapeType
9
 *
10
 *
11
 * XSD Type: TEntityTypeShape
12
 */
13
class TEntityTypeShapeType extends IsOK
14
{
15
16
    /**
17
     * @property string $entityType
18
     */
19
    private $entityType = null;
20
21
    /**
22
     * @property float $pointX
23
     */
24
    private $pointX = null;
25
26
    /**
27
     * @property float $pointY
28
     */
29
    private $pointY = null;
30
31
    /**
32
     * @property float $width
33
     */
34
    private $width = null;
35
36
    /**
37
     * @property float $height
38
     */
39
    private $height = null;
40
41
    /**
42
     * @property boolean $isExpanded
43
     */
44
    private $isExpanded = null;
45
46
    /**
47
     * @property string $fillColor
48
     */
49
    private $fillColor = null;
50
51
    /**
52
     * Gets as entityType
53
     *
54
     * @return string
55
     */
56
    public function getEntityType()
57
    {
58
        return $this->entityType;
59
    }
60
61
    /**
62
     * Sets a new entityType
63
     *
64
     * @param string $entityType
65
     * @return self
66
     */
67
    public function setEntityType($entityType)
68
    {
69
        if (!$this->isStringNotNullOrEmpty($this->entityType)) {
70
            $msg = "Entity type cannot be null or empty";
71
            throw new \InvalidArgumentException($msg);
72
        }
73
        $this->entityType = $entityType;
74
        return $this;
75
    }
76
77
    /**
78
     * Gets as pointX
79
     *
80
     * @return float
81
     */
82
    public function getPointX()
83
    {
84
        return $this->pointX;
85
    }
86
87
    /**
88
     * Sets a new pointX
89
     *
90
     * @param float $pointX
91
     * @return self
92
     */
93 View Code Duplication
    public function setPointX($pointX)
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...
94
    {
95
        if (null != $pointX && !is_numeric($pointX)) {
96
            $msg = "Point X value must be numeric";
97
            throw new \InvalidArgumentException($msg);
98
        }
99
        $this->pointX = $pointX;
100
        return $this;
101
    }
102
103
    /**
104
     * Gets as pointY
105
     *
106
     * @return float
107
     */
108
    public function getPointY()
109
    {
110
        return $this->pointY;
111
    }
112
113
    /**
114
     * Sets a new pointY
115
     *
116
     * @param float $pointY
117
     * @return self
118
     */
119 View Code Duplication
    public function setPointY($pointY)
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...
120
    {
121
        if (null != $pointY && !is_numeric($pointY)) {
122
            $msg = "Point Y value must be numeric";
123
            throw new \InvalidArgumentException($msg);
124
        }
125
        $this->pointY = $pointY;
126
        return $this;
127
    }
128
129
    /**
130
     * Gets as width
131
     *
132
     * @return float
133
     */
134
    public function getWidth()
135
    {
136
        return $this->width;
137
    }
138
139
    /**
140
     * Sets a new width
141
     *
142
     * @param float $width
143
     * @return self
144
     */
145 View Code Duplication
    public function setWidth($width)
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...
146
    {
147
        if (null != $width && (!is_numeric($width) || 0 >= $width)) {
148
            $msg = "Width value must be numeric and positive";
149
            throw new \InvalidArgumentException($msg);
150
        }
151
        $this->width = $width;
152
        return $this;
153
    }
154
155
    /**
156
     * Gets as height
157
     *
158
     * @return float
159
     */
160
    public function getHeight()
161
    {
162
        return $this->height;
163
    }
164
165
    /**
166
     * Sets a new height
167
     *
168
     * @param float $height
169
     * @return self
170
     */
171 View Code Duplication
    public function setHeight($height)
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...
172
    {
173
        if (null != $height && (!is_numeric($height) || 0 >= $height)) {
174
            $msg = "Height value must be numeric and positive";
175
            throw new \InvalidArgumentException($msg);
176
        }
177
        $this->height = $height;
178
        return $this;
179
    }
180
181
    /**
182
     * Gets as isExpanded
183
     *
184
     * @return boolean
185
     */
186
    public function getIsExpanded()
187
    {
188
        return $this->isExpanded;
189
    }
190
191
    /**
192
     * Sets a new isExpanded
193
     *
194
     * @param boolean $isExpanded
195
     * @return self
196
     */
197
    public function setIsExpanded($isExpanded)
198
    {
199
        $this->isExpanded = $isExpanded;
200
        return $this;
201
    }
202
203
    /**
204
     * Gets as fillColor
205
     *
206
     * @return string
207
     */
208
    public function getFillColor()
209
    {
210
        return $this->fillColor;
211
    }
212
213
    /**
214
     * Sets a new fillColor
215
     *
216
     * @param string $fillColor
217
     * @return self
218
     */
219
    public function setFillColor($fillColor)
220
    {
221
        if (null != $fillColor && !$this->isStringNotNullOrEmpty($fillColor)) {
222
            $msg = "Fill color cannot be null or empty";
0 ignored issues
show
Unused Code introduced by
$msg is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
223
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by AlgoWeb\ODataMetadata\Me...ShapeType::setFillColor of type AlgoWeb\ODataMetadata\Me...mx\TEntityTypeShapeType.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
224
        }
225
        $this->fillColor = $fillColor;
226
        return $this;
227
    }
228
229
    /**
230
     * @return bool
231
     */
232
    public function isOK(&$msg = null)
233
    {
234
        if (!$this->isStringNotNullOrEmpty($this->entityType)) {
235
            $msg = "Entity type cannot be null or empty";
236
            return false;
237
        }
238
239
        if (null != $this->fillColor && !$this->isStringNotNullOrEmpty($this->fillColor)) {
240
            $msg = "Fill color cannot be empty";
241
            return false;
242
        }
243
244 View Code Duplication
        if (null != $this->pointX && !is_numeric($this->pointX)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
245
            $msg = "Point X value must be numeric";
246
            return false;
247
        }
248 View Code Duplication
        if (null != $this->pointY && !is_numeric($this->pointY)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
249
            $msg = "Point Y value must be numeric";
250
            return false;
251
        }
252
        if (null != $this->width && (!is_numeric($this->width) || 0 >= $this->width)) {
253
            $msg = "Width value must be numeric and positive";
254
            return false;
255
        }
256
        if (null != $this->height && (!is_numeric($this->height) || 0 >= $this->height)) {
257
            $msg = "Height value must be numeric and positive";
258
            return false;
259
        }
260
261
        return true;
262
    }
263
}
264