Test Failed
Push — master ( 460acf...3c9528 )
by Christopher
04:41
created

EntityContainer::getTypeAccess()   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\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 \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType $documentation
41
     */
42
    private $documentation = null;
43
44
    /**
45
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\FunctionImportAnonymousType[]
46
     * $functionImport
47
     */
48
    private $functionImport = [];
49
50
    /**
51
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\EntitySetAnonymousType[] $entitySet
52
     */
53
    private $entitySet = [];
54
55
    /**
56
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType[]
57
     * $associationSet
58
     */
59
    private $associationSet = [];
60
61
    public function __construct($name = "DefaultContainer")
62
    {
63
        $this->setName($name);
64
    }
65
66
    /**
67
     * Gets as name
68
     *
69
     * @return string
70
     */
71
    public function getName()
72
    {
73
        return $this->name;
74
    }
75
76
    /**
77
     * Sets a new name
78
     *
79
     * @param string $name
80
     * @return self
81
     */
82
    public function setName($name)
83
    {
84
        if (!$this->isTSimpleIdentifierValid($name)) {
85
            $msg = "Name(" . $name . ") must be a valid TSimpleIdentifier";
86
            throw new \InvalidArgumentException($msg);
87
        }
88
        $this->name = $name;
89
        return $this;
90
    }
91
92
    /**
93
     * Gets as extends
94
     *
95
     * @return string
96
     */
97
    public function getExtends()
98
    {
99
        return $this->extends;
100
    }
101
102
    /**
103
     * Sets a new extends
104
     *
105
     * @param string $extends
106
     * @return self
107
     */
108
    public function setExtends($extends)
109
    {
110
        if (null != $extends && !$this->isTSimpleIdentifierValid($extends)) {
111
            $msg = "Extends must be a valid TSimpleIdentifier";
112
            throw new \InvalidArgumentException($msg);
113
        }
114
        $this->extends = $extends;
115
        return $this;
116
    }
117
118
    /**
119
     * Gets as typeAccess
120
     *
121
     * @return string
122
     */
123
    public function getTypeAccess()
124
    {
125
        return $this->typeAccess;
126
    }
127
128
    /**
129
     * Sets a new typeAccess
130
     *
131
     * @param string $typeAccess
132
     * @return self
133
     */
134 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...
135
    {
136
        if (null != $typeAccess && !($this->isTPublicOrInternalAccessOK($typeAccess))) {
137
            $msg = "Type access must be Public or Internal";
138
            throw new \InvalidArgumentException($msg);
139
        }
140
        $this->typeAccess = $typeAccess;
141
        return $this;
142
    }
143
144
    /**
145
     * Gets as lazyLoadingEnabled
146
     *
147
     * @return boolean
148
     */
149
    public function getLazyLoadingEnabled()
150
    {
151
        return $this->lazyLoadingEnabled;
152
    }
153
154
    /**
155
     * Sets a new lazyLoadingEnabled
156
     *
157
     * @param boolean $lazyLoadingEnabled
158
     * @return self
159
     */
160
    public function setLazyLoadingEnabled($lazyLoadingEnabled)
161
    {
162
        $this->lazyLoadingEnabled = boolval($lazyLoadingEnabled);
163
        return $this;
164
    }
165
166
    /**
167
     * Gets as documentation
168
     *
169
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType
170
     */
171
    public function getDocumentation()
172
    {
173
        return $this->documentation;
174
    }
175
176
    /**
177
     * Sets a new documentation
178
     *
179
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType $documentation
180
     * @return self
181
     */
182 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...
183
    {
184
        $msg = null;
185
        if (!$documentation->isOK($msg)) {
186
            throw new \InvalidArgumentException($msg);
187
        }
188
        $this->documentation = $documentation;
189
        return $this;
190
    }
191
192
    /**
193
     * Adds as functionImport
194
     *
195
     * @return self
196
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\FunctionImportAnonymousType
197
     * $functionImport
198
     */
199
    public function addToFunctionImport(FunctionImportAnonymousType $functionImport)
200
    {
201
        $msg = null;
202
        if (!$functionImport->isOK($msg)) {
203
            throw new \InvalidArgumentException($msg);
204
        }
205
        $this->functionImport[] = $functionImport;
206
        return $this;
207
    }
208
209
    /**
210
     * isset functionImport
211
     *
212
     * @param scalar $index
213
     * @return boolean
214
     */
215
    public function issetFunctionImport($index)
216
    {
217
        return isset($this->functionImport[$index]);
218
    }
219
220
    /**
221
     * unset functionImport
222
     *
223
     * @param scalar $index
224
     * @return void
225
     */
226
    public function unsetFunctionImport($index)
227
    {
228
        unset($this->functionImport[$index]);
229
    }
230
231
    /**
232
     * Gets as functionImport
233
     *
234
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\FunctionImportAnonymousType[]
235
     */
236
    public function getFunctionImport()
237
    {
238
        return $this->functionImport;
239
    }
240
241
    /**
242
     * Sets a new functionImport
243
     *
244
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\FunctionImportAnonymousType[]
245
     * $functionImport
246
     * @return self
247
     */
248
    public function setFunctionImport(array $functionImport)
