Passed
Push — master ( 8bcd2b...df571d )
by Christopher
02:43
created

FunctionImport::setMethodAccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlgoWeb\ODataMetadata\MetadataV3\Edm\EntityContainer;
6
7
use AlgoWeb\ODataMetadata\MetadataV3\AccessorType;
8
use AlgoWeb\ODataMetadata\MetadataV3\DomBase;
9
use AlgoWeb\ODataMetadata\MetadataV3\Edm\Concerns\Expressions\HasEntitySetReferenceExpression;
10
use AlgoWeb\ODataMetadata\MetadataV3\Edm\Concerns\HasDocumentation;
11
use AlgoWeb\ODataMetadata\MetadataV3\Edm\Concerns\HasValueAnnotation;
12
use AlgoWeb\ODataMetadata\MetadataV3\Edm\EdmBase;
13
use AlgoWeb\ODataMetadata\MetadataV3\Edm\EntityContainer\FunctionImport\ParameterType;
14
use AlgoWeb\ODataMetadata\MetadataV3\Edm\EntityContainer\FunctionImport\ReturnType;
15
use AlgoWeb\ODataMetadata\MetadataV3\Edm\Expressions\Dynamic\TEntitySetReferenceExpressionType;
0 ignored issues
show
Bug introduced by
The type AlgoWeb\ODataMetadata\Me...ReferenceExpressionType was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use AlgoWeb\ODataMetadata\MetadataV3\Edm\TOperandType;
0 ignored issues
show
Bug introduced by
The type AlgoWeb\ODataMetadata\MetadataV3\Edm\TOperandType was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use AlgoWeb\ODataMetadata\OdataVersions;
18
use AlgoWeb\ODataMetadata\Writer\AttributeContainer;
19
20
/**
21
 * 2.1.15 FunctionImport.
22
 *
23
 * FunctionImport element is used to import stored procedures or functions that are defined in the Store Schema Model
24
 * into Entity Data Model (EDM).
25
 *
26
 * The following is an example of the FunctionImport element.
27
 *
28
 *     <FunctionImport Name="annualCustomerSales" EntitySet="result_annualCustomerSalesSet" ReturnType="Collection(Self.result_annualCustomerSales)">
29
 *         <Parameter Name="fiscalyear" Mode="In" Type="String" />
30
 *     </FunctionImport>
31
 *
32
 * The following rules apply to the FunctionImport element:
33
 * - FunctionImport MUST have a Name attribute defined. Name attribute is of type SimpleIdentifier.
34
 * - FunctionImport can define a ReturnType as an attribute.
35
 * - In CSDL 3.0, the ReturnType can be defined as either an attribute or a child element, but not both.
36
 * - If defined in CSDL 1.1, CSDL 2.0, and CSDL 3.0, the type of ReturnType MUST be a scalar type, EntityType, or
37
 *   ComplexType that is in scope or a collection of one of these in-scope types. In CSDL 1.0, the ReturnType is
38
 *   collection of either scalar type or EntityType.
39
 * - Types that are in scope for a FunctionImport include all scalar types, EntityTypes, and ComplexTypes that are
40
 *   defined in the declaring SchemaNamespace or in schemas that are in scope of the declaring Schema.
41
 * - If the return type of FunctionImport is a collection of entities, the EntitySet attribute is defined.
42
 * - If the return type of FunctionImport is of ComplexType or scalar type, the EntitySet attribute cannot be defined.
43
 * - FunctionImport can contain any number of AnnotationAttribute attributes. The full names of the AnnotationAttribute
44
 *   attributes cannot collide.
45
 * - The FunctionImport element can contain a maximum of one Documentation element.
46
 * - FunctionImport can have zero or more Parameter elements.
47
 * - Parameter element names inside a FunctionImport cannot collide.
48
 * - FunctionImport can have an IsSideEffecting attribute defined. Possible values are "true" and "false". If the
49
 *   IsSideEffecting attribute is omitted, the value of the IsSideEffecting attribute defaults to "true".
50
 * - FunctionImport can have an IsBindable attribute defined. Possible values are "true" and "false". If the IsBindable
51
 *   attribute is omitted, the value of the IsBindable attribute is assumed to be "false".
52
 * - When IsBindable is set to "true", FunctionImport MUST have at least one Parameter element defined.
53
 * - FunctionImport can have an IsComposable attribute defined. Possible values are "true" and "false". If the
54
 *   IsComposable attribute is omitted, the value of the IsComposable attribute is assumed to be "false".
55
 * - FunctionImport cannot have IsComposable set to "true" if IsSideEffecting is set to "true".
56
 * - In CSDL 2.0 and CSDL 3.0, FunctionImport can contain any number of AnnotationElement elements.
57
 * - In CSDL 3.0, FunctionImport can have an EntitySetPath attribute defined. EntitySetPath defines the EntitySet
58
 *   that contains the entities that are returned by the FunctionImport when that EntitySet is dependent on one of the
59
 *   FunctionImport parameters. For example, the entities returned from a FunctionImport can be dependent on the entity
60
 *   set that is passed to the FunctionImport as a parameter. In this case, a static EntitySet is not sufficient, and an
61
 *   EntitySetPath is used. EntitySetPath is composed of segments that are separated by a forward slash. The first
62
 *   segment refers to a FunctionImport parameter. Each remaining segment represents either navigation, in which case
63
 *   the segment is a SimpleIdentifier, or a type cast, in which case the segment is a QualifiedName.
64
 * - In CSDL 3.0, FunctionImport can contain any number of ValueAnnotation elements.
65
 * - Child elements of FunctionImport are to appear in this sequence:
66
 *   Documentation (if present), ReturnType, Parameter, AnnotationElement.
67
 *
68
 * @see https://www.odata.org/documentation/odata-version-3-0/common-schema-definition-language-csdl/#csdl12.4
69
 */
