|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
namespace AlgoWeb\ODataMetadata\Edm\Validation\Internal\InterfaceValidator; |
|
7
|
|
|
|
|
8
|
|
|
use AlgoWeb\ODataMetadata\Edm\Validation\Internal\InterfaceValidator; |
|
9
|
|
|
use AlgoWeb\ODataMetadata\Enums\ExpressionKind; |
|
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\IValueTermReferenceExpression; |
|
37
|
|
|
|
|
38
|
|
|
class VisitorOfIExpression extends VisitorOfT |
|
39
|
|
|
{ |
|
40
|
|
|
protected $lookup = []; |
|
41
|
|
|
|
|
42
|
|
|
public function __construct() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->lookup[ExpressionKind::IntegerConstant()->getValue()] = IIntegerConstantExpression::class; |
|
45
|
|
|
$this->lookup[ExpressionKind::StringConstant()->getValue()] = IStringConstantExpression::class; |
|
46
|
|
|
$this->lookup[ExpressionKind::BinaryConstant()->getValue()] = IBinaryConstantExpression::class; |
|
47
|
|
|
$this->lookup[ExpressionKind::BooleanConstant()->getValue()] = IBooleanConstantExpression::class; |
|
48
|
|
|
$this->lookup[ExpressionKind::DateTimeConstant()->getValue()] = IDateTimeConstantExpression::class; |
|
49
|
|
|
$this->lookup[ExpressionKind::DateTimeOffsetConstant()->getValue()] = IDateTimeOffsetConstantExpression::class; |
|
50
|
|
|
$this->lookup[ExpressionKind::TimeConstant()->getValue()] = ITimeConstantExpression::class; |
|
51
|
|
|
$this->lookup[ExpressionKind::DecimalConstant()->getValue()] = IDecimalConstantExpression::class; |
|
52
|
|
|
$this->lookup[ExpressionKind::FloatingConstant()->getValue()] = IFloatingConstantExpression::class; |
|
53
|
|
|
$this->lookup[ExpressionKind::GuidConstant()->getValue()] = IGuidConstantExpression::class; |
|
54
|
|
|
$this->lookup[ExpressionKind::Null()->getValue()] = INullExpression::class; |
|
55
|
|
|
$this->lookup[ExpressionKind::Record()->getValue()] = IRecordExpression::class; |
|
56
|
|
|
$this->lookup[ExpressionKind::Collection()->getValue()] = ICollectionExpression::class; |
|
57
|
|
|
$this->lookup[ExpressionKind::Path()->getValue()] = IPathExpression::class; |
|
58
|
|
|
$this->lookup[ExpressionKind::ParameterReference()->getValue()] = IParameterReferenceExpression::class; |
|
59
|
|
|
$this->lookup[ExpressionKind::FunctionReference()->getValue()] = IFunctionReferenceExpression::class; |
|
60
|
|
|
$this->lookup[ExpressionKind::PropertyReference()->getValue()] = IPropertyReferenceExpression::class; |
|
61
|
|
|
$this->lookup[ExpressionKind::ValueTermReference()->getValue()] = IValueTermReferenceExpression::class; |
|
62
|
|
|
$this->lookup[ExpressionKind::EntitySetReference()->getValue()] = IEntitySetReferenceExpression::class; |
|
63
|
|
|
$this->lookup[ExpressionKind::EnumMemberReference()->getValue()] = IEnumMemberReferenceExpression::class; |
|
64
|
|
|
$this->lookup[ExpressionKind::If()->getValue()] = IIfExpression::class; |
|
65
|
|
|
$this->lookup[ExpressionKind::AssertType()->getValue()] = IAssertTypeExpression::class; |
|
66
|
|
|
$this->lookup[ExpressionKind::IsType()->getValue()] = IIsTypeExpression::class; |
|
67
|
|
|
$this->lookup[ExpressionKind::FunctionApplication()->getValue()] = IApplyExpression::class; |
|
68
|
|
|
$this->lookup[ExpressionKind::Labeled()->getValue()] = ILabeledExpression::class; |
|
69
|
|
|
$this->lookup[ExpressionKind::LabeledExpressionReference()->getValue()] = ILabeledExpressionReferenceExpression::class; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
protected function VisitT($expression, array &$followup, array &$references): ?iterable |
|
73
|
|
|
{ |
|
74
|
|
|
assert($expression instanceof IExpression); |
|
75
|
|
|
// Trying to reduce amount of noise in errors - if this expression is bad, then most likely it will have an |
|
76
|
|
|
// unacceptable kind, no need to report it. |
|
77
|
|
|
if (InterfaceValidator::IsCheckableBad($expression)) { |
|
78
|
|
|
return null; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
$expressionKindError = null; |
|
82
|
|
|
$kind = $expression->getExpressionKind(); |
|
83
|
|
|
|
|
84
|
|
|
if (!array_key_exists($kind->getValue(), $this->lookup)) { |
|
85
|
|
|
$expressionKindError = InterfaceValidator::CreateInterfaceKindValueUnexpectedError( |
|
86
|
|
|
$expression, |
|
87
|
|
|
$expression->getExpressionKind()->getKey(), |
|
88
|
|
|
'ExpressionKind' |
|
89
|
|
|
); |
|
90
|
|
|
} else { |
|
91
|
|
|
$interface = $this->lookup[$kind->getValue()]; |
|
92
|
|
|
$expressionKindError = InterfaceValidator::CheckForInterfaceKindValueMismatchError( |
|
93
|
|
|
$expression, |
|
94
|
|
|
$kind, |
|
95
|
|
|
'ExpressionKind', |
|
96
|
|
|
$interface |
|
97
|
|
|
); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return [$expressionKindError]; |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function forType(): string |
|
104
|
|
|
{ |
|
105
|
|
|
return IExpression::class; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|