Passed
Push — master ( feaee9...2b3e4e )
by Alex
04:28
created

GExpressionTrait::setEnum()   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\Groups;
4
5
use AlgoWeb\ODataMetadata\IsOKTraits\IsOKToolboxTrait;
6
use AlgoWeb\ODataMetadata\MetadataV3\edm\TAnonymousFunctionExpressionType;
7
use AlgoWeb\ODataMetadata\MetadataV3\edm\TApplyExpressionType;
8
use AlgoWeb\ODataMetadata\MetadataV3\edm\TCollectionExpressionType;
9
use AlgoWeb\ODataMetadata\MetadataV3\edm\TEntitySetReferenceExpressionType;
10
use AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionReferenceExpressionType;
11
use AlgoWeb\ODataMetadata\MetadataV3\edm\TIfExpressionType;
12
use AlgoWeb\ODataMetadata\MetadataV3\edm\TParameterReferenceExpressionType;
13
use AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyReferenceExpressionType;
14
use AlgoWeb\ODataMetadata\MetadataV3\edm\TRecordExpressionType;
15
use AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAssertExpressionType;
16
use AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeTestExpressionType;
17
use AlgoWeb\ODataMetadata\MetadataV3\edm\TValueTermReferenceExpressionType;
18
use AlgoWeb\ODataMetadata\StringTraits\XSDTopLevelTrait;
19
20
trait GExpressionTrait
21
{
22
    use XSDTopLevelTrait, IsOKToolboxTrait;
23
24
    private $gExpressionMinimum = -1;
25
    private $gExpressionMaximum = -1;
26
27
    private $gExpressionSimpleFieldNames = ['string', 'binary', 'int', 'float', 'guid', 'decimal', 'bool', 'dateTime',
28
        'dateTimeOffset', 'enum', 'path'];
29
    private $gExpressionObjectFieldTypes = [
30
        'if' => '\AlgoWeb\ODataMetadata\MetadataV3\edm\TIfExpressionType',
31
        'record' => '\AlgoWeb\ODataMetadata\MetadataV3\edm\TRecordExpressionType',
32
        'collection' => '\AlgoWeb\ODataMetadata\MetadataV3\edm\TCollectionExpressionType',
33
        'typeAssert' => '\AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAssertExpressionType',
34
        'typeTest' => '\AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeTestExpressionType',
35
        'functionReference' => '\AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionReferenceExpressionType',
36
        'entitySetReference' => '\AlgoWeb\ODataMetadata\MetadataV3\edm\TEntitySetReferenceExpressionType',
37
        'anonymousFunction' => '\AlgoWeb\ODataMetadata\MetadataV3\edm\TAnonymousFunctionExpressionType',
38
        'parameterReference' => '\AlgoWeb\ODataMetadata\MetadataV3\edm\TParameterReferenceExpressionType',
39
        'apply' => '\AlgoWeb\ODataMetadata\MetadataV3\edm\TApplyExpressionType',
40
        'propertyReference' => '\AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyReferenceExpressionType',
41
        'valueTermReference' => '\AlgoWeb\ODataMetadata\MetadataV3\edm\TValueTermReferenceExpressionType'
42
    ];
43
44
    /**
45
     * @property string $string
46
     */
47
    private $string = null;
48
49
    /**
50
     * @property mixed $binary
51
     */
52
    private $binary = null;
53
54
    /**
55
     * @property integer $int
56
     */
57
    private $int = null;
58
59
    /**
60
     * @property float $float
61
     */
62
    private $float = null;
63
64
    /**
65
     * @property string $guid
66
     */
67
    private $guid = null;
68
69
    /**
70
     * @property float $decimal
71
     */
72
    private $decimal = null;
73
74
    /**
75
     * @property boolean $bool
76
     */
77
    private $bool = null;
78
79
    /**
80
     * @property \DateTime $dateTime
81
     */
82
    private $dateTime = null;
83
84
    /**
85
     * @property \DateTime $dateTimeOffset
86
     */
87
    private $dateTimeOffset = null;
88
89
    /**
90
     * @property string $enum
91
     */
92
    private $enum = null;
93
94
    /**
95
     * @property string $path
96
     */
97
    private $path = null;
98
99
    /**
100
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TIfExpressionType $if
101
     */
102
    private $if = null;
103
104
    /**
105
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TRecordExpressionType $record
106
     */
107
    private $record = null;
108
109
    /**
110
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TCollectionExpressionType $collection
111
     */
112
    private $collection = null;
113
114
    /**
115
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAssertExpressionType $typeAssert
116
     */
117
    private $typeAssert = null;
118
119
    /**
120
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeTestExpressionType $typeTest
121
     */
122
    private $typeTest = null;
123
124
    /**
125
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionReferenceExpressionType $functionReference
126
     */
127
    private $functionReference = null;
128
129
    /**
130
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TEntitySetReferenceExpressionType $entitySetReference
131
     */
132
    private $entitySetReference = null;
133
134
    /**
135
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TAnonymousFunctionExpressionType $anonymousFunction
136
     */
137
    private $anonymousFunction = null;
138
139
    /**
140
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TParameterReferenceExpressionType $parameterReference
141
     */
142
    private $parameterReference = null;
143
144
    /**
145
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TApplyExpressionType $apply
146
     */
147
    private $apply = null;
148
149
    /**
150
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyReferenceExpressionType $propertyReference
151
     */
152
    private $propertyReference = null;
153
154
    /**
155
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TValueTermReferenceExpressionType $valueTermReference
156
     */
157
    private $valueTermReference = null;
158
159
    /**
160
     * Gets as string
161
     *
162
     * @return string
163
     */
164
    public function getString()
165
    {
166
        return $this->string;
167
    }
168
169
    /**
170
     * Sets a new string
171
     *
172
     * @param string $string
173
     * @return self
174
     */
175
    public function setString($string)
176
    {
177
        $this->string = $string;
178
        return $this;
179
    }
180
181
    /**
182
     * Gets as binary
183
     *
184
     * @return mixed
185
     */
186
    public function getBinary()
187
    {
188
        return $this->binary;
189
    }
190
191
    /**
192
     * Sets a new binary
193
     *
194
     * @param mixed $binary
195
     * @return self
196
     */
197
    public function setBinary($binary)
198
    {
199
        $this->binary = $binary;
200
        return $this;
201
    }
202
203
    /**
204
     * Gets as int
205
     *
206
     * @return integer
207
     */
208
    public function getInt()
209
    {
210
        return $this->int;
211
    }
212
213
    /**
214
     * Sets a new int
215
     *
216
     * @param integer $int
217
     * @return self
218
     */
219
    public function setInt($int)
220
    {
221
        $this->int = $int;
222
        return $this;
223
    }
224
225
    /**
226
     * Gets as float
227
     *
228
     * @return float
229
     */
230
    public function getFloat()
231
    {
232
        return $this->float;
233
    }
234
235
    /**
236
     * Sets a new float
237
     *
238
     * @param float $float
239
     * @return self
240
     */
241
    public function setFloat($float)
242
    {
243
        $this->float = $float;
244
        return $this;
245
    }
246
247
    /**
248
     * Gets as guid
249
     *
250
     * @return string
251
     */
252
    public function getGuid()
253
    {
254
        return $this->guid;
255
    }
256
257
    /**
258
     * Sets a new guid
259
     *
260
     * @param string $guid
261
     * @return self
262
     */
263
    public function setGuid($guid)
264
    {
265
        $this->guid = $guid;
266
        return $this;
267
    }
268
269
    /**
270
     * Gets as decimal
271
     *
272
     * @return float
273
     */
274
    public function getDecimal()
275
    {
276
        return $this->decimal;
277
    }
278
279
    /**
280
     * Sets a new decimal
281
     *
282
     * @param float $decimal
283
     * @return self
284
     */
285
    public function setDecimal($decimal)
286
    {
287
        $this->decimal = $decimal;
288
        return $this;
289
    }
290
291
    /**
292
     * Gets as bool
293
     *
294
     * @return boolean
295
     */
296
    public function getBool()
297
    {
298
        return $this->bool;
299
    }
300
301
    /**
302
     * Sets a new bool
303
     *
304
     * @param boolean $bool
305
     * @return self
306
     */
307
    public function setBool($bool)
308
    {
309
        $this->bool = $bool;
310
        return $this;
311
    }
312
313
    /**
314
     * Gets as dateTime
315
     *
316
     * @return \DateTime
317
     */
318
    public function getDateTime()
319
    {
320
        return $this->dateTime;
321
    }
322
323
    /**
324
     * Sets a new dateTime
325
     *
326
     * @param \DateTime $dateTime
327
     * @return self
328
     */
329
    public function setDateTime(\DateTime $dateTime)
330
    {
331
        $this->dateTime = $dateTime;
332
        return $this;
333
    }
334
335
    /**
336
     * Gets as dateTimeOffset
337
     *
338
     * @return \DateTime
339
     */
340
    public function getDateTimeOffset()
341
    {
342
        return $this->dateTimeOffset;
343
    }
344
345
    /**
346
     * Sets a new dateTimeOffset
347
     *
348
     * @param \DateTime $dateTimeOffset
349
     * @return self
350
     */
351
    public function setDateTimeOffset(\DateTime $dateTimeOffset)
352
    {
353
        $this->dateTimeOffset = $dateTimeOffset;
354
        return $this;
355
    }
356
357
    /**
358
     * Gets as enum
359
     *
360
     * @return string
361
     */
362
    public function getEnum()
363
    {
364
        return $this->enum;
365
    }
366
367
    /**
368
     * Sets a new enum
369
     *
370
     * @param string $enum
371
     * @return self
372
     */
373
    public function setEnum($enum)
374
    {
375
        $this->enum = $enum;
376
        return $this;
377
    }
378
379
    /**
380
     * Gets as path
381
     *
382
     * @return string
383
     */
384
    public function getPath()
385
    {
386
        return $this->path;
387
    }
388
389
    /**
390
     * Sets a new path
391
     *
392
     * @param string $path
393
     * @return self
394
     */
395
    public function setPath($path)
396
    {
397
        $this->path = $path;
398
        return $this;
399
    }
400
401
    /**
402
     * Gets as if
403
     *
404
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TIfExpressionType
405
     */
406
    public function getIf()
407
    {
408
        return $this->if;
409
    }
410
411
    /**
412
     * Sets a new if
413
     *
414
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TIfExpressionType $if
415
     * @return self
416
     */
417
    public function setIf(TIfExpressionType $if)
418
    {
419
        $this->if = $if;
420
        return $this;
421
    }
422
423
    /**
424
     * Gets as record
425
     *
426
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TRecordExpressionType
427
     */
428
    public function getRecord()
429
    {
430
        return $this->record;
431
    }
432
433
    /**
434
     * Sets a new record
435
     *
436
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TRecordExpressionType $record
437
     * @return self
438
     */
439
    public function setRecord(TRecordExpressionType $record)
440
    {
441
        $this->record = $record;
442
        return $this;
443
    }
444
445
    /**
446
     * Gets as collection
447
     *
448
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TCollectionExpressionType
449
     */
450
    public function getCollection()
451
    {
452
        return $this->collection;
453
    }
454
455
    /**
456
     * Sets a new collection
457
     *
458
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TCollectionExpressionType $collection
459
     * @return self
460
     */
461
    public function setCollection(TCollectionExpressionType $collection)
462
    {
463
        $this->collection = $collection;
464
        return $this;
465
    }
466
467
    /**
468
     * Gets as typeAssert
469
     *
470
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAssertExpressionType
471
     */
472
    public function getTypeAssert()
473
    {
474
        return $this->typeAssert;
475
    }
476
477
    /**
478
     * Sets a new typeAssert
479
     *
480
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAssertExpressionType $typeAssert
481
     * @return self
482
     */
483
    public function setTypeAssert(TTypeAssertExpressionType $typeAssert)
484
    {
485
        $this->typeAssert = $typeAssert;
486
        return $this;
487
    }
488
489
    /**
490
     * Gets as typeTest
491
     *
492
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeTestExpressionType
493
     */
494
    public function getTypeTest()
495
    {
496
        return $this->typeTest;
497
    }
498
499
    /**
500
     * Sets a new typeTest
501
     *
502
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeTestExpressionType $typeTest
503
     * @return self
504
     */
505
    public function setTypeTest(TTypeTestExpressionType $typeTest)
506
    {
507
        $this->typeTest = $typeTest;
508
        return $this;
509
    }
510
511
    /**
512
     * Gets as functionReference
513
     *
514
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionReferenceExpressionType
515
     */
516
    public function getFunctionReference()
517
    {
518
        return $this->functionReference;
519
    }
520
521
    /**
522
     * Sets a new functionReference
523
     *
524
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionReferenceExpressionType $functionReference
525
     * @return self
526
     */
527
    public function setFunctionReference(TFunctionReferenceExpressionType $functionReference)
528
    {
529
        $this->functionReference = $functionReference;
530
        return $this;
531
    }
532
533
    /**
534
     * Gets as entitySetReference
535
     *
536
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TEntitySetReferenceExpressionType
537
     */
538
    public function getEntitySetReference()
539
    {
540
        return $this->entitySetReference;
541
    }
542
543
    /**
544
     * Sets a new entitySetReference
545
     *
546
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TEntitySetReferenceExpressionType $entitySetReference
547
     * @return self
548
     */
549
    public function setEntitySetReference(TEntitySetReferenceExpressionType $entitySetReference)
550
    {
551
        $this->entitySetReference = $entitySetReference;
552
        return $this;
553
    }
554
555
    /**
556
     * Gets as anonymousFunction
557
     *
558
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TAnonymousFunctionExpressionType
559
     */
560
    public function getAnonymousFunction()
561
    {
562
        return $this->anonymousFunction;
563
    }
564
565
    /**
566
     * Sets a new anonymousFunction
567
     *
568
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TAnonymousFunctionExpressionType $anonymousFunction
569
     * @return self
570
     */
571
    public function setAnonymousFunction(TAnonymousFunctionExpressionType $anonymousFunction)
572
    {
573
        $this->anonymousFunction = $anonymousFunction;
574
        return $this;
575
    }
576
577
    /**
578
     * Gets as parameterReference
579
     *
580
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TParameterReferenceExpressionType
581
     */
582
    public function getParameterReference()
583
    {
584
        return $this->parameterReference;
585
    }
586
587
    /**
588
     * Sets a new parameterReference
589
     *
590
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TParameterReferenceExpressionType $parameterReference
591
     * @return self
592
     */
593
    public function setParameterReference(TParameterReferenceExpressionType $parameterReference)
594
    {
595
        $this->parameterReference = $parameterReference;
596
        return $this;
597
    }
598
599
    /**
600
     * Gets as apply
601
     *
602
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TApplyExpressionType
603
     */
604
    public function getApply()
605
    {
606
        return $this->apply;
607
    }
608
609
    /**
610
     * Sets a new apply
611
     *
612
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TApplyExpressionType $apply
613
     * @return self
614
     */
615
    public function setApply(TApplyExpressionType $apply)
616
    {
617
        $this->apply = $apply;
618
        return $this;
619
    }
620
621
    /**
622
     * Gets as propertyReference
623
     *
624
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyReferenceExpressionType
625
     */
626
    public function getPropertyReference()
627
    {
628
        return $this->propertyReference;
629
    }
630
631
    /**
632
     * Sets a new propertyReference
633
     *
634
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyReferenceExpressionType $propertyReference
635
     * @return self
636
     */
637
    public function setPropertyReference(TPropertyReferenceExpressionType $propertyReference)
638
    {
639
        $this->propertyReference = $propertyReference;
640
        return $this;
641
    }
642
643
    /**
644
     * Gets as valueTermReference
645
     *
646
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TValueTermReferenceExpressionType
647
     */
648
    public function getValueTermReference()
649
    {
650
        return $this->valueTermReference;
651
    }
652
653
    /**
654
     * Sets a new valueTermReference
655
     *
656
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TValueTermReferenceExpressionType $valueTermReference
657
     * @return self
658
     */
659
    public function setValueTermReference(TValueTermReferenceExpressionType $valueTermReference)
660
    {
661
        $this->valueTermReference = $valueTermReference;
662
        return $this;
663
    }
664
665
    public function isGExpressionValid(&$msg = null)
666
    {
667
        if (-1 < $this->gExpressionMinimum || -1 < $this->gExpressionMaximum) {
668
            $counter = 0;
669
            foreach ($this->gExpressionSimpleFieldNames as $name) {
670
                $counter += isset($this->$name) ? 1 : 0;
671
            }
672
            foreach ($this->gExpressionObjectFieldTypes as $name => $type) {
673
                $counter += isset($this->$name) ? 1 : 0;
674
            }
675
            if (-1 < $this->gExpressionMinimum && $counter < $this->gExpressionMinimum) {
676
                $msg = $counter . " fields not null.  Need minimum of ".$this->gExpressionMinimum;
677
                return false;
678
            }
679
            if (-1 < $this->gExpressionMaximum && $counter > $this->gExpressionMaximum) {
680
                $msg = $counter . " fields not null.  Need maximum of ".$this->gExpressionMaximum;
681
                return false;
682
            }
683
        }
684
685
        foreach ($this->gExpressionObjectFieldTypes as $key => $type) {
686
            if (!$this->isObjectNullOrOK($this->$key, $msg)) {
687
                return false;
688
            }
689
            if (!$this->isObjectNullOrType($type, $this->$key)) {
690
                $msg = 'Type mismatch - should be ' .$type. ", is ".get_class($this->$key);
691
                return false;
692
            }
693
        }
694
695
        return true;
696
    }
697
}
698