Passed
Pull Request — master (#93)
by Alex
04:41
created

EntityContainer::setIsDefaultEntityContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
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\IsOKTraits\IsOKToolboxTrait;
8
use AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType;
9
use AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\EntitySetAnonymousType;
10
use AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\FunctionImportAnonymousType;
11
use AlgoWeb\ODataMetadata\MetadataV3\edm\IsOKTraits\TSimpleIdentifierTrait;
12
13
/**
14
 * Class representing EntityContainer
15
 */
16
class EntityContainer extends IsOK
17
{
18
    use IsOKToolboxTrait, TSimpleIdentifierTrait, AccessTypeTraits;
19
    /**
20
     * @property string $name
21
     */
22
    private $name = null;
23
24
    /**
25
     * @property string $extends
26
     */
27
    private $extends = null;
28
29
    /**
30
     * @property string $typeAccess
31
     */
32
    private $typeAccess = null;
33
34
    /**
35
     * @property boolean $lazyLoadingEnabled
36
     */
37
    private $lazyLoadingEnabled = null;
38
39
    /**
40
     * @property boolean $isDefaultEntityContainer
41
     */
42
    private $isDefaultEntityContainer = false;
43
44
    /**
45
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType $documentation
46
     */
47
    private $documentation = null;
48
49
    /**
50
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\FunctionImportAnonymousType[]
51
     * $functionImport
52
     */
53
    private $functionImport = [];
54
55
    /**
56
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\EntitySetAnonymousType[] $entitySet
57
     */
58
    private $entitySet = [];
59
60
    /**
61
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType[]
62
     * $associationSet
63
     */
64
    private $associationSet = [];
65
66
    public function __construct($name = "DefaultContainer")
67
    {
68
        $this->setName($name);
69
    }
70
71
    /**
72
     * Gets as name
73
     *
74
     * @return string
75
     */
76
    public function getName()
77
    {
78
        return $this->name;
79
    }
80
81
    /**
82
     * Sets a new name
83
     *
84
     * @param string $name
85
     * @return self
86
     */
87
    public function setName($name)
88
    {
89
        if (!$this->isTSimpleIdentifierValid($name)) {
90
            $msg = "Name(" . $name . ") must be a valid TSimpleIdentifier";
91
            throw new \InvalidArgumentException($msg);
92
        }
93
        $this->name = $name;
94
        return $this;
95
    }
96
97
    /**
98
     * Gets as extends
99
     *
100
     * @return string
101
     */
102
    public function getExtends()
103
    {
104
        return $this->extends;
105
    }
106
107
    /**
108
     * Sets a new extends
109
     *
110
     * @param string $extends
111
     * @return self
112
     */
113
    public function setExtends($extends)
114
    {
115
        if (null != $extends && !$this->isTSimpleIdentifierValid($extends)) {
116
            $msg = "Extends must be a valid TSimpleIdentifier";
117
            throw new \InvalidArgumentException($msg);
118
        }
119
        $this->extends = $extends;
120
        return $this;
121
    }
122
123
    /**
124
     * Gets as typeAccess
125
     *
126
     * @return string
127
     */
128
    public function getTypeAccess()
129
    {
130
        return $this->typeAccess;
131
    }
132
133
    /**
134
     * Sets a new typeAccess
135
     *
136
     * @param string $typeAccess
137
     * @return self
138
     */
139 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...
140
    {
141
        if (null != $typeAccess && !($this->isTPublicOrInternalAccessOK($typeAccess))) {
142
            $msg = "Type access must be Public or Internal";
143
            throw new \InvalidArgumentException($msg);
144
        }
145
        $this->typeAccess = $typeAccess;
146
        return $this;
147
    }
148
149
    /**
150
     * Gets as lazyLoadingEnabled
151
     *
152
     * @return boolean
153
     */
154
    public function getLazyLoadingEnabled()
155
    {
156
        return $this->lazyLoadingEnabled;
157
    }
158
159
    /**
160
     * Sets a new lazyLoadingEnabled
161
     *
162
     * @param boolean $lazyLoadingEnabled
163
     * @return self
164
     */
165
    public function setLazyLoadingEnabled($lazyLoadingEnabled)
166
    {
167
        $this->lazyLoadingEnabled = boolval($lazyLoadingEnabled);
168
        return $this;
169
    }
170
171
    /**
172
     * Gets as documentation
173
     *
174
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType
175
     */
176
    public function getDocumentation()
177
    {
178
        return $this->documentation;
179
    }
180
181
    /**
182
     * Gets as lazyLoadingEnabled
183
     *
184
     * @return boolean
185
     */
186
    public function getIsDefaultEntityContainer()
187
    {
188
        return boolval($this->isDefaultEntityContainer);
189
    }
190
191
    /**
192
     * Sets a new lazyLoadingEnabled
193
     *
194
     * @param boolean $lazyLoadingEnabled
0 ignored issues
show
Bug introduced by
There is no parameter named $lazyLoadingEnabled. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
195
     * @return self
196
     */
197
    public function setIsDefaultEntityContainer($isDefaultEntityContainer)
198
    {
199
        $this->isDefaultEntityContainer = boolval($isDefaultEntityContainer);
200
        return $this;
201
    }
202
203
    /**
204
     * Sets a new documentation
205
     *
206
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType $documentation
207
     * @return self
208
     */
209 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...
210
    {
211
        $msg = null;
212
        if (!$documentation->isOK($msg)) {
213
            throw new \InvalidArgumentException($msg);
214
        }
215
        $this->documentation = $documentation;
216
        return $this;
217
    }
218
219
    /**
220
     * Adds as functionImport
221
     *
222
     * @return self
223
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\FunctionImportAnonymousType
224
     * $functionImport
225
     */
226
    public function addToFunctionImport(FunctionImportAnonymousType $functionImport)
227
    {
228
        $msg = null;
229
        if (!$functionImport->isOK($msg)) {
230
            throw new \InvalidArgumentException($msg);
231
        }
232
        $this->functionImport[] = $functionImport;
233
        return $this;
234
    }
235
236
    /**
237
     * isset functionImport
238
     *
239
     * @param scalar $index
240
     * @return boolean
241
     */
242
    public function issetFunctionImport($index)
243
    {
244
        return isset($this->functionImport[$index]);
245
    }
246
247
    /**
248
     * unset functionImport
249
     *
250
     * @param scalar $index
251
     * @return void
252
     */
253
    public function unsetFunctionImport($index)
254
    {
255
        unset($this->functionImport[$index]);
256
    }
257
258
    /**
259
     * Gets as functionImport
260
     *
261
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\FunctionImportAnonymousType[]
262
     */
263
    public function getFunctionImport()
264
    {
265
        return $this->functionImport;
266
    }
267
268
    /**
269
     * Sets a new functionImport
270
     *
271
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\FunctionImportAnonymousType[]
272
     * $functionImport
273
     * @return self
274
     */
275
    public function setFunctionImport(array $functionImport)
276
    {
277
        if (!$this->isValidArrayOK(
278
            $functionImport,
279
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\FunctionImportAnonymousType',
280
            $msg
281
        )) {
282
            throw new \InvalidArgumentException($msg);
283
        }
284
        $this->functionImport = $functionImport;
285
        return $this;
286
    }
287
288
    /**
289
     * Adds as entitySet
290
     *
291
     * @return self
292
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\EntitySetAnonymousType $entitySet
293
     */
294 View Code Duplication
    public function addToEntitySet(EntitySetAnonymousType $entitySet)
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...
295
    {
296
        $msg = null;
297
        if (!$entitySet->isOK($msg)) {
298
            throw new \InvalidArgumentException($msg);
299
        }
300
        $this->entitySet[] = $entitySet;
301
        return $this;
302
    }
303
304
    /**
305
     * isset entitySet
306
     *
307
     * @param scalar $index
308
     * @return boolean
309
     */
310
    public function issetEntitySet($index)
311
    {
312
        return isset($this->entitySet[$index]);
313
    }
314
315
    /**
316
     * unset entitySet
317
     *
318
     * @param scalar $index
319
     * @return void
320
     */
321
    public function unsetEntitySet($index)
322
    {
323
        unset($this->entitySet[$index]);
324
    }
325
326
    /**
327
     * Gets as entitySet
328
     *
329
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\EntitySetAnonymousType[]
330
     */
331
    public function getEntitySet()
332
    {
333
        return $this->entitySet;
334
    }
335
336
    /**
337
     * Sets a new entitySet
338
     *
339
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\EntitySetAnonymousType[] $entitySet
340
     * @return self
341
     */
342 View Code Duplication
    public function setEntitySet(array $entitySet)
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...
343
    {
344
        if (!$this->isValidArrayOK(
345
            $entitySet,
346
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\EntitySetAnonymousType',
347
            $msg
348
        )) {
349
            throw new \InvalidArgumentException($msg);
350
        }
351
        $this->entitySet = $entitySet;
352
        return $this;
353
    }
354
355
    /**
356
     * Adds as associationSet
357
     *
358
     * @return self
359
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType
360
     * $associationSet
361
     */
362
    public function addToAssociationSet(AssociationSetAnonymousType $associationSet)
363
    {
364
        $msg = null;
365
        if (!$associationSet->isOK($msg)) {
366
            throw new \InvalidArgumentException($msg);
367
        }
368
        $this->associationSet[] = $associationSet;
369
        return $this;
370
    }
371
372
    /**
373
     * isset associationSet
374
     *
375
     * @param scalar $index
376
     * @return boolean
377
     */
378
    public function issetAssociationSet($index)
379
    {
380
        return isset($this->associationSet[$index]);
381
    }
382
383
    /**
384
     * unset associationSet
385
     *
386
     * @param scalar $index
387
     * @return void
388
     */
389
    public function unsetAssociationSet($index)
390
    {
391
        unset($this->associationSet[$index]);
392
    }
393
394
    /**
395
     * Gets as associationSet
396
     *
397
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType[]
398
     */
399
    public function getAssociationSet()
400
    {
401
        return $this->associationSet;
402
    }
403
404
    /**
405
     * Sets a new associationSet
406
     *
407
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType[]
408
     * $associationSet
409
     * @return self
410
     */
411 View Code Duplication
    public function setAssociationSet(array $associationSet)
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...
412
    {
413
        if (!$this->isValidArrayOK(
414
            $associationSet,
415
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType',
416
            $msg
417
        )) {
418
            throw new \InvalidArgumentException($msg);
419
        }
420
        $this->associationSet = $associationSet;
421
        return $this;
422
    }
423
424
    public function isOK(&$msg = null)
425
    {
426
        if (!$this->isTSimpleIdentifierValid($this->name)) {
427
            $msg = "Name(" . $this->name . ") must be a valid TSimpleIdentifier " . __FILE__ . ":" . __LINE__;
428
            return false;
429
        }
430
431
        if (null != $this->extends && !$this->isTSimpleIdentifierValid($this->extends)) {
432
            $msg = "Extends must be a valid TSimpleIdentifier";
433
            return false;
434
        }
435
436 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...
437
            $msg = "Type access must be Public or Internal";
438
            return false;
439
        }
440
        
441
        if (!$this->isObjectNullOrOK($this->documentation, $msg)) {
442
            return false;
443
        }
444
445
        if (!$this->isValidArrayOK(
446
            $this->functionImport,
447
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\FunctionImportAnonymousType',
448
            $msg
449
        )) {
450
            return false;
451
        }
452
453
        if (!$this->isValidArrayOK(
454
            $this->entitySet,
455
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\EntitySetAnonymousType',
456
            $msg
457
        )) {
458
            return false;
459
        }
460
461
        if (!$this->isValidArrayOK(
462
            $this->associationSet,
463
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType',
464
            $msg
465
        )) {
466
            return false;
467
        }
468
469
        return $this->isStructureOK($msg);
470
    }
471
472
    public function isStructureOK(&$msg = null)
473
    {
474
        $entityNames = [];
475
        foreach ($this->entitySet as $entitySet) {
476
            $entityNames[] = $entitySet->getName();
477
        }
478
        foreach ($this->associationSet as $assocationSet) {
479
            if (!in_array($assocationSet->getEnd()[0]->getEntitySet(), $entityNames)) {
480
                $msg = "The entitysets for assocations must have a valid entity set. " . $assocationSet->getName() . " Does not";
481
                return false;
482
            }
483
        }
484
        return true;
485
    }
486
}
487