70
class FunctionImport extends EdmBase
71
{
72
    /*
73
     * In CSDL 3.0, FunctionImport can contain any number of ValueAnnotation elements.
74
     */
75
    use HasValueAnnotation,
76
        /*
77
         * The FunctionImport element can contain a maximum of one Documentation element.
78
         */
79
        HasDocumentation,
80
        HasEntitySetReferenceExpression;
81
    /**
82
     * @var string $name FunctionImport MUST have a Name attribute defined. Name attribute is of type SimpleIdentifier.
83
     */
84
    private $name;
85
86
    /**
87
     * @var ReturnType|null $returnType FunctionImport can define a ReturnType as an attribute.
88
     *                      In CSDL 3.0, the ReturnType can be defined as either an attribute or a child element, but not both.
89
     *
90
     * If defined in CSDL 1.1, CSDL 2.0, and CSDL 3.0, the type of ReturnType MUST be a scalar type, EntityType,
91
     * or ComplexType that is in scope or a collection of one of these in-scope types. In CSDL 1.0, the ReturnType
92
     * is collection of either scalar type or EntityType.
93
     */
94
    private $returnType = null;
95
96
    /**
97
     * @var TEntitySetReferenceExpressionType|null $entitySet If the return type of FunctionImport is a collection of entities, the EntitySet
98
     *                                             attribute is defined.
99
     *
100
     * If the return type of FunctionImport is of ComplexType or scalar type, the EntitySet attribute cannot be defined.
101
     */
102
    private $entitySet = null;
0 ignored issues
show
introduced by
The private property $entitySet is not used, and could be removed.
Loading history...
103
    /**
104
     * @var string In CSDL 3.0, FunctionImport can have an EntitySetPath attribute defined. EntitySetPath defines the
105
     *             EntitySet that contains the entities that are returned by the FunctionImport when that EntitySet is dependent
106
     *             on one of the FunctionImport parameters. For example, the entities returned from a FunctionImport can be
107
     *             dependent on the entity set that is passed to the FunctionImport as a parameter. In this case, a static EntitySet
108
     *             is not sufficient, and an EntitySetPath is used. EntitySetPath is composed of segments that are separated by a
109
     *             forward slash. The first segment refers to a FunctionImport parameter. Each remaining segment represents either
110
     *             navigation, in which case the segment is a SimpleIdentifier, or a type cast, in which case the segment is a
111
     *             QualifiedName.
112
     */
113
    private $entitySetPath = null;
114
115
    /**
116
     * @var bool $isComposable FunctionImport can have an IsComposable attribute defined. Possible values are "true"
117
     *           and "false". If the IsComposable attribute is omitted, the value of the IsComposable attribute is assumed to
118
     *           be "false".
119
     *
120
     * FunctionImport cannot have IsComposable set to "true" if IsSideEffecting is set to "true".
121
     */
122
    private $isComposable = false;
123
124
    /**
125
     * @var bool $isSideEffecting FunctionImport can have an IsSideEffecting attribute defined. Possible values are
126
     *           "true" and "false". If the IsSideEffecting attribute is omitted, the value of the IsSideEffecting attribute
127
     *           defaults to "true".
128
     */
129
    private $isSideEffecting = true;
130
131
    /**
132
     * @var bool $isBindable FunctionImport can have an IsBindable attribute defined. Possible values are "true" and
133
     *           "false". If the IsBindable attribute is omitted, the value of the IsBindable attribute is assumed to be "false".
134
     *
135
     * When IsBindable is set to "true", FunctionImport MUST have at least one Parameter element defined.
136
     */
137
    private $isBindable = false;
138
139
    /**
140
     * @var AccessorType? $methodAccess
0 ignored issues
show
Documentation Bug introduced by
The doc comment AccessorType? at position 0 could not be parsed: Unknown type name 'AccessorType?' at position 0 in AccessorType?.
Loading history...
141
     */
142
    private $methodAccess = null;
143
144
145
    /**
146
     * @var ParameterType[] $parameter FunctionImport can have zero or more Parameter elements.
147
     *                      Parameter element names inside a FunctionImport cannot collide.
148
     */
149
    private $parameter = [];
150
151
    /**
152
     * Gets as name.
153
     *
154
     * @return string
155
     */
156
    public function getName():string
157
    {
158
        return $this->name;
159
    }
160
161
    /**
162
     * Sets a new name.
163
     *
164
     * @param  string $name
165
     * @return self
166
     */
167
    public function setName(string $name): self
168
    {
169
        $this->name = $name;
170
        return $this;
171
    }
172
173
    /**
174
     * Gets as returnType.
175
     *
176
     * @return ReturnType|null
177
     */
178
    public function getReturnType(): ?ReturnType
179
    {
180
        return $this->returnType;
181
    }
182
183
    /**
184
     * Sets a new returnType.
185
     *
186
     * @param  ReturnType|null $returnType
187
     * @return self
188
     */
189
    public function setReturnType(?ReturnType $returnType): self
190
    {
191
        $this->returnType = $returnType;
192
        return $this;
193
    }
194
195
    /**
196
     * Gets as entitySet.
197
     *
198
     * @return string|null
199
     */
200
    public function getEntitySetPath(): ?string
201
    {
202
        return $this->entitySetPath;
203
    }
204
205
    /**
206
     * Sets a new entitySet.
207
     *
208
     * @param  string|null $entitySet
209
     * @return self
210
     */
211
    public function setEntitySetPath(?string $entitySet):self
212
    {
213
        $this->entitySetPath = $entitySet;
214
        return $this;
215
    }
216
    /**
217
     * Gets as isComposable.
218
     *
219
     * @return bool
220
     */
221
    public function getIsComposable(): bool
222
    {
223
        return $this->isComposable;
224
    }
225
226
    /**
227
     * Sets a new isComposable.
228
     *
229
     * @param  bool $isComposable
230
     * @return self
231
     */
232
    public function setIsComposable(bool $isComposable): self
233
    {
234
        $this->isComposable = $isComposable;
235
        return $this;
236
    }
237
238
    /**
239
     * Gets as isSideEffecting.
240
     *
241
     * @return bool
242
     */
243
    public function getIsSideEffecting(): bool
244
    {
245
        return $this->isSideEffecting;
246
    }
247
248
    /**
249
     * Sets a new isSideEffecting.
250
     *
251
     * @param  bool $isSideEffecting
252
     * @return self
253
     */
254
    public function setIsSideEffecting(bool $isSideEffecting): self
255
    {
256
        $this->isSideEffecting = $isSideEffecting;
257
        return $this;
258
    }
259
260
    /**
261
     * Gets as isBindable.
262
     *
263
     * @return bool
264
     */
265
    public function getIsBindable(): bool
266
    {
267
        return $this->isBindable;
268
    }
269
270
    /**
271
     * Sets a new isBindable.
272
     *
273
     * @param  bool $isBindable
274
     * @return self
275
     */
276
    public function setIsBindable(bool $isBindable): self
277
    {
278
        $this->isBindable = $isBindable;
279
        return $this;
280
    }
281
282
    /**
283
     * Gets as methodAccess.
284
     *
285
     * @return AccessorType|null
286
     */
287
    public function getMethodAccess(): ?AccessorType
288
    {
289
        return $this->methodAccess;
290
    }
291
292
    /**
293
     * Sets a new methodAccess.
294
     *
295
     * @param  AccessorType|null $methodAccess
296
     * @return self
297
     */
298
    public function setMethodAccess(?AccessorType $methodAccess): self
299
    {
300
        $this->methodAccess = $methodAccess;
301
        return $this;
302
    }
303
304
    /**
305
     * Adds as parameter.
306
     *
307
     * @param  ParameterType $parameter
308
     * @return self
309
     */
310
    public function addToParameter(ParameterType $parameter): self
311
    {
312
        $this->parameter[] = $parameter;
313
        return $this;
314
    }
315
316
    /**
317
     * isset parameter.
318
     *
319
     * @param  int  $index
320
     * @return bool
321
     */
322
    public function issetParameter(int $index): bool
323
    {
324
        return isset($this->parameter[$index]);
325
    }
326
327
    /**
328
     * unset parameter.
329
     *
330
     * @param  int  $index
331
     * @return void
332
     */
333
    public function unsetParameter(int $index):void
334
    {
335
        unset($this->parameter[$index]);
336
    }
337
338
    /**
339
     * Gets as parameter.
340
     *
341
     * @return ParameterType[]
342
     */
343
    public function getParameter():array
344
    {
345
        return $this->parameter;
346
    }
347
348
    /**
349
     * Sets a new parameter.
350
     *
351
     * @param  ParameterType[] $parameter
352
     * @return self
353
     */
354
    public function setParameter(array $parameter): self
355
    {
356
        $this->parameter = $parameter;
357
        return $this;
358
    }
359
360
    /**
361
     * @return string
362
     */
363
    public function getDomName(): string
364
    {
365
        return 'FunctionImport';
366
    }
367
368
    /**
369
     * @return array|AttributeContainer[]
370
     */
371
    public function getAttributes(): array
372
    {
373
        return [
374
            new AttributeContainer('Name', $this->getName()),
375
            new AttributeContainer('EntitySet', $this->getEntitySetReference(), true),
0 ignored issues
show
Bug introduced by
$this->getEntitySetReference() of type AlgoWeb\ODataMetadata\Me...ferenceExpressionType[] is incompatible with the type string expected by parameter $value of AlgoWeb\ODataMetadata\Wr...ontainer::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

375
            new AttributeContainer('EntitySet', /** @scrutinizer ignore-type */ $this->getEntitySetReference(), true),
Loading history...
376
            new AttributeContainer('EntitySetPath', $this->getEntitySetPath(), true),
377
            new AttributeContainer('ReturnType', $this->getReturnType()->getType(), true, OdataVersions::TWO(), [OdataVersions::THREE()]),
378
        ];
379
    }
380
381
    /**
382
     * @return array|DomBase[]
383
     */
384
    public function getChildElements(): array
385
    {
386
        return array_merge(
387
            [
388
                $this->getDocumentation(),
389
                $this->getReturnType()
390
            ],
391
            $this->getParameter(),
392
            $this->getValueAnnotation()
393
        );
394
    }
395
}
396