1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace POData\ObjectModel; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class ODataLink represents an OData Navigation Link. |
9
|
|
|
*/ |
10
|
|
|
class ODataLink |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Name of the link. This becomes last segment of rel attribute value. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
private $name; |
18
|
|
|
/** |
19
|
|
|
* Title of the link. This become value of title attribute. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
public $title; |
24
|
|
|
/** |
25
|
|
|
* Type of link. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
public $type; |
30
|
|
|
/** |
31
|
|
|
* Url to the navigation property. This become value of href attribute. |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
public $url; |
36
|
|
|
/** |
37
|
|
|
* Checks is Expand result contains single entity or collection of |
38
|
|
|
* entities i.e. feed. |
39
|
|
|
* |
40
|
|
|
* @var bool |
41
|
|
|
*/ |
42
|
|
|
public $isCollection; |
43
|
|
|
/** |
44
|
|
|
* The expanded result. This becomes the inline content of the link. |
45
|
|
|
* |
46
|
|
|
* @var ODataEntry|ODataFeed |
47
|
|
|
*/ |
48
|
|
|
public $expandedResult; |
49
|
|
|
/** |
50
|
|
|
* True if Link is Expanded, False if not. |
51
|
|
|
* |
52
|
|
|
* @var bool |
53
|
|
|
*/ |
54
|
|
|
public $isExpanded; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* ODataLink constructor. |
58
|
|
|
* @param string $name |
59
|
|
|
* @param string $title |
60
|
|
|
* @param string $type |
61
|
|
|
* @param string $url |
62
|
|
|
* @param bool $isCollection |
63
|
|
|
* @param ODataExpandedResult|null $expandedResult |
64
|
|
|
*/ |
65
|
|
|
public function __construct(string $name = null, string $title = null, string $type = null, string $url = null, bool $isCollection = null, ODataExpandedResult $expandedResult = null) |
66
|
|
|
{ |
67
|
|
|
$this->name = $name; |
68
|
|
|
$this->title = $title; |
69
|
|
|
$this->type = $type; |
70
|
|
|
$this->url = $url; |
71
|
|
|
$this->isCollection = $isCollection; |
72
|
|
|
$this->expandedResult = $expandedResult; |
|
|
|
|
73
|
|
|
} |
74
|
|
|
/** |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
public function getName(): ?string |
78
|
|
|
{ |
79
|
|
|
return $this->name; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param string $name |
84
|
|
|
* @return ODataLink |
85
|
|
|
*/ |
86
|
|
|
public function setName(string $name): ODataLink |
87
|
|
|
{ |
88
|
|
|
$this->name = $name; |
89
|
|
|
return $this; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function getTitle(): string |
96
|
|
|
{ |
97
|
|
|
return $this->title; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param string $title |
102
|
|
|
* @return ODataLink |
103
|
|
|
*/ |
104
|
|
|
public function setTitle(string $title): ODataLink |
105
|
|
|
{ |
106
|
|
|
$this->title = $title; |
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
|
|
public function getType(): string |
114
|
|
|
{ |
115
|
|
|
return $this->type; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param string $type |
120
|
|
|
* @return ODataLink |
121
|
|
|
*/ |
122
|
|
|
public function setType(string $type): ODataLink |
123
|
|
|
{ |
124
|
|
|
$this->type = $type; |
125
|
|
|
return $this; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return string |
130
|
|
|
*/ |
131
|
|
|
public function getUrl(): string |
132
|
|
|
{ |
133
|
|
|
return $this->url; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @param string $url |
138
|
|
|
* @return ODataLink |
139
|
|
|
*/ |
140
|
|
|
public function setUrl(string $url): ODataLink |
141
|
|
|
{ |
142
|
|
|
$this->url = $url; |
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return bool |
148
|
|
|
*/ |
149
|
|
|
public function isCollection(): bool |
150
|
|
|
{ |
151
|
|
|
return $this->isCollection; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param bool $isCollection |
156
|
|
|
* @return ODataLink |
157
|
|
|
*/ |
158
|
|
|
public function setIsCollection(bool $isCollection): ODataLink |
159
|
|
|
{ |
160
|
|
|
$this->isCollection = $isCollection; |
161
|
|
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @return ODataEntry|ODataFeed |
166
|
|
|
*/ |
167
|
|
|
public function getExpandedResult() |
168
|
|
|
{ |
169
|
|
|
return $this->expandedResult; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param ODataEntry|ODataFeed $expandedResult |
174
|
|
|
* @return ODataLink |
175
|
|
|
*/ |
176
|
|
|
public function setExpandedResult($expandedResult) |
177
|
|
|
{ |
178
|
|
|
$this->expandedResult = $expandedResult; |
179
|
|
|
return $this; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @return bool |
184
|
|
|
*/ |
185
|
|
|
public function isExpanded(): bool |
186
|
|
|
{ |
187
|
|
|
return $this->isExpanded; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @param bool $isExpanded |
192
|
|
|
* @return ODataLink |
193
|
|
|
*/ |
194
|
|
|
public function setIsExpanded(bool $isExpanded): ODataLink |
195
|
|
|
{ |
196
|
|
|
$this->isExpanded = $isExpanded; |
197
|
|
|
return $this; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @return null|ODataExpandedResult |
202
|
|
|
*/ |
203
|
|
|
public function getExpandResult(): ?ODataExpandedResult |
204
|
|
|
{ |
205
|
|
|
if (!$this->isExpanded) { |
206
|
|
|
return null; |
207
|
|
|
} |
208
|
|
|
if ($this->isCollection) { |
209
|
|
|
assert($this->expandedResult instanceof ODataFeed); |
210
|
|
|
return new ODataExpandedResult(null, $this->expandedResult); |
211
|
|
|
} |
212
|
|
|
assert($this->expandedResult instanceof ODataEntry); |
213
|
|
|
return new ODataExpandedResult($this->expandedResult); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @param ODataExpandedResult $eResult |
218
|
|
|
*/ |
219
|
|
|
public function setExpandResult(ODataExpandedResult $eResult) |
220
|
|
|
{ |
221
|
|
|
if (null !== $eResult->getFeed()) { |
222
|
|
|
$this->isExpanded = true; |
223
|
|
|
$this->isCollection = true; |
224
|
|
|
$this->expandedResult = $eResult->getFeed(); |
225
|
|
|
} |
226
|
|
|
if (null !== $eResult->getEntry()) { |
227
|
|
|
$this->isExpanded = true; |
228
|
|
|
$this->isCollection = false; |
229
|
|
|
$this->expandedResult = $eResult->getEntry(); |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.