Passed
Push — master ( 143625...0aa694 )
by Alex
03:46
created

TValueTermType::isOK()   C

Complexity

Conditions 14
Paths 54

Size

Total Lines 54
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 6.7343
c 0
b 0
f 0
cc 14
eloc 37
nc 54
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace AlgoWeb\ODataMetadata\MetadataV3\edm;
4
5
use AlgoWeb\ODataMetadata\IsOK;
6
use AlgoWeb\ODataMetadata\MetadataV3\edm\Groups\GExpressionTrait;
7
use AlgoWeb\ODataMetadata\MetadataV3\edm\Groups\TFacetAttributesTrait;
8
use AlgoWeb\ODataMetadata\MetadataV3\edm\IsOKTraits\TQualifiedNameTrait;
9
use AlgoWeb\ODataMetadata\MetadataV3\edm\IsOKTraits\TSimpleIdentifierTrait;
10
use AlgoWeb\ODataMetadata\MetadataV3\edm\IsOKTraits\TWrappedFunctionReturnTypeTrait;
11
12
/**
13
 * Class representing TValueTermType
14
 *
15
 *
16
 * XSD Type: TValueTerm
17
 */
18
class TValueTermType extends IsOK
19
{
20
    use TFacetAttributesTrait,
21
        GExpressionTrait,
22
        TQualifiedNameTrait,
23
        TSimpleIdentifierTrait,
24
        TWrappedFunctionReturnTypeTrait;
25
26
    public function __construct()
27
    {
28
        $this->gExpressionMaximum = 1;
29
        $this->gExpressionMinimum = 1;
30
    }
31
    /**
32
     * @property string $name
33
     */
34
    private $name = null;
35
36
    /**
37
     * @property string $type
38
     */
39
    private $type = null;
40
41
    /**
42
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType $documentation
43
     */
44
    private $documentation = null;
45
46
    /**
47
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TCollectionTypeType $collectionType
48
     */
49
    private $collectionType = null;
50
51
    /**
52
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TReferenceTypeType $referenceType
53
     */
54
    private $referenceType = null;
55
56
    /**
57
     * @property \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyType[] $rowType
58
     */
59
    private $rowType = null;
60
61
    /**
62
     * Gets as name
63
     *
64
     * @return string
65
     */
66
    public function getName()
67
    {
68
        return $this->name;
69
    }
70
71
    /**
72
     * Sets a new name
73
     *
74
     * @param string $name
75
     * @return self
76
     */
77
    public function setName($name)
78
    {
79
        $this->name = $name;
80
        return $this;
81
    }
82
83
    /**
84
     * Gets as type
85
     *
86
     * @return string
87
     */
88
    public function getType()
89
    {
90
        return $this->type;
91
    }
92
93
    /**
94
     * Sets a new type
95
     *
96
     * @param string $type
97
     * @return self
98
     */
99
    public function setType($type)
100
    {
101
        $this->type = $type;
102
        return $this;
103
    }
104
105
    /**
106
     * Gets as documentation
107
     *
108
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType
109
     */
110
    public function getDocumentation()
111
    {
112
        return $this->documentation;
113
    }
114
115
    /**
116
     * Sets a new documentation
117
     *
118
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType $documentation
119
     * @return self
120
     */
121
    public function setDocumentation(TDocumentationType $documentation)
122
    {
123
        $this->documentation = $documentation;
124
        return $this;
125
    }
126
127
    /**
128
     * Gets as collectionType
129
     *
130
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TCollectionTypeType
131
     */
132
    public function getCollectionType()
133
    {
134
        return $this->collectionType;
135
    }
136
137
    /**
138
     * Sets a new collectionType
139
     *
140
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TCollectionTypeType $collectionType
141
     * @return self
142
     */
143
    public function setCollectionType(TCollectionTypeType $collectionType)
144
    {
145
        $this->collectionType = $collectionType;
146
        return $this;
147
    }
148
149
    /**
150
     * Gets as referenceType
151
     *
152
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TReferenceTypeType
153
     */
154
    public function getReferenceType()
155
    {
156
        return $this->referenceType;
157
    }
158
159
    /**
160
     * Sets a new referenceType
161
     *
162
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TReferenceTypeType $referenceType
163
     * @return self
164
     */
165
    public function setReferenceType(TReferenceTypeType $referenceType)
166
    {
167
        $this->referenceType = $referenceType;
168
        return $this;
169
    }
170
171
    /**
172
     * Adds as property
173
     *
174
     * @return self
175
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyType $property
176
     */
177
    public function addToRowType(TPropertyType $property)
178
    {
179
        $this->rowType[] = $property;
180
        return $this;
181
    }
182
183
    /**
184
     * isset rowType
185
     *
186
     * @param scalar $index
187
     * @return boolean
188
     */
189
    public function issetRowType($index)
190
    {
191
        return isset($this->rowType[$index]);
192
    }
193
194
    /**
195
     * unset rowType
196
     *
197
     * @param scalar $index
198
     * @return void
199
     */
200
    public function unsetRowType($index)
201
    {
202
        unset($this->rowType[$index]);
203
    }
204
205
    /**
206
     * Gets as rowType
207
     *
208
     * @return \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyType[]
209
     */
210
    public function getRowType()
211
    {
212
        return $this->rowType;
213
    }
214
215
    /**
216
     * Sets a new rowType
217
     *
218
     * @param \AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyType[] $rowType
219
     * @return self
220
     */
221
    public function setRowType(array $rowType)
222
    {
223
        $this->rowType = $rowType;
224
        return $this;
225
    }
226
227
    public function isOK(&$msg = null)
228
    {
229
        if (!$this->isTSimpleIdentifierValid($this->name)) {
230
            $msg = "Name must be a valid TSimpleIdentifier";
231
            return false;
232
        }
233
        if (null != $this->type && !$this->isTWrappedFunctionTypeValid($this->type)) {
234
            $msg = "Type must be a valid TWrappedFunctionType";
235
            return false;
236
        }
237
238
        if (!$this->isObjectNullOrType(
239
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\TDocumentationType',
240
            $this->documentation,
241
            $msg
242
        )) {
243
            return false;
244
        }
245
        if (!$this->isObjectNullOrType(
246
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\TCollectionTypeType',
247
            $this->collectionType,
248
            $msg
249
        )) {
250
            return false;
251
        }
252
        if (!$this->isObjectNullOrType(
253
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\TReferenceTypeType',
254
            $this->referenceType,
255
            $msg
256
        )) {
257
            return false;
258
        }
259
        if (!$this->isValidArrayOK(
260
            $this->rowType,
261
            '\AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyType',
262
            $msg
263
        )) {
264
            return false;
265
        }
266
267
        $count = (isset($this->collectionType) ? 1 : 0)
268
                 + (isset($this->referenceType) ? 1 : 0)
269
                 + (isset($this->documentation) ? 1 : 0)
270
                 + (0 < count($this->rowType) ? 1 : 0);
271
        if (1 < $count) {
272
            $msg = "At most one of documentation, collection type, reference type and row type can be set/nonempty";
273
            return false;
274
        }
275
276
        if (!$this->isTFacetAttributesTraitValid($msg)) {
277
            return false;
278
        }
279
        return true;
280
    }
281
}
282