Completed
Push — master ( 941487...1b7170 )
by Alex
12:44 queued 07:23
created

TEntityContainerMappingType   B

Complexity

Total Complexity 40

Size/Duplication

Total Lines 366
Duplicated Lines 18.03 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 40
lcom 1
cbo 5
dl 66
loc 366
rs 8.2608
c 0
b 0
f 0

22 Methods

Rating   Name   Duplication   Size   Complexity  
A getCdmEntityContainer() 0 4 1
A setCdmEntityContainer() 0 13 3
A getStorageEntityContainer() 0 4 1
A setStorageEntityContainer() 0 9 2
A getGenerateUpdateViews() 0 4 1
A setGenerateUpdateViews() 0 5 1
A addToEntitySetMapping() 9 9 2
A issetEntitySetMapping() 0 4 1
A unsetEntitySetMapping() 0 4 1
A getEntitySetMapping() 0 4 1
A setEntitySetMapping() 13 13 2
A addToAssociationSetMapping() 9 9 2
A issetAssociationSetMapping() 0 4 1
A unsetAssociationSetMapping() 0 4 1
A getAssociationSetMapping() 0 4 1
A setAssociationSetMapping() 13 13 2
A addToFunctionImportMapping() 9 9 2
A issetFunctionImportMapping() 0 4 1
A unsetFunctionImportMapping() 0 4 1
A getFunctionImportMapping() 0 4 1
A setFunctionImportMapping() 13 13 2
D isOK() 0 46 10

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 TEntityContainerMappingType 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 TEntityContainerMappingType, and based on these observations, apply Extract Interface, too.

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 TEntityContainerMappingType
10
 *
11
 * Type for EntityContainerMapping element
12
 *
13
 * XSD Type: TEntityContainerMapping
14
 */
