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; |
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
|
|
|
* @property \AlgoWeb\ODataMetadata\MetadataV3\edm\ssdl\TDocumentationType $documentation |
75
|
|
|
*/ |
76
|
|
|
private $documentation = null; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Gets as name |
80
|
|
|
* |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
|
|
public function getName() |
84
|
|
|
{ |
85
|
|
|
return $this->name; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Sets a new name |
90
|
|
|
* |
91
|
|
|
* @param string $name |
92
|
|
|
* @return self |
93
|
|
|
*/ |
94
|
|
|
public function setName($name) |
95
|
|
|
{ |
96
|
|
|
$this->name = $name; |
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Gets as type |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
public function getType() |
106
|
|
|
{ |
107
|
|
|
return $this->type; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Sets a new type |
112
|
|
|
* |
113
|
|
|
* @param string $type |
114
|
|
|
* @return self |
115
|
|
|
*/ |
116
|
|
|
public function setType($type) |
117
|
|
|
{ |
118
|
|
|
$this->type = $type; |
119
|
|
|
return $this; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Gets as nullable |
124
|
|
|
* |
125
|
|
|
* @return boolean |
126
|
|
|
*/ |
127
|
|
|
public function getNullable() |
128
|
|
|
{ |
129
|
|
|
return $this->nullable; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Sets a new nullable |
134
|
|
|
* |
135
|
|
|
* @param boolean $nullable |
136
|
|
|
* @return self |
137
|
|
|
*/ |
138
|
|
|
public function setNullable($nullable) |
139
|
|
|
{ |
140
|
|
|
$this->nullable = $nullable; |
141
|
|
|
return $this; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Gets as defaultValue |
146
|
|
|
* |
147
|
|
|
* @return string |
148
|
|
|
*/ |
149
|
|
|
public function getDefaultValue() |
150
|
|
|
{ |
151
|
|
|
return $this->defaultValue; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Sets a new defaultValue |
156
|
|
|
* |
157
|
|
|
* @param string $defaultValue |
158
|
|
|
* @return self |
159
|
|
|
*/ |
160
|
|
|
public function setDefaultValue($defaultValue) |
161
|
|
|
{ |
162
|
|
|
$this->defaultValue = $defaultValue; |
163
|
|
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Gets as maxLength |
168
|
|
|
* |
169
|
|
|
* @return string |
170
|
|
|
*/ |
171
|
|
|
public function getMaxLength() |
172
|
|
|
{ |
173
|
|
|
return $this->maxLength; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Sets a new maxLength |
178
|
|
|
* |
179
|
|
|
* @param string $maxLength |
180
|
|
|
* @return self |
181
|
|
|
*/ |
182
|
|
|
public function setMaxLength($maxLength) |
183
|
|
|
{ |
184
|
|
|
$this->maxLength = $maxLength; |
185
|
|
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Gets as fixedLength |
190
|
|
|
* |
191
|
|
|
* @return boolean |
192
|
|
|
*/ |
193
|
|
|
public function getFixedLength() |
194
|
|
|
{ |
195
|
|
|
return $this->fixedLength; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Sets a new fixedLength |
200
|
|
|
* |
201
|
|
|
* @param boolean $fixedLength |
202
|
|
|
* @return self |
203
|
|
|
*/ |
204
|
|
|
public function setFixedLength($fixedLength) |
205
|
|
|
{ |
206
|
|
|
$this->fixedLength = $fixedLength; |
207
|
|
|
return $this; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Gets as precision |
212
|
|
|
* |
213
|
|
|
* @return integer |
214
|
|
|
*/ |
215
|
|
|
public function getPrecision() |
216
|
|
|
{ |
217
|
|
|
return $this->precision; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Sets a new precision |
222
|
|
|
* |
223
|
|
|
* @param integer $precision |
224
|
|
|
* @return self |
225
|
|
|
*/ |
226
|
|
|
public function setPrecision($precision) |
227
|
|
|
{ |
228
|
|
|
$this->precision = $precision; |
229
|
|
|
return $this; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Gets as scale |
234
|
|
|
* |
235
|
|
|
* @return integer |
236
|
|
|
*/ |
237
|
|
|
public function getScale() |
238
|
|
|
{ |
239
|
|
|
return $this->scale; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Sets a new scale |
244
|
|
|
* |
245
|
|
|
* @param integer $scale |
246
|
|
|
* @return self |
247
|
|
|
*/ |
248
|
|
|
public function setScale($scale) |
249
|
|
|
{ |
250
|
|
|
$this->scale = $scale; |
251
|
|
|
return $this; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Gets as unicode |
256
|
|
|
* |
257
|
|
|
* @return boolean |
258
|
|
|
*/ |
259
|
|
|
public function getUnicode() |
260
|
|
|
{ |
261
|
|
|
return $this->unicode; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Sets a new unicode |
266
|
|
|
* |
267
|
|
|
* @param boolean $unicode |
268
|
|
|
* @return self |
269
|
|
|
*/ |
270
|
|
|
public function setUnicode($unicode) |
271
|
|
|
{ |
272
|
|
|
$this->unicode = $unicode; |
273
|
|
|
return $this; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Gets as collation |
278
|
|
|
* |
279
|
|
|
* @return string |
280
|
|
|
*/ |
281
|
|
|
public function getCollation() |
282
|
|
|
{ |
283
|
|
|
return $this->collation; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* Sets a new collation |
288
|
|
|
* |
289
|
|
|
* @param string $collation |
290
|
|
|
* @return self |
291
|
|
|
*/ |
292
|
|
|
public function setCollation($collation) |
293
|
|
|
{ |
294
|
|
|
$this->collation = $collation; |
295
|
|
|
return $this; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* Gets as sRID |
300
|
|
|
* |
301
|
|
|
* @return string |
302
|
|
|
*/ |
303
|
|
|
public function getSRID() |
304
|
|
|
{ |
305
|
|
|
return $this->sRID; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Sets a new sRID |
310
|
|
|
* |
311
|
|
|
* @param string $sRID |
312
|
|
|
* @return self |
313
|
|
|
*/ |
314
|
|
|
public function setSRID($sRID) |
315
|
|
|
{ |
316
|
|
|
$this->sRID = $sRID; |
317
|
|
|
return $this; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* Gets as documentation |
322
|
|
|
* |
323
|
|
|
* @return \AlgoWeb\ODataMetadata\MetadataV3\edm\ssdl\TDocumentationType |
324
|
|
|
*/ |
325
|
|
|
public function getDocumentation() |
326
|
|
|
{ |
327
|
|
|
return $this->documentation; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* Sets a new documentation |
332
|
|
|
* |
333
|
|
|
* @param \AlgoWeb\ODataMetadata\MetadataV3\edm\ssdl\TDocumentationType $documentation |
334
|
|
|
* @return self |
335
|
|
|
*/ |
336
|
|
|
public function setDocumentation(TDocumentationType $documentation) |
337
|
|
|
{ |
338
|
|
|
$this->documentation = $documentation; |
339
|
|
|
return $this; |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
public function isOK(&$msg = null) |
343
|
|
|
{ |
344
|
|
|
if (!$this->isStringNotNullOrEmpty($this->name)) { |
345
|
|
|
$msg = "Name cannot be null or empty"; |
346
|
|
|
return false; |
347
|
|
|
} |
348
|
|
|
if (!$this->isStringNotNullOrEmpty($this->type)) { |
349
|
|
|
$msg = "Type cannot be null or empty"; |
350
|
|
|
return false; |
351
|
|
|
} |
352
|
|
View Code Duplication |
if (null != $this->defaultValue && !$this->isStringNotNullOrEmpty($this->defaultValue)) { |
|
|
|
|
353
|
|
|
$msg = "Default value cannot be empty"; |
354
|
|
|
return false; |
355
|
|
|
} |
356
|
|
View Code Duplication |
if (null != $this->sRID && !$this->isStringNotNullOrEmpty($this->sRID)) { |
|
|
|
|
357
|
|
|
$msg = "SRID value cannot be empty"; |
358
|
|
|
return false; |
359
|
|
|
} |
360
|
|
View Code Duplication |
if (null != $this->collation && !$this->isStringNotNullOrEmpty($this->collation)) { |
|
|
|
|
361
|
|
|
$msg = "Collation value cannot be empty"; |
362
|
|
|
return false; |
363
|
|
|
} |
364
|
|
View Code Duplication |
if (null != $this->maxLength && !(is_numeric($this->maxLength) && 0 <= $this->maxLength)) { |
|
|
|
|
365
|
|
|
$msg = "Max length must be numeric and non-negative"; |
366
|
|
|
return false; |
367
|
|
|
} |
368
|
|
View Code Duplication |
if (null != $this->precision && !(is_numeric($this->precision) && 0 <= $this->precision)) { |
|
|
|
|
369
|
|
|
$msg = "Precision must be numeric and non-negative"; |
370
|
|
|
return false; |
371
|
|
|
} |
372
|
|
View Code Duplication |
if (null != $this->scale && !(is_numeric($this->scale) && 0 <= $this->scale)) { |
|
|
|
|
373
|
|
|
$msg = "Scale must be numeric and non-negative"; |
374
|
|
|
return false; |
375
|
|
|
} |
376
|
|
|
if (!$this->isTSimpleIdentifierValid($this->name)) { |
377
|
|
|
$msg = "Name must be valid TSimpleIdentifier"; |
378
|
|
|
return false; |
379
|
|
|
} |
380
|
|
|
if (!$this->isTPropertyTypeValid($this->type)) { |
381
|
|
|
$msg = "Type must be valid TPropertyType"; |
382
|
|
|
return false; |
383
|
|
|
} |
384
|
|
|
|
385
|
|
|
if (!$this->isObjectNullOrOK($this->documentation, $msg)) { |
386
|
|
|
return false; |
387
|
|
|
} |
388
|
|
|
return true; |
389
|
|
|
} |
390
|
|
|
} |
391
|
|
|
|
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.