Completed
Pull Request — master (#269)
by Christopher
04:04
created

ODataLink   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 209
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 52
c 1
b 0
f 1
dl 0
loc 209
rs 10
wmc 20

15 Methods

Rating   Name   Duplication   Size   Complexity  
A isExpanded() 0 3 1
A setName() 0 4 1
A isCollection() 0 3 1
A getTitle() 0 3 1
A setIsCollection() 0 4 1
A getName() 0 3 1
A getUrl() 0 3 1
A getExpandResult() 0 11 3
A setTitle() 0 4 1
A getType() 0 3 1
A setIsExpanded() 0 4 1
A setUrl() 0 4 1
A setType() 0 4 1
A setExpandResult() 0 16 4
A __construct() 0 10 1
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
    private $title;
24
    /**
25
     * Type of link.
26
     *
27
     * @var string
28
     */
29
    private $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, bool $isExpanded = null)
66
    {
67
        $this
68
            ->setName($name)
69
            ->setTitle($title)
70
            ->setType($type)
71
            ->setUrl($url)
72
            ->setIsCollection($isCollection)
73
            ->setExpandResult($expandedResult)
74
            ->setIsExpanded($isExpanded);
75
    }
76
    /**
77
     * @return string
78
     */
79
    public function getName(): ?string
80
    {
81
        return $this->name;
82
    }
83
84
    /**
85
     * @param string $name
86
     * @return ODataLink
87
     */
88
    public function setName(?string $name): ODataLink
89
    {
90
        $this->name = $name;
91
        return $this;
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public function getTitle(): ?string
98
    {
99
        return $this->title;
100
    }
101
102
    /**
103
     * @param string $title
104
     * @return ODataLink
105
     */
106
    public function setTitle(?string $title): ODataLink
107
    {
108
        $this->title = $title;
109
        return $this;
110
    }
111
112
    /**
113
     * @return string|null
114
     */
115
    public function getType(): ?string
116
    {
117
        return $this->type;
118
    }
119
120
    /**
121
     * @param string $type
122
     * @return ODataLink
123
     */
124
    public function setType(?string $type): ODataLink
125
    {
126
        $this->type = $type;
127
        return $this;
128
    }
129
130
    /**
131
     * @return string
132
     */
133
    public function getUrl(): ?string
134
    {
135
        return $this->url;
136
    }
137
138
    /**
139
     * @param string $url
140
     * @return ODataLink
141
     */
142
    public function setUrl(?string $url): ODataLink
143
    {
144
        $this->url = $url;
145
        return $this;
146
    }
147
148
    /**
149
     * @return bool
150
     */
151
    public function isCollection(): ?bool
152
    {
153
        return $this->isCollection;
154
    }
155
156
    /**
157
     * @param bool $isCollection
158
     * @return ODataLink
159
     */
160
    public function setIsCollection(?bool $isCollection): ODataLink
161
    {
162
        $this->isCollection = $isCollection;
163
        return $this;
164
    }
165
166
    /**
167
     * @return bool
168
     */
169
    public function isExpanded(): ?bool
170
    {
171
        return $this->isExpanded;
172
    }
173
174
    /**
175
     * @param bool $isExpanded
176
     * @return ODataLink
177
     */
178
    public function setIsExpanded(?bool $isExpanded): ODataLink
179
    {
180
        $this->isExpanded = $isExpanded;
181
        return $this;
182
    }
183
184
    /**
185
     * @return null|ODataExpandedResult
186
     */
187
    public function getExpandResult(): ?ODataExpandedResult
188
    {
189
        if (!$this->isExpanded) {
190
            return null;
191
        }
192
        if ($this->isCollection) {
193
            assert($this->expandedResult instanceof ODataFeed);
194
            return new ODataExpandedResult( $this->expandedResult);
195
        }
196
        assert($this->expandedResult instanceof ODataEntry);
197
        return new ODataExpandedResult($this->expandedResult);
198
    }
199
200
    /**
201
     * @param ODataExpandedResult $eResult
202
     */
203
    public function setExpandResult(?ODataExpandedResult $eResult)
204
    {
205
        if(null === $eResult){
206
            return $this;
207
        }
208
        if (null !== $eResult->getFeed()) {
209
            $this->isExpanded     = true;
210
            $this->isCollection   = true;
211
            $this->expandedResult = $eResult->getFeed();
212
        }
213
        if (null !== $eResult->getEntry()) {
214
            $this->isExpanded     = true;
215
            $this->isCollection   = false;
216
            $this->expandedResult = $eResult->getEntry();
217
        }
218
        return $this;
219
    }
220
}
221