15
class TEntityContainerMappingType extends IsOK
16
{
17
    use TSimpleIdentifierTrait;
18
    /**
19
     * @property string $cdmEntityContainer
20
     */
21
    private $cdmEntityContainer = null;
22
23
    /**
24
     * @property string $storageEntityContainer
25
     */
26
    private $storageEntityContainer = null;
27
28
    /**
29
     * @property boolean $generateUpdateViews
30
     */
31
    private $generateUpdateViews = null;
32
33
    /**
34
     * @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TEntitySetMappingType[] $entitySetMapping
35
     */
36
    private $entitySetMapping = [];
37
38
    /**
39
     * @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TAssociationSetMappingType[]
40
     * $associationSetMapping
41
     */
42
    private $associationSetMapping = [];
43
44
    /**
45
     * @property \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TFunctionImportMappingType[]
46
     * $functionImportMapping
47
     */
48
    private $functionImportMapping = [];
49
50
    /**
51
     * Gets as cdmEntityContainer
52
     *
53
     * @return string
54
     */
55
    public function getCdmEntityContainer()
56
    {
57
        return $this->cdmEntityContainer;
58
    }
59
60
    /**
61
     * Sets a new cdmEntityContainer
62
     *
63
     * @param string $cdmEntityContainer
64
     * @return self
65
     */
66
    public function setCdmEntityContainer($cdmEntityContainer)
67
    {
68
        if (!$this->isStringNotNullOrEmpty($cdmEntityContainer)) {
69
            $msg = 'CDM entity container cannot be null or empty';
70
            throw new \InvalidArgumentException($msg);
71
        }
72
        if (!$this->isTSimpleIdentifierValid($cdmEntityContainer)) {
73
            $msg = 'CDM entity container must be a valid TSimpleIdentifier';
74
            throw new \InvalidArgumentException($msg);
75
        }
76
        $this->cdmEntityContainer = $cdmEntityContainer;
77
        return $this;
78
    }
79
80
    /**
81
     * Gets as storageEntityContainer
82
     *
83
     * @return string
84
     */
85
    public function getStorageEntityContainer()
86
    {
87
        return $this->storageEntityContainer;
88
    }
89
90
    /**
91
     * Sets a new storageEntityContainer
92
     *
93
     * @param string $storageEntityContainer
94
     * @return self
95
     */
96
    public function setStorageEntityContainer($storageEntityContainer)
97
    {
98
        if (!$this->isStringNotNullOrEmpty($storageEntityContainer)) {
99
            $msg = 'Storage entity container cannot be null or empty';
100
            throw new \InvalidArgumentException($msg);
101
        }
102
        $this->storageEntityContainer = $storageEntityContainer;
103
        return $this;
104
    }
105
106
    /**
107
     * Gets as generateUpdateViews
108
     *
109
     * @return boolean
110
     */
111
    public function getGenerateUpdateViews()
112
    {
113
        return $this->generateUpdateViews;
114
    }
115
116
    /**
117
     * Sets a new generateUpdateViews
118
     *
119
     * @param boolean $generateUpdateViews
120
     * @return self
121
     */
122
    public function setGenerateUpdateViews($generateUpdateViews)
123
    {
124
        $this->generateUpdateViews = $generateUpdateViews;
125
        return $this;
126
    }
127
128
    /**
129
     * Adds as entitySetMapping
130
     *
131
     * @return self
132
     * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TEntitySetMappingType $entitySetMapping
133
     */
134 View Code Duplication
    public function addToEntitySetMapping(TEntitySetMappingType $entitySetMapping)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
135
    {
136
        $msg = null;
137
        if (!$entitySetMapping->isOK($msg)) {
138
            throw new \InvalidArgumentException($msg);
139
        }
140
        $this->entitySetMapping[] = $entitySetMapping;
141
        return $this;
142
    }
143
144
    /**
145
     * isset entitySetMapping
146
     *
147
     * @param scalar $index
148
     * @return boolean
149
     */
150
    public function issetEntitySetMapping($index)
151
    {
152
        return isset($this->entitySetMapping[$index]);
153
    }
154
155
    /**
156
     * unset entitySetMapping
157
     *
158
     * @param scalar $index
159
     * @return void
160
     */
161
    public function unsetEntitySetMapping($index)
162
    {
163
        unset($this->entitySetMapping[$index]);
164
    }
165
166
    /**
167
     * Gets as entitySetMapping
168
     *
169
     * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TEntitySetMappingType[]
170
     */
171
    public function getEntitySetMapping()
172
    {
173
        return $this->entitySetMapping;
174
    }
175
176
    /**
177
     * Sets a new entitySetMapping
178
     *
179
     * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TEntitySetMappingType[] $entitySetMapping
180
     * @return self
181
     */
182 View Code Duplication
    public function setEntitySetMapping(array $entitySetMapping)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
183
    {
184
        $msg = null;
185
        if (!$this->isValidArrayOK(
186
            $entitySetMapping,
187
            '\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TEntitySetMappingType',
188
            $msg
189
        )) {
190
            throw new \InvalidArgumentException($msg);
191
        }
192
        $this->entitySetMapping = $entitySetMapping;
193
        return $this;
194
    }
195
196
    /**
197
     * Adds as associationSetMapping
198
     *
199
     * @return self
200
     * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TAssociationSetMappingType $associationSetMapping
201
     */
202 View Code Duplication
    public function addToAssociationSetMapping(TAssociationSetMappingType $associationSetMapping)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
203
    {
204
        $msg = null;
205
        if (!$associationSetMapping->isOK($msg)) {
206
            throw new \InvalidArgumentException($msg);
207
        }
208
        $this->associationSetMapping[] = $associationSetMapping;
209
        return $this;
210
    }
211
212
    /**
213
     * isset associationSetMapping
214
     *
215
     * @param scalar $index
216
     * @return boolean
217
     */
218
    public function issetAssociationSetMapping($index)
219
    {
220
        return isset($this->associationSetMapping[$index]);
221
    }
222
223
    /**
224
     * unset associationSetMapping
225
     *
226
     * @param scalar $index
227
     * @return void
228
     */
229
    public function unsetAssociationSetMapping($index)
230
    {
231
        unset($this->associationSetMapping[$index]);
232
    }
233
234
    /**
235
     * Gets as associationSetMapping
236
     *
237
     * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TAssociationSetMappingType[]
238
     */
239
    public function getAssociationSetMapping()
240
    {
241
        return $this->associationSetMapping;
242
    }
243
244
    /**
245
     * Sets a new associationSetMapping
246
     *
247
     * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TAssociationSetMappingType[]
248
     * $associationSetMapping
249
     * @return self
250
     */
251 View Code Duplication
    public function setAssociationSetMapping(array $associationSetMapping)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
252
    {
253
        $msg = null;
254
        if (!$this->isValidArrayOK(
255
            $associationSetMapping,
256
            '\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TAssociationSetMappingType',
257
            $msg
258
        )) {
259
            throw new \InvalidArgumentException($msg);
260
        }
261
        $this->associationSetMapping = $associationSetMapping;
262
        return $this;
263
    }
264
265
    /**
266
     * Adds as functionImportMapping
267
     *
268
     * @return self
269
     * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TFunctionImportMappingType $functionImportMapping
270
     */
271 View Code Duplication
    public function addToFunctionImportMapping(TFunctionImportMappingType $functionImportMapping)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
272
    {
273
        $msg = null;
274
        if (!$functionImportMapping->isOK($msg)) {
275
            throw new \InvalidArgumentException($msg);
276
        }
277
        $this->functionImportMapping[] = $functionImportMapping;
278
        return $this;
279
    }
280
281
    /**
282
     * isset functionImportMapping
283
     *
284
     * @param scalar $index
285
     * @return boolean
286
     */
287
    public function issetFunctionImportMapping($index)
288
    {
289
        return isset($this->functionImportMapping[$index]);
290
    }
291
292
    /**
293
     * unset functionImportMapping
294
     *
295
     * @param scalar $index
296
     * @return void
297
     */
298
    public function unsetFunctionImportMapping($index)
299
    {
300
        unset($this->functionImportMapping[$index]);
301
    }
302
303
    /**
304
     * Gets as functionImportMapping
305
     *
306
     * @return \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TFunctionImportMappingType[]
307
     */
308
    public function getFunctionImportMapping()
309
    {
310
        return $this->functionImportMapping;
311
    }
312
313
    /**
314
     * Sets a new functionImportMapping
315
     *
316
     * @param \AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TFunctionImportMappingType[]
317
     * $functionImportMapping
318
     * @return self
319
     */
320 View Code Duplication
    public function setFunctionImportMapping(array $functionImportMapping)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
321
    {
322
        $msg = null;
323
        if (!$this->isValidArrayOK(
324
            $functionImportMapping,
325
            '\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TFunctionImportMappingType',
326
            $msg
327
        )) {
328
            throw new \InvalidArgumentException($msg);
329
        }
330
        $this->functionImportMapping = $functionImportMapping;
331
        return $this;
332
    }
333
334
    public function isOK(&$msg = null)
335
    {
336
        if (!$this->isStringNotNullOrEmpty($this->cdmEntityContainer)) {
337
            $msg = 'CDM entity container cannot be null or empty';
338
            return false;
339
        }
340
        if (!$this->isStringNotNullOrEmpty($this->storageEntityContainer)) {
341
            $msg = 'Storage entity container cannot be null or empty';
342
            return false;
343
        }
344
        if (!$this->isTSimpleIdentifierValid($this->cdmEntityContainer)) {
345
            $msg = 'CDM entity container must be a valid TSimpleIdentifier';
346
            return false;
347
        }
348
        if (!$this->isValidArray(
349
            $this->entitySetMapping,
350
            '\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TEntitySetMappingType'
351
        )) {
352
            $msg = "Entity set mapping array not a valid array";
353
            return false;
354
        }
355
        if (!$this->isChildArrayOK($this->entitySetMapping, $msg)) {
356
            return false;
357
        }
358
        if (!$this->isValidArray(
359
            $this->associationSetMapping,
360
            '\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TAssociationSetMappingType'
361
        )) {
362
            $msg = "Association set mapping array not a valid array";
363
            return false;
364
        }
365
        if (!$this->isChildArrayOK($this->associationSetMapping, $msg)) {
366
            return false;
367
        }
368
        if (!$this->isValidArray(
369
            $this->functionImportMapping,
370
            '\AlgoWeb\ODataMetadata\MetadataV3\mapping\cs\TFunctionImportMappingType'
371
        )) {
372
            $msg = "Function import mapping array not a valid array";
373
            return false;
374
        }
375
        if (!$this->isChildArrayOK($this->functionImportMapping, $msg)) {
376
            return false;
377
        }
378
        return true;
379
    }
380
}
381