1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlgoWeb\ODataMetadata\MetadataV3\edm\ssdl; |
4
|
|
|
|
5
|
|
|
use AlgoWeb\ODataMetadata\IsOK; |
6
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\ssdl\IsOKTraits\TPropertyTypeTrait; |
7
|
|
|
use AlgoWeb\ODataMetadata\MetadataV3\edm\ssdl\IsOKTraits\TSimpleIdentifierTrait; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class representing TPropertyType |
11
|
|
|
* |
12
|
|
|
* |
13
|
|
|
* XSD Type: TProperty |
14
|
|
|
*/ |
15
|
|
|
class TPropertyType extends IsOK |
16
|
|
|
{ |
17
|
|
|
use TSimpleIdentifierTrait, TPropertyTypeTrait, GEmptyElementExtensibilityTrait; |
18
|
|
|
/** |
19
|
|
|
* @property string $name |
20
|
|
|
*/ |
21
|
|
|
private $name = null; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @property string $type |
25
|
|
|
*/ |
26
|
|
|
private $type = null; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @property boolean $nullable |
30
|
|
|
*/ |
31
|
|
|
private $nullable = true; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @property string $defaultValue |
35
|
|
|
*/ |
36
|
|
|
private $defaultValue = null; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @property string $maxLength |
40
|
|
|
*/ |
41
|
|
|
private $maxLength = null; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @property boolean $fixedLength |
45
|
|
|
*/ |
46
|
|
|
private $fixedLength = null; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @property integer $precision |
50
|
|
|
*/ |
51
|
|
|
private $precision = null; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @property integer $scale |
55
|
|
|
*/ |
56
|
|
|
private $scale = null; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @property boolean $unicode |
60
|
|
|
*/ |
61
|
|
|
private $unicode = null; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @property string $collation |
65
|
|
|
*/ |
66
|
|
|
private $collation = null; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @property string $sRID |
70
|
|
|
*/ |
71
|
|
|
private $sRID = null; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Gets as name |
75
|
|
|
* |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
public function getName() |
79
|
|
|
{ |
80
|
|
|
return $this->name; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Sets a new name |
85
|
|
|
* |
86
|
|
|
* @param string $name |
87
|
|
|
* @return self |
88
|
|
|
*/ |
89
|
|
View Code Duplication |
public function setName($name) |
|
|
|
|
90
|
|
|
{ |
91
|
|
|
$msg = null; |
|
|
|
|
92
|
|
|
if (!$this->isStringNotNullOrEmpty($name)) { |
93
|
|
|
$msg = "Name cannot be null or empty"; |
94
|
|
|
throw new \InvalidArgumentException($msg); |
95
|
|
|
} |
96
|
|
|
if (!$this->isTSimpleIdentifierValid($name)) { |
97
|
|
|
$msg = "Name must be valid TSimpleIdentifier"; |
98
|
|
|
throw new \InvalidArgumentException($msg); |
99
|
|
|
} |
100
|
|
|
$this->name = $name; |
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Gets as type |
106
|
|
|
* |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
public function getType() |
110
|
|
|
{ |
111
|
|
|
return $this->type; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Sets a new type |
116
|
|
|
* |
117
|
|
|
* @param string $type |
118
|
|
|
* @return self |
119
|
|
|
*/ |
120
|
|
View Code Duplication |
public function setType($type) |
|
|
|
|
121
|
|
|
{ |
122
|
|
|
$msg = null; |
|
|
|
|
123
|
|
|
if (!$this->isStringNotNullOrEmpty($type)) { |
124
|
|
|
$msg = "Type cannot be null or empty"; |
125
|
|
|
throw new \InvalidArgumentException($msg); |
126
|
|
|
} |
127
|
|
|
if (!$this->isTPropertyTypeValid($type)) { |
128
|
|
|
$msg = "Type must be valid TPropertyType"; |
129
|
|
|
throw new \InvalidArgumentException($msg); |
130
|
|
|
} |
131
|
|
|
$this->type = $type; |
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Gets as nullable |
137
|
|
|
* |
138
|
|
|
* @return boolean |
139
|
|
|
*/ |
140
|
|
|
public function getNullable() |
141
|
|
|
{ |
142
|
|
|
return $this->nullable; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Sets a new nullable |
147
|
|
|
* |
148
|
|
|
* @param boolean $nullable |
149
|
|
|
* @return self |
150
|
|
|
*/ |
151
|
|
|
public function setNullable($nullable) |
152
|
|
|
{ |
153
|
|
|
$this->nullable = boolval($nullable); |
154
|
|
|
return $this; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Gets as defaultValue |
159
|
|
|
* |
160
|
|
|
* @return string |
161
|
|
|
*/ |
162
|
|
|
public function getDefaultValue() |
163
|
|
|
{ |
164
|
|
|
return $this->defaultValue; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Sets a new defaultValue |
169
|
|
|
* |
170
|
|
|
* @param string $defaultValue |
171
|
|
|
* @return self |
172
|
|
|
*/ |
173
|
|
View Code Duplication |
public function setDefaultValue($defaultValue) |
|
|
|
|
174
|
|
|
{ |
175
|
|
|
$msg = null; |
|
|
|
|
176
|
|
|
if (null != $defaultValue && !$this->isStringNotNullOrEmpty($defaultValue)) { |
177
|
|
|
$msg = "Default value cannot be empty"; |
178
|
|
|
throw new \InvalidArgumentException($msg); |
179
|
|
|
} |
180
|
|
|
$this->defaultValue = $defaultValue; |
181
|
|
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Gets as maxLength |
186
|
|
|
* |
187
|
|
|
* @return string |
188
|
|
|
*/ |
189
|
|
|
public function getMaxLength() |
190
|
|
|
{ |
191
|
|
|
return $this->maxLength; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Sets a new maxLength |
196
|
|
|
* |
197
|
|
|
* @param string $maxLength |
198
|
|
|
* @return self |
199
|
|
|
*/ |
200
|
|
|
public function setMaxLength($maxLength) |
201
|
|
|
{ |
202
|
|
|
$msg = null; |
|
|
|
|
203
|
|
|
if (null != $maxLength && !(is_numeric($maxLength) && 0 <= $maxLength)) { |
204
|
|
|
$msg = "Max length must be numeric and non-negative"; |
205
|
|
|
throw new \InvalidArgumentException($msg); |
206
|
|
|
} |
207
|
|
|
$this->maxLength = $maxLength; |
208
|
|
|
return $this; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Gets as fixedLength |
213
|
|
|
* |
214
|
|
|
* @return boolean |
215
|
|
|
*/ |
216
|
|
|
public function getFixedLength() |
217
|
|
|
{ |
218
|
|
|
return $this->fixedLength; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Sets a new fixedLength |
223
|
|
|
* |
224
|
|
|
* @param boolean $fixedLength |
225
|
|
|
* @return self |
226
|
|
|
*/ |
227
|
|
|
public function setFixedLength($fixedLength) |
228
|
|
|
{ |
229
|
|
|
$this->fixedLength = boolval($fixedLength); |
230
|
|
|
return $this; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Gets as precision |
235
|
|
|
* |
236
|
|
|
* @return integer |
237
|
|
|
*/ |
238
|
|
|
public function getPrecision() |
239
|
|
|
{ |
240
|
|
|
return $this->precision; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Sets a new precision |
245
|
|
|
* |
246
|
|
|
* @param integer $precision |
247
|
|
|
* @return self |
248
|
|
|
*/ |
249
|
|
View Code Duplication |
public function setPrecision($precision) |
|
|
|
|
250
|
|
|
{ |
251
|
|
|
$msg = null; |
|
|
|
|
252
|
|
|
if (null != $precision && !(is_numeric($precision) && 0 <= $precision)) { |
253
|
|
|
$msg = "Precision must be numeric and non-negative"; |
254
|
|
|
throw new \InvalidArgumentException($msg); |
255
|
|
|
} |
256
|
|
|
$this->precision = $precision; |
257
|
|
|
return $this; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Gets as scale |
262
|
|
|
* |
263
|
|
|
* @return integer |
264
|
|
|
*/ |
265
|
|
|
public function getScale() |
266
|
|
|
{ |
267
|
|
|
return $this->scale; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Sets a new scale |
272
|
|
|
* |
273
|
|
|
* @param integer $scale |
274
|
|
|
* @return self |
275
|
|
|
*/ |
276
|
|
View Code Duplication |
public function setScale($scale) |
|
|
|
|
277
|
|
|
{ |
278
|
|
|
$msg = null; |
|
|
|
|
279
|
|
|
if (null != $scale && !(is_numeric($scale) && 0 <= $scale)) { |
280
|
|
|
$msg = "Scale must be numeric and non-negative"; |
281
|
|
|
throw new \InvalidArgumentException($msg); |
282
|
|
|
} |
283
|
|
|
$this->scale = $scale; |
284
|
|
|
return $this; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Gets as unicode |
289
|
|
|
* |
290
|
|
|
* @return boolean |
291
|
|
|
*/ |
292
|
|
|
public function getUnicode() |
293
|
|
|
{ |
294
|
|
|
return $this->unicode; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* Sets a new unicode |
299
|
|
|
* |
300
|
|
|
* @param boolean $unicode |
301
|
|
|
* @return self |
302
|
|
|
*/ |
303
|
|
|
public function setUnicode($unicode) |
304
|
|
|
{ |
305
|
|
|
$this->unicode = $unicode; |
306
|
|
|
return $this; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* Gets as collation |
311
|
|
|
* |
312
|
|
|
* @return string |
313
|
|
|
*/ |
314
|
|
|
public function getCollation() |
315
|
|
|
{ |
316
|
|
|
return $this->collation; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* Sets a new collation |
321
|
|
|
* |
322
|
|
|
* @param string $collation |
323
|
|
|
* @return self |
324
|
|
|
*/ |
325
|
|
View Code Duplication |
public function setCollation($collation) |
|
|
|
|
326
|
|
|
{ |
327
|
|
|
$msg = null; |
|
|
|
|
328
|
|
|
if (null != $collation && !$this->isStringNotNullOrEmpty($collation)) { |
329
|
|
|
$msg = "Collation value cannot be empty"; |
330
|
|
|
throw new \InvalidArgumentException($msg); |
331
|
|
|
} |
332
|
|
|
$this->collation = $collation; |
333
|
|
|
return $this; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* Gets as sRID |
338
|
|
|
* |
339
|
|
|
* @return string |
340
|
|
|
*/ |
341
|
|
|
public function getSRID() |
342
|
|
|
{ |
343
|
|
|
return $this->sRID; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* Sets a new sRID |
348
|
|
|
* |
349
|
|
|
* @param string $sRID |
350
|
|
|
* @return self |
351
|
|
|
*/ |
352
|
|
View Code Duplication |
public function setSRID($sRID) |
|
|
|
|
353
|
|
|
{ |
354
|
|
|
$msg = null; |
|
|
|
|
355
|
|
|
if (null != $sRID && !$this->isStringNotNullOrEmpty($sRID)) { |
356
|
|
|
$msg = "SRID value cannot be empty"; |
357
|
|
|
throw new \InvalidArgumentException($msg); |
358
|
|
|
} |
359
|
|
|
$this->sRID = $sRID; |
360
|
|
|
return $this; |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
public function isOK(&$msg = null) |
364
|
|
|
{ |
365
|
|
|
if (!$this->isStringNotNullOrEmpty($this->name)) { |
366
|
|
|
$msg = "Name cannot be null or empty"; |
367
|
|
|
return false; |
368
|
|
|
} |
369
|
|
|
if (!$this->isStringNotNullOrEmpty($this->type)) { |
370
|
|
|
$msg = "Type cannot be null or empty"; |
371
|
|
|
return false; |
372
|
|
|
} |
373
|
|
View Code Duplication |
if (null != $this->defaultValue && !$this->isStringNotNullOrEmpty($this->defaultValue)) { |
|
|
|
|
374
|
|
|
$msg = "Default value cannot be empty"; |
375
|
|
|
return false; |
376
|
|
|
} |
377
|
|
View Code Duplication |
if (null != $this->sRID && !$this->isStringNotNullOrEmpty($this->sRID)) { |
|
|
|
|
378
|
|
|
$msg = "SRID value cannot be empty"; |
379
|
|
|
return false; |
380
|
|
|
} |
381
|
|
View Code Duplication |
if (null != $this->collation && !$this->isStringNotNullOrEmpty($this->collation)) { |
|
|
|
|
382
|
|
|
$msg = "Collation value cannot be empty"; |
383
|
|
|
return false; |
384
|
|
|
} |
385
|
|
View Code Duplication |
if (null != $this->maxLength && !(is_numeric($this->maxLength) && 0 <= $this->maxLength)) { |
|
|
|
|
386
|
|
|
$msg = "Max length must be numeric and non-negative"; |
387
|
|
|
return false; |
388
|
|
|
} |
389
|
|
View Code Duplication |
if (null != $this->precision && !(is_numeric($this->precision) && 0 <= $this->precision)) { |
|
|
|
|
390
|
|
|
$msg = "Precision must be numeric and non-negative"; |
391
|
|
|
return false; |
392
|
|
|
} |
393
|
|
View Code Duplication |
if (null != $this->scale && !(is_numeric($this->scale) && 0 <= $this->scale)) { |
|
|
|
|
394
|
|
|
$msg = "Scale must be numeric and non-negative"; |
395
|
|
|
return false; |
396
|
|
|
} |
397
|
|
|
if (!$this->isTSimpleIdentifierValid($this->name)) { |
398
|
|
|
$msg = "Name must be valid TSimpleIdentifier"; |
399
|
|
|
return false; |
400
|
|
|
} |
401
|
|
|
if (!$this->isTPropertyTypeValid($this->type)) { |
402
|
|
|
$msg = "Type must be valid TPropertyType"; |
403
|
|
|
return false; |
404
|
|
|
} |
405
|
|
|
if (!$this->isExtensibilityElementOK($msg)) { |
406
|
|
|
return false; |
407
|
|
|
} |
408
|
|
|
return true; |
409
|
|
|
} |
410
|
|
|
} |
411
|
|
|
|
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.