Completed
Push — master ( c9e4cd...c85fb5 )
by Christopher
18:34 queued 13:48
created

TEntityTypeType::isStructureOK()   B

Complexity

Conditions 6
Paths 11

Size

Total Lines 23
Code Lines 16

Duplication

Lines 14
Ratio 60.87 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 14
loc 23
rs 8.5906
cc 6
eloc 16
nc 11
nop 1
1
<?php
2
3
namespace AlgoWeb\ODataMetadata\MetadataV3\edm;
4
5
use AlgoWeb\ODataMetadata\CodeGeneration\AccessTypeTraits;
6
use AlgoWeb\ODataMetadata\IsOK;
7
use AlgoWeb\ODataMetadata\MetadataV3\edm\Groups\TDerivableTypeAttributesTrait;
8
9
/**
10
 * Class representing TEntityTypeType
11
 *
12
 *
13
 * XSD Type: TEntityType
14
 */
15
class TEntityTypeType extends IsOK
16
{
17
    use TDerivableTypeAttributesTrait, AccessTypeTraits;
18
    /**
19
     * @property boolean $openType
20
     */
21
    private $openType = false;
22
23
    /**
24
     * @property string $typeAccess
25
     */
26
    private $typeAccess = null;
27
28
    /**
29
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType $documentation
30
     */
31
    private $documentation = null;
32
33
    /**
34
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyRefType[] $key
35
     */
36
    private $key = null;
37
38
    /**
39
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityPropertyType[] $property
40
     */
41
    private $property = [];
42
43
    /**
44
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TNavigationPropertyType[] $navigationProperty
45
     */
46
    private $navigationProperty = [];
47
48
    /**
49
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TValueAnnotationType[] $valueAnnotation
50
     */
51
    private $valueAnnotation = [];
52
53
    /**
54
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAnnotationType[] $typeAnnotation
55
     */
56
    private $typeAnnotation = [];
57
58
    /**
59
     * Gets as openType
60
     *
61
     * @return boolean
62
     */
63
    public function getOpenType()
64
    {
65
        return $this->openType;
66
    }
67
68
    /**
69
     * Sets a new openType
70
     *
71
     * @param boolean $openType
72
     * @return self
73
     */
74
    public function setOpenType($openType)
75
    {
76
        $this->openType = $openType;
77
        return $this;
78
    }
79
80
    /**
81
     * Gets as typeAccess
82
     *
83
     * @return string
84
     */
85
    public function getTypeAccess()
86
    {
87
        return $this->typeAccess;
88
    }
89
90
    /**
91
     * Sets a new typeAccess
92
     *
93
     * @param string $typeAccess
94
     * @return self
95
     */
96 View Code Duplication
    public function setTypeAccess($typeAccess)
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...
97
    {
98
        if (null != $typeAccess && !$this->isTPublicOrInternalAccessOK($typeAccess)) {
99
            $msg = "Type access must be Public or Internal";
100
            throw new \InvalidArgumentException($msg);
101
        }
102
        $this->typeAccess = $typeAccess;
103
        return $this;
104
    }
105
106
    /**
107
     * Gets as documentation
108
     *
109
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType
110
     */
111
    public function getDocumentation()
112
    {
113
        return $this->documentation;
114
    }
115
116
    /**
117
     * Sets a new documentation
118
     *
119
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType $documentation
120
     * @return self
121
     */
122 View Code Duplication
    public function setDocumentation(TDocumentationType $documentation)
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...
123
    {
124
        $msg = null;
125
        if (!$documentation->isOK($msg)) {
126
            throw new \InvalidArgumentException($msg);
127
        }
128
        $this->documentation = $documentation;
129
        return $this;
130
    }
131
132
    /**
133
     * Adds as propertyRef
134
     *
135
     * @return self
136
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyRefType $propertyRef
137
     */
138
    public function addToKey(TPropertyRefType $propertyRef)
139
    {
140
        $msg = null;
141
        if (!$propertyRef->isOK($msg)) {
142
            throw new \InvalidArgumentException($msg);
143
        }
144
        $this->key[] = $propertyRef;
145
        return $this;
146
    }
147
148
    /**
149
     * isset key
150
     *
151
     * @param scalar $index
152
     * @return boolean
153
     */
154
    public function issetKey($index)
155
    {
156
        return isset($this->key[$index]);
157
    }
158
159
    /**
160
     * unset key
161
     *
162
     * @param scalar $index
163
     * @return void
164
     */
165
    public function unsetKey($index)
166
    {
167
        unset($this->key[$index]);
168
    }
169
170
    /**
171
     * Gets as key
172
     *
173
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyRefType[]
174
     */
175
    public function getKey()
176
    {
177
        return $this->key;
178
    }
179
180
    /**
181
     * Sets a new key
182
     *
183
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyRefType[] $key
184
     * @return self
185
     */
186 View Code Duplication
    public function setKey(array $key)
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...
187
    {
188
        if (!$this->isValidArrayOK(
189
            $key,
190
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyRefType',
191
            $msg
192
        )) {
193
            throw new \InvalidArgumentException($msg);
194
        }
195
        $this->key = $key;
196
        return $this;
197
    }
198
199
    /**
200
     * Adds as property
201
     *
202
     * @return self
203
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityPropertyType $property
204
     */
205 View Code Duplication
    public function addToProperty(TEntityPropertyType $property)
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...
206
    {
207
        $msg = null;
208
        if (!$property->isOK($msg)) {
209
            throw new \InvalidArgumentException($msg);
210
        }
211
        $this->property[] = $property;
212
        return $this;
213
    }
214
215
    /**
216
     * isset property
217
     *
218
     * @param scalar $index
219
     * @return boolean
220
     */
221
    public function issetProperty($index)
222
    {
223
        return isset($this->property[$index]);
224
    }
225
226
    /**
227
     * unset property
228
     *
229
     * @param scalar $index
230
     * @return void
231
     */
232
    public function unsetProperty($index)
233
    {
234
        unset($this->property[$index]);
235
    }
236
237
    /**
238
     * Adds as navigationProperty
239
     *
240
     * @return self
241
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TNavigationPropertyType $navigationProperty
242
     */
243
    public function addToNavigationProperty(TNavigationPropertyType $navigationProperty)
244
    {
245
        $msg = null;
246
        if (!$navigationProperty->isOK($msg)) {
247
            throw new \InvalidArgumentException($msg);
248
        }
249
        $this->navigationProperty[] = $navigationProperty;
250
        return $this;
251
    }
252
253
    /**
254
     * isset navigationProperty
255
     *
256
     * @param scalar $index
257
     * @return boolean
258
     */
259
    public function issetNavigationProperty($index)
260
    {
261
        return isset($this->navigationProperty[$index]);
262
    }
263
264
    /**
265
     * unset navigationProperty
266
     *
267
     * @param scalar $index
268
     * @return void
269
     */
270
    public function unsetNavigationProperty($index)
271
    {
272
        unset($this->navigationProperty[$index]);
273
    }
274
275
    /**
276
     * Adds as valueAnnotation
277
     *
278
     * @return self
279
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TValueAnnotationType $valueAnnotation
280
     */
281 View Code Duplication
    public function addToValueAnnotation(TValueAnnotationType $valueAnnotation)
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...
282
    {
283
        $msg = null;
284
        if (!$valueAnnotation->isOK($msg)) {
285
            throw new \InvalidArgumentException($msg);
286
        }
287
        $this->valueAnnotation[] = $valueAnnotation;
288
        return $this;
289
    }
290
291
    /**
292
     * isset valueAnnotation
293
     *
294
     * @param scalar $index
295
     * @return boolean
296
     */
297
    public function issetValueAnnotation($index)
298
    {
299
        return isset($this->valueAnnotation[$index]);
300
    }
301
302
    /**
303
     * unset valueAnnotation
304
     *
305
     * @param scalar $index
306
     * @return void
307
     */
308
    public function unsetValueAnnotation($index)
309
    {
310
        unset($this->valueAnnotation[$index]);
311
    }
312
313
    /**
314
     * Gets as valueAnnotation
315
     *
316
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TValueAnnotationType[]
317
     */
318
    public function getValueAnnotation()
319
    {
320
        return $this->valueAnnotation;
321
    }
322
323
    /**
324
     * Sets a new valueAnnotation
325
     *
326
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TValueAnnotationType[] $valueAnnotation
327
     * @return self
328
     */
329 View Code Duplication
    public function setValueAnnotation(array $valueAnnotation)
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...
330
    {
331
        if (!$this->isValidArrayOK(
332
            $valueAnnotation,
333
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\TValueAnnotationType',
334
            $msg
335
        )) {
336
            throw new \InvalidArgumentException($msg);
337
        }
338
        $this->valueAnnotation = $valueAnnotation;
339
        return $this;
340
    }
341
342
    /**
343
     * Adds as typeAnnotation
344
     *
345
     * @return self
346
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAnnotationType $typeAnnotation
347
     */
348 View Code Duplication
    public function addToTypeAnnotation(TTypeAnnotationType $typeAnnotation)
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...
349
    {
350
        $msg = null;
351
        if (!$typeAnnotation->isOK($msg)) {
352
            throw new \InvalidArgumentException($msg);
353
        }
354
        $this->typeAnnotation[] = $typeAnnotation;
355
        return $this;
356
    }
357
358
    /**
359
     * isset typeAnnotation
360
     *
361
     * @param scalar $index
362
     * @return boolean
363
     */
364
    public function issetTypeAnnotation($index)
365
    {
366
        return isset($this->typeAnnotation[$index]);
367
    }
368
369
    /**
370
     * unset typeAnnotation
371
     *
372
     * @param scalar $index
373
     * @return void
374
     */
375
    public function unsetTypeAnnotation($index)
376
    {
377
        unset($this->typeAnnotation[$index]);
378
    }
379
380
    /**
381
     * Gets as typeAnnotation
382
     *
383
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAnnotationType[]
384
     */
385
    public function getTypeAnnotation()
386
    {
387
        return $this->typeAnnotation;
388
    }
389
390
    /**
391
     * Sets a new typeAnnotation
392
     *
393
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAnnotationType[] $typeAnnotation
394
     * @return self
395
     */
396 View Code Duplication
    public function setTypeAnnotation(array $typeAnnotation)
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...
397
    {
398
        if (!$this->isValidArrayOK(
399
            $typeAnnotation,
400
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAnnotationType',
401
            $msg
402
        )) {
403
            throw new \InvalidArgumentException($msg);
404
        }
405
        $this->typeAnnotation = $typeAnnotation;
406
        return $this;
407
    }
408
409
    public function isOK(&$msg = null)
410
    {
411 View Code Duplication
        if (null != $this->typeAccess && !$this->isTPublicOrInternalAccessOK($this->typeAccess)) {
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...
412
            $msg = "Type access must be Public or Internal";
413
            return false;
414
        }
415
        if (!$this->isObjectNullOrOK($this->documentation, $msg)) {
416
            return false;
417
        }
418
        if (!$this->isValidArrayOK(
419
            $this->key,
420
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyRefType',
421
            $msg
422
        )
423
        ) {
424
            return false;
425
        }
426
427
        if (!$this->isValidArrayOK(
428
            $this->property,
429
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityPropertyType',
430
            $msg
431
        )
432
        ) {
433
            return false;
434
        }
435
        if (!$this->isValidArrayOK(
436
            $this->navigationProperty,
437
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\TNavigationPropertyType',
438
            $msg
439
        )
440
        ) {
441
            return false;
442
        }
443
        if (!$this->isValidArrayOK(
444
            $this->valueAnnotation,
445
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\TValueAnnotationType',
446
            $msg
447
        )
448
        ) {
449
            return false;
450
        }
451
        if (!$this->isValidArrayOK(
452
            $this->typeAnnotation,
453
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAnnotationType',
454
            $msg
455
        )
456
        ) {
457
            return false;
458
        }
459
        if (!$this->isTDerivableTypeAttributesValid($msg)) {
460
            return false;
461
        }
462
        return $this->isStructureOK($msg);
463
    }
464
465
    public function isStructureOK(&$msg = null)
466
    {
467
        $pArray = [];
468 View Code Duplication
        foreach ($this->getProperty() as $prop) {
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...
469
            if (in_array($prop->getName(), $pArray)) {
470
                $msg = "Property Names, and Navigation Property Must Be Unique " . __CLASS__;
471
                return false;
472
            }
473
            $pArray[] = $prop->getName();
474
        }
475 View Code Duplication
        foreach ($this->getNavigationProperty() as $prop) {
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...
476
            if (in_array($prop->getName(), $pArray)) {
477
                $msg = "Property Names, and Navigation Property Must Be Unique " . __CLASS__;
478
                return false;
479
            }
480
            $pArray[] = $prop->getName();
481
        }
482
        if (in_array($this->getName(), $prop)) {
0 ignored issues
show
Bug introduced by
The variable $prop does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
483
            $msg = "entity types can not contain a property with the same name " . __CLASS__;
484
            return false;
485
        }
486
        return true;
487
    }
488
489
    /**
490
     * Gets as property
491
     *
492
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityPropertyType[]
493
     */
494
    public function getProperty()
495
    {
496
        return $this->property;
497
    }
498
499
    /**
500
     * Sets a new property
501
     *
502
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityPropertyType[] $property
503
     * @return self
504
     */
505
    public function setProperty(array $property)
506
    {
507
        if (!$this->isValidArrayOK(
508
            $property,
509
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\TEntityPropertyType',
510
            $msg
511
        )
512
        ) {
513
            throw new \InvalidArgumentException($msg);
514
        }
515
        $this->property = $property;
516
        return $this;
517
    }
518
519
    /**
520
     * Gets as navigationProperty
521
     *
522
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TNavigationPropertyType[]
523
     */
524
    public function getNavigationProperty()
525
    {
526
        return $this->navigationProperty;
527
    }
528
529
    /**
530
     * Sets a new navigationProperty
531
     *
532
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TNavigationPropertyType[] $navigationProperty
533
     * @return self
534
     */
535
    public function setNavigationProperty(array $navigationProperty)
536
    {
537
        if (!$this->isValidArrayOK(
538
            $navigationProperty,
539
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\TNavigationPropertyType',
540
            $msg
541
        )
542
        ) {
543
            throw new \InvalidArgumentException($msg);
544
        }
545
        $this->navigationProperty = $navigationProperty;
546
        return $this;
547
    }
548
}
549