Passed
Push — master ( 497f66...189420 )
by Alex
04:13
created

TCommonPropertyAttributesTrait   C

Complexity

Total Complexity 55

Size/Duplication

Total Lines 446
Duplicated Lines 8.07 %

Coupling/Cohesion

Components 1
Dependencies 12

Importance

Changes 0
Metric Value
wmc 55
lcom 1
cbo 12
dl 36
loc 446
rs 6.8
c 0
b 0
f 0

29 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A setName() 0 5 1
A getType() 0 4 1
A setType() 0 5 1
A getNullable() 0 4 1
A setNullable() 0 5 1
A getDefaultValue() 0 4 1
A setDefaultValue() 0 5 1
A getMaxLength() 0 4 1
A setMaxLength() 0 5 1
A getFixedLength() 0 4 1
A setFixedLength() 0 5 1
A getPrecision() 0 4 1
A setPrecision() 0 5 1
A getScale() 0 4 1
A setScale() 0 5 1
A getUnicode() 0 4 1
A setUnicode() 0 5 1
A getCollation() 0 4 1
A setCollation() 0 5 1
A getSRID() 0 4 1
A setSRID() 0 5 1
A getConcurrencyMode() 0 4 1
A setConcurrencyMode() 0 5 1
A getSetterAccess() 0 4 1
A setSetterAccess() 0 5 1
A getGetterAccess() 0 4 1
A setGetterAccess() 0 5 1
C isTCommonPropertyAttributesValid() 36 61 27

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like TCommonPropertyAttributesTrait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use TCommonPropertyAttributesTrait, and based on these observations, apply Extract Interface, too.

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