1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlgoWeb\ODataMetadata\MetadataV3\mapping\cs; |
4
|
|
|
|
5
|
|
|
use AlgoWeb\ODataMetadata\IsOK; |
6
|
|
|
use AlgoWeb\ODataMetadata\MetadataV4\edm\IsOKTraits\TSimpleIdentifierTrait; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class representing TComplexPropertyType |
10
|
|
|
* |
11
|
|
|
* Type for Complex Property Map elements |
12
|
|
|
* |
13
|
|
|
* XSD Type: TComplexProperty |
14
|
|
|
*/ |
15
|
|
|
class TComplexPropertyType extends IsOK |
16
|
|
|
{ |
17
|
|
|
use TSimpleIdentifierTrait; |
18
|
|
|
/** |
19
|
|
|
* @property string $name |
20
|
|
|
*/ |
21
|
|
|
private $name = null; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @property string $typeName |
25
|
|
|
*/ |
26
|
|
|
private $typeName = null; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @property boolean $isPartial |
30
|
|
|
*/ |
31
|
|
|
private $isPartial = null; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType[] $scalarProperty |
35
|
|
|
*/ |
36
|
|
|
private $scalarProperty = []; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType[] $complexProperty |
40
|
|
|
*/ |
41
|
|
|
private $complexProperty = []; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexTypeMappingType[] $complexTypeMapping |
45
|
|
|
*/ |
46
|
|
|
private $complexTypeMapping = []; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType[] $condition |
50
|
|
|
*/ |
51
|
|
|
private $condition = []; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Gets as name |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
public function getName() |
59
|
|
|
{ |
60
|
|
|
return $this->name; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Sets a new name |
65
|
|
|
* |
66
|
|
|
* @param string $name |
67
|
|
|
* @return self |
68
|
|
|
*/ |
69
|
|
|
public function setName($name) |
70
|
|
|
{ |
71
|
|
|
if (!$this->isStringNotNullOrEmpty($name)) { |
72
|
|
|
$msg = 'Name cannot be null or empty'; |
73
|
|
|
throw new \InvalidArgumentException($msg); |
74
|
|
|
} |
75
|
|
|
if (!$this->isTSimpleIdentifierValid($name)) { |
76
|
|
|
$msg = 'Name must be a valid TSimpleIdentifier'; |
77
|
|
|
throw new \InvalidArgumentException($msg); |
78
|
|
|
} |
79
|
|
|
$this->name = $name; |
80
|
|
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Gets as typeName |
85
|
|
|
* |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
public function getTypeName() |
89
|
|
|
{ |
90
|
|
|
return $this->typeName; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Sets a new typeName |
95
|
|
|
* |
96
|
|
|
* @param string $typeName |
97
|
|
|
* @return self |
98
|
|
|
*/ |
99
|
|
View Code Duplication |
public function setTypeName($typeName) |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
if (null != $typeName && !$this->isStringNotNullOrEmpty($typeName)) { |
102
|
|
|
$msg = 'Type name cannot be empty'; |
103
|
|
|
throw new \InvalidArgumentException($msg); |
104
|
|
|
} |
105
|
|
|
$this->typeName = $typeName; |
106
|
|
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Gets as isPartial |
111
|
|
|
* |
112
|
|
|
* @return boolean |
113
|
|
|
*/ |
114
|
|
|
public function getIsPartial() |
115
|
|
|
{ |
116
|
|
|
return $this->isPartial; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Sets a new isPartial |
121
|
|
|
* |
122
|
|
|
* @param boolean $isPartial |
123
|
|
|
* @return self |
124
|
|
|
*/ |
125
|
|
|
public function setIsPartial($isPartial) |
126
|
|
|
{ |
127
|
|
|
$this->isPartial = $isPartial; |
128
|
|
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Adds as scalarProperty |
133
|
|
|
* |
134
|
|
|
* @return self |
135
|
|
|
* @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType $scalarProperty |
136
|
|
|
*/ |
137
|
|
View Code Duplication |
public function addToScalarProperty(TScalarPropertyType $scalarProperty) |
|
|
|
|
138
|
|
|
{ |
139
|
|
|
$msg = null; |
140
|
|
|
if (!$scalarProperty->isOK($msg)) { |
141
|
|
|
throw new \InvalidArgumentException($msg); |
142
|
|
|
} |
143
|
|
|
$this->scalarProperty[] = $scalarProperty; |
144
|
|
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* isset scalarProperty |
149
|
|
|
* |
150
|
|
|
* @param scalar $index |
151
|
|
|
* @return boolean |
152
|
|
|
*/ |
153
|
|
|
public function issetScalarProperty($index) |
154
|
|
|
{ |
155
|
|
|
return isset($this->scalarProperty[$index]); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* unset scalarProperty |
160
|
|
|
* |
161
|
|
|
* @param scalar $index |
162
|
|
|
* @return void |
163
|
|
|
*/ |
164
|
|
|
public function unsetScalarProperty($index) |
165
|
|
|
{ |
166
|
|
|
unset($this->scalarProperty[$index]); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Gets as scalarProperty |
171
|
|
|
* |
172
|
|
|
* @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType[] |
173
|
|
|
*/ |
174
|
|
|
public function getScalarProperty() |
175
|
|
|
{ |
176
|
|
|
return $this->scalarProperty; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Sets a new scalarProperty |
181
|
|
|
* |
182
|
|
|
* @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType[] $scalarProperty |
183
|
|
|
* @return self |
184
|
|
|
*/ |
185
|
|
|
public function setScalarProperty(array $scalarProperty) |
186
|
|
|
{ |
187
|
|
|
$msg = null; |
188
|
|
|
// if other arrays are empty, then the array we're assigning must not be empty |
189
|
|
|
$count = count($this->complexProperty) + count($this->condition) + count($this->complexTypeMapping); |
190
|
|
|
if (!$this->isValidArrayOK( |
191
|
|
|
$scalarProperty, |
192
|
|
|
'\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType', |
193
|
|
|
$msg, |
194
|
|
|
0 < $count ? 0 : 1 |
195
|
|
|
)) { |
196
|
|
|
throw new \InvalidArgumentException($msg); |
197
|
|
|
} |
198
|
|
|
$this->scalarProperty = $scalarProperty; |
199
|
|
|
return $this; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Adds as complexProperty |
204
|
|
|
* |
205
|
|
|
* @return self |
206
|
|
|
* @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType $complexProperty |
207
|
|
|
*/ |
208
|
|
View Code Duplication |
public function addToComplexProperty(TComplexPropertyType $complexProperty) |
|
|
|
|
209
|
|
|
{ |
210
|
|
|
$msg = null; |
211
|
|
|
if (!$complexProperty->isOK($msg)) { |
212
|
|
|
throw new \InvalidArgumentException($msg); |
213
|
|
|
} |
214
|
|
|
$this->complexProperty[] = $complexProperty; |
215
|
|
|
return $this; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* isset complexProperty |
220
|
|
|
* |
221
|
|
|
* @param scalar $index |
222
|
|
|
* @return boolean |
223
|
|
|
*/ |
224
|
|
|
public function issetComplexProperty($index) |
225
|
|
|
{ |
226
|
|
|
return isset($this->complexProperty[$index]); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* unset complexProperty |
231
|
|
|
* |
232
|
|
|
* @param scalar $index |
233
|
|
|
* @return void |
234
|
|
|
*/ |
235
|
|
|
public function unsetComplexProperty($index) |
236
|
|
|
{ |
237
|
|
|
unset($this->complexProperty[$index]); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Gets as complexProperty |
242
|
|
|
* |
243
|
|
|
* @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType[] |
244
|
|
|
*/ |
245
|
|
|
public function getComplexProperty() |
246
|
|
|
{ |
247
|
|
|
return $this->complexProperty; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Sets a new complexProperty |
252
|
|
|
* |
253
|
|
|
* @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType[] $complexProperty |
254
|
|
|
* @return self |
255
|
|
|
*/ |
256
|
|
|
public function setComplexProperty(array $complexProperty) |
257
|
|
|
{ |
258
|
|
|
$msg = null; |
259
|
|
|
// if other arrays are empty, then the array we're assigning must not be empty |
260
|
|
|
$count = count($this->scalarProperty) + count($this->condition) + count($this->complexTypeMapping); |
261
|
|
|
if (!$this->isValidArrayOK( |
262
|
|
|
$complexProperty, |
263
|
|
|
'\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType', |
264
|
|
|
$msg, |
265
|
|
|
0 < $count ? 0 : 1 |
266
|
|
|
)) { |
267
|
|
|
throw new \InvalidArgumentException($msg); |
268
|
|
|
} |
269
|
|
|
$this->complexProperty = $complexProperty; |
270
|
|
|
return $this; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* Adds as complexTypeMapping |
275
|
|
|
* |
276
|
|
|
* @return self |
277
|
|
|
* @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexTypeMappingType $complexTypeMapping |
278
|
|
|
*/ |
279
|
|
|
public function addToComplexTypeMapping(TComplexTypeMappingType $complexTypeMapping) |
280
|
|
|
{ |
281
|
|
|
$msg = null; |
282
|
|
|
if (!$complexTypeMapping->isOK($msg)) { |
283
|
|
|
throw new \InvalidArgumentException($msg); |
284
|
|
|
} |
285
|
|
|
$this->complexTypeMapping[] = $complexTypeMapping; |
286
|
|
|
return $this; |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* isset complexTypeMapping |
291
|
|
|
* |
292
|
|
|
* @param scalar $index |
293
|
|
|
* @return boolean |
294
|
|
|
*/ |
295
|
|
|
public function issetComplexTypeMapping($index) |
296
|
|
|
{ |
297
|
|
|
return isset($this->complexTypeMapping[$index]); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* unset complexTypeMapping |
302
|
|
|
* |
303
|
|
|
* @param scalar $index |
304
|
|
|
* @return void |
305
|
|
|
*/ |
306
|
|
|
public function unsetComplexTypeMapping($index) |
307
|
|
|
{ |
308
|
|
|
unset($this->complexTypeMapping[$index]); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Gets as complexTypeMapping |
313
|
|
|
* |
314
|
|
|
* @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexTypeMappingType[] |
315
|
|
|
*/ |
316
|
|
|
public function getComplexTypeMapping() |
317
|
|
|
{ |
318
|
|
|
return $this->complexTypeMapping; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* Sets a new complexTypeMapping |
323
|
|
|
* |
324
|
|
|
* @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexTypeMappingType[] $complexTypeMapping |
325
|
|
|
* @return self |
326
|
|
|
*/ |
327
|
|
|
public function setComplexTypeMapping(array $complexTypeMapping) |
328
|
|
|
{ |
329
|
|
|
$msg = null; |
330
|
|
|
// if other arrays are empty, then the array we're assigning must not be empty |
331
|
|
|
$count = count($this->scalarProperty) + count($this->complexProperty) + count($this->condition); |
332
|
|
|
if (!$this->isValidArrayOK( |
333
|
|
|
$complexTypeMapping, |
334
|
|
|
'\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType', |
335
|
|
|
$msg, |
336
|
|
|
0 < $count ? 0 : 1 |
337
|
|
|
)) { |
338
|
|
|
throw new \InvalidArgumentException($msg); |
339
|
|
|
} |
340
|
|
|
$this->complexTypeMapping = $complexTypeMapping; |
341
|
|
|
return $this; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* Adds as condition |
346
|
|
|
* |
347
|
|
|
* @return self |
348
|
|
|
* @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType $condition |
349
|
|
|
*/ |
350
|
|
View Code Duplication |
public function addToCondition(TConditionType $condition) |
|
|
|
|
351
|
|
|
{ |
352
|
|
|
$msg = null; |
353
|
|
|
if (!$condition->isOK($msg)) { |
354
|
|
|
throw new \InvalidArgumentException($msg); |
355
|
|
|
} |
356
|
|
|
$this->condition[] = $condition; |
357
|
|
|
return $this; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* isset condition |
362
|
|
|
* |
363
|
|
|
* @param scalar $index |
364
|
|
|
* @return boolean |
365
|
|
|
*/ |
366
|
|
|
public function issetCondition($index) |
367
|
|
|
{ |
368
|
|
|
return isset($this->condition[$index]); |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* unset condition |
373
|
|
|
* |
374
|
|
|
* @param scalar $index |
375
|
|
|
* @return void |
376
|
|
|
*/ |
377
|
|
|
public function unsetCondition($index) |
378
|
|
|
{ |
379
|
|
|
unset($this->condition[$index]); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* Gets as condition |
384
|
|
|
* |
385
|
|
|
* @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType[] |
386
|
|
|
*/ |
387
|
|
|
public function getCondition() |
388
|
|
|
{ |
389
|
|
|
return $this->condition; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* Sets a new condition |
394
|
|
|
* |
395
|
|
|
* @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType[] $condition |
396
|
|
|
* @return self |
397
|
|
|
*/ |
398
|
|
|
public function setCondition(array $condition) |
399
|
|
|
{ |
400
|
|
|
$msg = null; |
401
|
|
|
// if other arrays are empty, then the array we're assigning must not be empty |
402
|
|
|
$count = count($this->scalarProperty) + count($this->complexProperty) + count($this->complexTypeMapping); |
403
|
|
|
if (!$this->isValidArrayOK( |
404
|
|
|
$condition, |
405
|
|
|
'\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType', |
406
|
|
|
$msg, |
407
|
|
|
0 < $count ? 0 : 1 |
408
|
|
|
)) { |
409
|
|
|
throw new \InvalidArgumentException($msg); |
410
|
|
|
} |
411
|
|
|
$this->condition = $condition; |
412
|
|
|
return $this; |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
public function isOK(&$msg = null) |
416
|
|
|
{ |
417
|
|
|
if (!$this->isStringNotNullOrEmpty($this->name)) { |
418
|
|
|
$msg = 'Name cannot be null or empty'; |
419
|
|
|
return false; |
420
|
|
|
} |
421
|
|
View Code Duplication |
if (null != $this->typeName && !$this->isStringNotNullOrEmpty($this->typeName)) { |
|
|
|
|
422
|
|
|
$msg = 'Type name cannot be empty'; |
423
|
|
|
return false; |
424
|
|
|
} |
425
|
|
|
if (!$this->isTSimpleIdentifierValid($this->name)) { |
426
|
|
|
$msg = 'Name must be a valid TSimpleIdentifier'; |
427
|
|
|
return false; |
428
|
|
|
} |
429
|
|
|
$count = count($this->scalarProperty) + count($this->complexProperty) + count($this->condition) |
430
|
|
|
+ count($this->complexTypeMapping); |
431
|
|
|
if (1 > $count) { |
432
|
|
|
$msg = "Cannot have all arrays empty"; |
433
|
|
|
return false; |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
if (!$this->isValidArray( |
437
|
|
|
$this->scalarProperty, |
438
|
|
|
'\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TScalarPropertyType' |
439
|
|
|
)) { |
440
|
|
|
$msg = "Scalar property array not a valid array"; |
441
|
|
|
return false; |
442
|
|
|
} |
443
|
|
|
if (!$this->isChildArrayOK($this->scalarProperty, $msg)) { |
444
|
|
|
return false; |
445
|
|
|
} |
446
|
|
|
if (!$this->isValidArray( |
447
|
|
|
$this->complexProperty, |
448
|
|
|
'\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexPropertyType' |
449
|
|
|
)) { |
450
|
|
|
$msg = "Complex property array not a valid array"; |
451
|
|
|
return false; |
452
|
|
|
} |
453
|
|
|
if (!$this->isChildArrayOK($this->complexProperty, $msg)) { |
454
|
|
|
return false; |
455
|
|
|
} |
456
|
|
|
if (!$this->isValidArray( |
457
|
|
|
$this->condition, |
458
|
|
|
'\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TConditionType' |
459
|
|
|
)) { |
460
|
|
|
$msg = "Condition array not a valid array"; |
461
|
|
|
return false; |
462
|
|
|
} |
463
|
|
|
if (!$this->isChildArrayOK($this->condition, $msg)) { |
464
|
|
|
return false; |
465
|
|
|
} |
466
|
|
|
if (!$this->isValidArray( |
467
|
|
|
$this->complexTypeMapping, |
468
|
|
|
'\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TComplexTypeMappingType' |
469
|
|
|
)) { |
470
|
|
|
$msg = "Complex type mapping array not a valid array"; |
471
|
|
|
return false; |
472
|
|
|
} |
473
|
|
|
if (!$this->isChildArrayOK($this->complexTypeMapping, $msg)) { |
474
|
|
|
return false; |
475
|
|
|
} |
476
|
|
|
return true; |
477
|
|
|
} |
478
|
|
|
} |
479
|
|
|
|
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.