VisitExpressions::visitExpressions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
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\ModelVisitorConcerns;
6
7
use AlgoWeb\ODataMetadata\EdmModelVisitor;
8
use AlgoWeb\ODataMetadata\Enums\ExpressionKind;
9
use AlgoWeb\ODataMetadata\Exception\InvalidOperationException;
10
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IApplyExpression;
11
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IAssertTypeExpression;
12
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IBinaryConstantExpression;
13
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IBooleanConstantExpression;
14
use AlgoWeb\ODataMetadata\Interfaces\Expressions\ICollectionExpression;
15
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IDateTimeConstantExpression;
16
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IDateTimeOffsetConstantExpression;
17
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IDecimalConstantExpression;
18
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IEntitySetReferenceExpression;
19
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IEnumMemberReferenceExpression;
20
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IExpression;
21
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IFloatingConstantExpression;
22
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IFunctionReferenceExpression;
23
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IGuidConstantExpression;
24
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IIfExpression;
25
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IIntegerConstantExpression;
26
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IIsTypeExpression;
27
use AlgoWeb\ODataMetadata\Interfaces\Expressions\ILabeledExpression;
28
use AlgoWeb\ODataMetadata\Interfaces\Expressions\ILabeledExpressionReferenceExpression;
29
use AlgoWeb\ODataMetadata\Interfaces\Expressions\INullExpression;
30
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IParameterReferenceExpression;
31
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IPathExpression;
32
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IPropertyReferenceExpression;
33
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IRecordExpression;
34
use AlgoWeb\ODataMetadata\Interfaces\Expressions\IStringConstantExpression;
35
use AlgoWeb\ODataMetadata\Interfaces\Expressions\ITimeConstantExpression;
36
use AlgoWeb\ODataMetadata\Interfaces\Expressions\RecordExpression\IPropertyConstructor;
37
use AlgoWeb\ODataMetadata\StringConst;
38
39
/**
40
 * Trait VisitExpressions.
41
 * @package AlgoWeb\ODataMetadata\ModelVisitorConcerns
42
 * @mixin EdmModelVisitor
43
 */
