Completed
Push — master ( 1b7170...9fa28d )
by Alex
05:38
created

TComplexTypeMappingType::isOK()   C

Complexity

Conditions 10
Paths 17

Size

Total Lines 49
Code Lines 31

Duplication

Lines 6
Ratio 12.24 %

Importance

Changes 0
Metric Value
dl 6
loc 49
rs 5.5471
c 0
b 0
f 0
cc 10
eloc 31
nc 17
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace AlgoWeb\ODataMetadata\MetadataV3\mapping\cs;
4
5
use AlgoWeb\ODataMetadata\IsOK;
6
7
/**
8
 * Class representing TComplexTypeMappingType
9
 *
10
 * Type for Complex Type mapping element
11
 *
12
 * XSD Type: TComplexTypeMapping
13
 */
14
class TComplexTypeMappingType extends IsOK
15
{
16
17
    /**
18
     * @property string $typeName
19
     */
20
    private $typeName = null;
21
22
    /**
23
     * @property boolean $isPartial
24
     */
25
    private $isPartial = null;
26
27
    /**
28
     * @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType[] $scalarProperty
29
     */
30
    private $scalarProperty = [];
31
32
    /**
33
     * @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType[] $complexProperty
34
     */
35
    private $complexProperty = [];
36
37
    /**
38
     * @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType[] $condition
39
     */
40
    private $condition = [];
41
42
    /**
43
     * Gets as typeName
44
     *
45
     * @return string
46
     */
47
    public function getTypeName()
48
    {
49
        return $this->typeName;
50
    }
51
52
    /**
53
     * Sets a new typeName
54
     *
55
     * @param  string $typeName
56
     * @return self
57
     */
58 View Code Duplication
    public function setTypeName($typeName)
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...
59
    {
60
        if (null != $typeName) {
61
            if (!$this->isStringNotNullOrEmpty($typeName)) {
62
                $msg = 'Type name cannot be empty';
63
                throw new \InvalidArgumentException($msg);
64
            }
65
        }
66
        $this->typeName = $typeName;
67
        return $this;
68
    }
69
70
    /**
71
     * Gets as isPartial
72
     *
73
     * @return boolean
74
     */
75
    public function getIsPartial()
76
    {
77
        return $this->isPartial;
78
    }
79
80
    /**
81
     * Sets a new isPartial
82
     *
83
     * @param  boolean $isPartial
84
     * @return self
85
     */
86
    public function setIsPartial($isPartial)
87
    {
88
        $this->isPartial = $isPartial;
89
        return $this;
90
    }
91
92
    /**
93
     * Adds as scalarProperty
94
     *
95
     * @return self
96
     * @param  \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType $scalarProperty
97
     */
98 View Code Duplication
    public function addToScalarProperty(TScalarPropertyType $scalarProperty)
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...
99
    {
100
        $msg = null;
101
        if (!$scalarProperty->isOK($msg)) {
102
            throw new \InvalidArgumentException($msg);
103
        }
104
        $this->scalarProperty[] = $scalarProperty;
105
        return $this;
106
    }
107
108
    /**
109
     * isset scalarProperty
110
     *
111
     * @param  scalar $index
112
     * @return boolean
113
     */
114
    public function issetScalarProperty($index)
115
    {
116
        return isset($this->scalarProperty[$index]);
117
    }
118
119
    /**
120
     * unset scalarProperty
121
     *
122
     * @param  scalar $index
123
     * @return void
124
     */
125
    public function unsetScalarProperty($index)
126
    {
127
        unset($this->scalarProperty[$index]);
128
    }
129
130
    /**
131
     * Gets as scalarProperty
132
     *
133
     * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType[]
134
     */
135
    public function getScalarProperty()
136
    {
137
        return $this->scalarProperty;
138
    }
139
140
    /**
141
     * Sets a new scalarProperty
142
     *
143
     * @param  \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType[] $scalarProperty
144
     * @return self
145
     */
146 View Code Duplication
    public function setScalarProperty(array $scalarProperty)
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...
147
    {
148
        $msg = null;
149
        // if other arrays are empty, then the array we're assigning must not be empty
150
        $count = count($this->complexProperty) + count($this->condition);
151
        if (!$this->isValidArrayOK(
152
            $scalarProperty,
153
            '\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType',
154
            $msg,
155
            0 < $count ? 0 : 1
156
        )
157
        ) {
158
            throw new \InvalidArgumentException($msg);
159
        }
160
        $this->scalarProperty = $scalarProperty;
161
        return $this;
162
    }
163
164
    /**
165
     * Adds as complexProperty
166
     *
167
     * @return self
168
     * @param  \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType $complexProperty
169
     */
170 View Code Duplication
    public function addToComplexProperty(TComplexPropertyType $complexProperty)
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...
171
    {
172
        $msg = null;
173
        if (!$complexProperty->isOK($msg)) {
174
            throw new \InvalidArgumentException($msg);
175
        }
176
        $this->complexProperty[] = $complexProperty;
177
        return $this;
178
    }
179
180
    /**
181
     * isset complexProperty
182
     *
183
     * @param  scalar $index
184
     * @return boolean
185
     */
186
    public function issetComplexProperty($index)
187
    {
188
        return isset($this->complexProperty[$index]);
189
    }
190
191
    /**
192
     * unset complexProperty
193
     *
194
     * @param  scalar $index
195
     * @return void
196
     */
197
    public function unsetComplexProperty($index)
198
    {
199
        unset($this->complexProperty[$index]);
200
    }
201
202
    /**
203
     * Gets as complexProperty
204
     *
205
     * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType[]
206
     */
207
    public function getComplexProperty()
208
    {
209
        return $this->complexProperty;
210
    }
211
212
    /**
213
     * Sets a new complexProperty
214
     *
215
     * @param  \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType[] $complexProperty
216
     * @return self
217
     */
218 View Code Duplication
    public function setComplexProperty(array $complexProperty)
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...
219
    {
220
        $msg = null;
221
        // if other arrays are empty, then the array we're assigning must not be empty
222
        $count = count($this->scalarProperty) + count($this->condition);
223
        if (!$this->isValidArrayOK(
224
            $complexProperty,
225
            '\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType',
226
            $msg,
227
            0 < $count ? 0 : 1
228
        )
229
        ) {
230
            throw new \InvalidArgumentException($msg);
231
        }
232
        $this->complexProperty = $complexProperty;
233
        return $this;
234
    }
235
236
    /**
237
     * Adds as condition
238
     *
239
     * @return self
240
     * @param  \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType $condition
241
     */
242 View Code Duplication
    public function addToCondition(TConditionType $condition)
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...
243
    {
244
        $msg = null;
245
        if (!$condition->isOK($msg)) {
246
            throw new \InvalidArgumentException($msg);
247
        }
248
        $this->condition[] = $condition;
249
        return $this;
250
    }
251
252
    /**
253
     * isset condition
254
     *
255
     * @param  scalar $index
256
     * @return boolean
257
     */
258
    public function issetCondition($index)
259
    {
260
        return isset($this->condition[$index]);
261
    }
262
263
    /**
264
     * unset condition
265
     *
266
     * @param  scalar $index
267
     * @return void
268
     */
269
    public function unsetCondition($index)
270
    {
271
        unset($this->condition[$index]);
272
    }
273
274
    /**
275
     * Gets as condition
276
     *
277
     * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType[]
278
     */
279
    public function getCondition()
280
    {
281
        return $this->condition;
282
    }
283
284
    /**
285
     * Sets a new condition
286
     *
287
     * @param  \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType[] $condition
288
     * @return self
289
     */
290 View Code Duplication
    public function setCondition(array $condition)
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...
291
    {
292
        $msg = null;
293
        // if other arrays are empty, then the array we're assigning must not be empty
294
        $count = count($this->scalarProperty) + count($this->complexProperty);
295
        if (!$this->isValidArrayOK(
296
            $condition,
297
            '\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType',
298
            $msg,
299
            0 < $count ? 0 : 1
300
        )
301
        ) {
302
            throw new \InvalidArgumentException($msg);
303
        }
304
        $this->condition = $condition;
305
        return $this;
306
    }
307
308
    public function isOK(&$msg = null)
309
    {
310 View Code Duplication
        if (null != $this->typeName) {
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...
311
            if (!$this->isStringNotNullOrEmpty($this->typeName)) {
312
                $msg = 'Type name cannot be empty';
313
                return false;
314
            }
315
        }
316
        $count = count($this->scalarProperty) + count($this->complexProperty) + count($this->condition);
317
        if (1 > $count) {
318
            $msg = "Cannot have all arrays empty";
319
            return false;
320
        }
321
322
        if (!$this->isValidArray(
323
            $this->scalarProperty,
324
            '\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType'
325
        )
326
        ) {
327
            $msg = "Scalar property array not a valid array";
328
            return false;
329
        }
330
        if (!$this->isChildArrayOK($this->scalarProperty, $msg)) {
331
            return false;
332
        }
333
        if (!$this->isValidArray(
334
            $this->complexProperty,
335
            '\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType'
336
        )
337
        ) {
338
            $msg = "Complex property array not a valid array";
339
            return false;
340
        }
341
        if (!$this->isChildArrayOK($this->complexProperty, $msg)) {
342
            return false;
343
        }
344
        if (!$this->isValidArray(
345
            $this->condition,
346
            '\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType'
347
        )
348
        ) {
349
            $msg = "Condition array not a valid array";
350
            return false;
351
        }
352
        if (!$this->isChildArrayOK($this->condition, $msg)) {
353
            return false;
354
        }
355
        return true;
356
    }
357
}
358