249
    {
250
        if (!$this->isValidArrayOK(
251
            $functionImport,
252
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\FunctionImportAnonymousType',
253
            $msg
254
        )) {
255
            throw new \InvalidArgumentException($msg);
256
        }
257
        $this->functionImport = $functionImport;
258
        return $this;
259
    }
260
261
    /**
262
     * Adds as entitySet
263
     *
264
     * @return self
265
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\EntitySetAnonymousType $entitySet
266
     */
267 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...
268
    {
269
        $msg = null;
270
        if (!$entitySet->isOK($msg)) {
271
            throw new \InvalidArgumentException($msg);
272
        }
273
        $this->entitySet[] = $entitySet;
274
        return $this;
275
    }
276
277
    /**
278
     * isset entitySet
279
     *
280
     * @param scalar $index
281
     * @return boolean
282
     */
283
    public function issetEntitySet($index)
284
    {
285
        return isset($this->entitySet[$index]);
286
    }
287
288
    /**
289
     * unset entitySet
290
     *
291
     * @param scalar $index
292
     * @return void
293
     */
294
    public function unsetEntitySet($index)
295
    {
296
        unset($this->entitySet[$index]);
297
    }
298
299
    /**
300
     * Gets as entitySet
301
     *
302
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\EntitySetAnonymousType[]
303
     */
304
    public function getEntitySet()
305
    {
306
        return $this->entitySet;
307
    }
308
309
    /**
310
     * Sets a new entitySet
311
     *
312
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\EntitySetAnonymousType[] $entitySet
313
     * @return self
314
     */
315 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...
316
    {
317
        if (!$this->isValidArrayOK(
318
            $entitySet,
319
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\EntitySetAnonymousType',
320
            $msg
321
        )) {
322
            throw new \InvalidArgumentException($msg);
323
        }
324
        $this->entitySet = $entitySet;
325
        return $this;
326
    }
327
328
    /**
329
     * Adds as associationSet
330
     *
331
     * @return self
332
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType
333
     * $associationSet
334
     */
335
    public function addToAssociationSet(AssociationSetAnonymousType $associationSet)
336
    {
337
        $msg = null;
338
        if (!$associationSet->isOK($msg)) {
339
            throw new \InvalidArgumentException($msg);
340
        }
341
        $this->associationSet[] = $associationSet;
342
        return $this;
343
    }
344
345
    /**
346
     * isset associationSet
347
     *
348
     * @param scalar $index
349
     * @return boolean
350
     */
351
    public function issetAssociationSet($index)
352
    {
353
        return isset($this->associationSet[$index]);
354
    }
355
356
    /**
357
     * unset associationSet
358
     *
359
     * @param scalar $index
360
     * @return void
361
     */
362
    public function unsetAssociationSet($index)
363
    {
364
        unset($this->associationSet[$index]);
365
    }
366
367
    /**
368
     * Gets as associationSet
369
     *
370
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType[]
371
     */
372
    public function getAssociationSet()
373
    {
374
        return $this->associationSet;
375
    }
376
377
    /**
378
     * Sets a new associationSet
379
     *
380
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType[]
381
     * $associationSet
382
     * @return self
383
     */
384 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...
385
    {
386
        if (!$this->isValidArrayOK(
387
            $associationSet,
388
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType',
389
            $msg
390
        )) {
391
            throw new \InvalidArgumentException($msg);
392
        }
393
        $this->associationSet = $associationSet;
394
        return $this;
395
    }
396
397
    public function isOK(&$msg = null)
398
    {
399
        if (!$this->isTSimpleIdentifierValid($this->name)) {
400
            $msg = "Name(" . $this->name . ") must be a valid TSimpleIdentifier " . __FILE__ . ":" . __LINE__;
401
            return false;
402
        }
403
404
        if (null != $this->extends && !$this->isTSimpleIdentifierValid($this->extends)) {
405
            $msg = "Extends must be a valid TSimpleIdentifier";
406
            return false;
407
        }
408
409 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...
410
            $msg = "Type access must be Public or Internal";
411
            return false;
412
        }
413
        
414
        if (!$this->isObjectNullOrOK($this->documentation, $msg)) {
415
            return false;
416
        }
417
418
        if (!$this->isValidArrayOK(
419
            $this->functionImport,
420
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\FunctionImportAnonymousType',
421
            $msg
422
        )) {
423
            return false;
424
        }
425
426
        if (!$this->isValidArrayOK(
427
            $this->entitySet,
428
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\EntitySetAnonymousType',
429
            $msg
430
        )) {
431
            return false;
432
        }
433
434
        if (!$this->isValidArrayOK(
435
            $this->associationSet,
436
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\EntityContainer\AssociationSetAnonymousType',
437
            $msg
438
        )) {
439
            return false;
440
        }
441
442
        return $this->isStructureOK($msg);
443
    }
444
445
    public function isStructureOK(&$msg = null)
446
    {
447
        $entityNames = [];
448
        foreach ($this->entitySet as $entitySet) {
449
            $entityNames[] = $entitySet->getName();
450
        }
451
        foreach ($this->associationSet as $assocationSet) {
452
            if (!in_array($assocationSet->getEnd()[0]->getEntitySet(), $entityNames)) {
453
                $msg = "The entitysets for assocations must have a valid entity set. " . $assocationSet->getName() . " Does not";
454
                return false;
455
            }
456
        }
457
        return true;
458
    }
459
}
460