44
trait VisitExpressions
45
{
46
    public function visitExpressions(array $expressions): void
47
    {
48
        /** @var EdmModelVisitor $this */
49
        self::visitCollection($expressions, [$this, 'visitExpression']);
50
    }
51
52
    public function visitExpression(IExpression $expression): void
53
    {
54
        /** @var EdmModelVisitor $this */
55
        switch ($expression->getExpressionKind()) {
56
            case ExpressionKind::AssertType():
57
                assert($expression instanceof  IAssertTypeExpression);
58
                $this->processAssertTypeExpression($expression);
59
                break;
60
            case ExpressionKind::BinaryConstant():
61
                assert($expression instanceof  IBinaryConstantExpression);
62
                $this->processBinaryConstantExpression($expression);
63
                break;
64
            case ExpressionKind::BooleanConstant():
65
                assert($expression instanceof  IBooleanConstantExpression);
66
                $this->processBooleanConstantExpression($expression);
67
                break;
68
            case ExpressionKind::Collection():
69
                assert($expression instanceof  ICollectionExpression);
70
                $this->processCollectionExpression($expression);
71
                break;
72
            case ExpressionKind::DateTimeConstant():
73
                assert($expression instanceof  IDateTimeConstantExpression);
74
                $this->processDateTimeConstantExpression($expression);
75
                break;
76
            case ExpressionKind::DateTimeOffsetConstant():
77
                assert($expression instanceof  IDateTimeOffsetConstantExpression);
78
                $this->processDateTimeOffsetConstantExpression($expression);
79
                break;
80
            case ExpressionKind::DecimalConstant():
81
                assert($expression instanceof  IDecimalConstantExpression);
82
                $this->processDecimalConstantExpression($expression);
83
                break;
84
            case ExpressionKind::EntitySetReference():
85
                assert($expression instanceof  IEntitySetReferenceExpression);
86
                $this->processEntitySetReferenceExpression($expression);
87
                break;
88
            case ExpressionKind::EnumMemberReference():
89
                assert($expression instanceof  IEnumMemberReferenceExpression);
90
                $this->processEnumMemberReferenceExpression($expression);
91
                break;
92
            case ExpressionKind::FloatingConstant():
93
                assert($expression instanceof  IFloatingConstantExpression);
94
                $this->processFloatingConstantExpression($expression);
95
                break;
96
            case ExpressionKind::FunctionApplication():
97
                assert($expression instanceof  IApplyExpression);
98
                $this->processFunctionApplicationExpression($expression);
99
                break;
100
            case ExpressionKind::FunctionReference():
101
                assert($expression instanceof  IFunctionReferenceExpression);
102
                $this->processFunctionReferenceExpression($expression);
103
                break;
104
            case ExpressionKind::GuidConstant():
105
                assert($expression instanceof  IGuidConstantExpression);
106
                $this->processGuidConstantExpression($expression);
107
                break;
108
            case ExpressionKind::If():
109
                assert($expression instanceof  IIfExpression);
110
                $this->processIfExpression($expression);
111
                break;
112
            case ExpressionKind::IntegerConstant():
113
                assert($expression instanceof  IIntegerConstantExpression);
114
                $this->processIntegerConstantExpression($expression);
115
                break;
116
            case ExpressionKind::IsType():
117
                assert($expression instanceof  IIsTypeExpression);
118
                $this->processIsTypeExpression($expression);
119
                break;
120
            case ExpressionKind::ParameterReference():
121
                assert($expression instanceof  IParameterReferenceExpression);
122
                $this->processParameterReferenceExpression($expression);
123
                break;
124
            case ExpressionKind::LabeledExpressionReference():
125
                assert($expression instanceof  ILabeledExpressionReferenceExpression);
126
                $this->processLabeledExpressionReferenceExpression($expression);
127
                break;
128
            case ExpressionKind::Labeled():
129
                assert($expression instanceof  ILabeledExpression);
130
                $this->processLabeledExpression($expression);
131
                break;
132
            case ExpressionKind::Null():
133
                assert($expression instanceof  INullExpression);
134
                $this->processNullConstantExpression($expression);
135
                break;
136
            case ExpressionKind::Path():
137
                assert($expression instanceof  IPathExpression);
138
                $this->processPathExpression($expression);
139
                break;
140
            case ExpressionKind::PropertyReference():
141
                assert($expression instanceof  IPropertyReferenceExpression);
142
                $this->processPropertyReferenceExpression($expression);
143
                break;
144
            case ExpressionKind::Record():
145
                assert($expression instanceof  IRecordExpression);
146
                $this->processRecordExpression($expression);
147
                break;
148
            case ExpressionKind::StringConstant():
149
                assert($expression instanceof  IStringConstantExpression);
150
                $this->processStringConstantExpression($expression);
151
                break;
152
            case ExpressionKind::TimeConstant():
153
                assert($expression instanceof  ITimeConstantExpression);
154
                $this->processTimeConstantExpression($expression);
155
                break;
156
            case ExpressionKind::ValueTermReference():
157
                assert($expression instanceof  IPropertyReferenceExpression);
158
                $this->processPropertyReferenceExpression($expression);
159
                break;
160
            case ExpressionKind::None():
161
                $this->processExpression($expression);
162
                break;
163
            default:
164
                throw new InvalidOperationException(
165
                    StringConst::UnknownEnumVal_TermKind($expression->getExpressionKind()->getKey())
166
                );
167
        }
168
    }
169
    /**
170
     * @param IPropertyConstructor[] $constructor
171
     */
172
    public function visitPropertyConstructors(array $constructor): void
173
    {
174
        /** @var EdmModelVisitor $this */
175
        self::visitCollection($constructor, [$this, 'processPropertyConstructor']);
176
    }
177
}
178