Completed
Push — master ( e40b6a...f5580e )
by Beñat
11s
created

Site::getClosedBetaDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Stack Exchange Api Client library.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
/*
14
 * This file is part of the Stack Exchange Api Client library.
15
 *
16
 * (c) Beñat Espiña <[email protected]>
17
 *
18
 * For the full copyright and license information, please view the LICENSE
19
 * file that was distributed with this source code.
20
 */
21
22
namespace BenatEspina\StackExchangeApiClient\Model;
23
24
/**
25
 * The site model class.
26
 *
27
 * @author Beñat Espiña <[email protected]>
28
 */
29
class Site implements Model
30
{
31
    const SITE_STATES = ['closed_beta', 'linked_meta', 'normal', 'open_beta'];
32
    const SITE_TYPES = ['main_site', 'meta_site'];
33
34
    protected $aliases;
35
    protected $apiSiteParameter;
36
    protected $audience;
37
    protected $launchDate;
38
    protected $markdownExtensions;
39
    protected $name;
40
    protected $styling;
41
    protected $twitterAccount;
42
    protected $closedBetaDate;
43
    protected $openBetaDate;
44
    protected $relatedSites;
45
    protected $siteState;
46
    protected $siteType;
47
    protected $siteUrl;
48
    protected $faviconUrl;
49
    protected $highResIconUrl;
50
    protected $iconUrl;
51
    protected $logoUrl;
52
53
    public static function fromProperties(
54
        array $aliases,
55
        $apiSiteParameter,
56
        $audience,
57
        \DateTimeInterface $launchDate,
58
        array $markdownExtensions,
59
        $name,
60
        $styling,
61
        $twitterAccount,
62
        $closedBetaDate,
63
        $openBetaDate,
64
        array $relatedSites,
65
        $siteState,
66
        $siteType,
67
        $siteUrl,
68
        $faviconUrl,
69
        $highResIconUrl,
70
        $iconUrl,
71
        $logoUrl
72
    ) {
73
        $instance = new self();
74
        $instance
75
            ->setAliases($aliases)
76
            ->setApiSiteParameter($apiSiteParameter)
77
            ->setAudience($audience)
78
            ->setLaunchDate($launchDate)
79
            ->setMarkdownExtensions($markdownExtensions)
80
            ->setName($name)
81
            ->setStyling($styling)
82
            ->setTwitterAccount($twitterAccount)
83
            ->setClosedBetaDate($closedBetaDate)
84
            ->setOpenBetaDate($openBetaDate)
85
            ->setRelatedSites($relatedSites)
86
            ->setSiteState($siteState)
87
            ->setSiteType($siteType)
88
            ->setSiteUrl($siteUrl)
89
            ->setFaviconUrl($faviconUrl)
90
            ->setHighResIconUrl($highResIconUrl)
91
            ->setIconUrl($iconUrl)
92
            ->setLogoUrl($logoUrl);
93
94
        return $instance;
95
    }
96
97
    public static function fromJson(array $data)
98
    {
99
        $aliases = [];
100
        if (array_key_exists('aliases', $data) && is_array($data['aliases'])) {
101
            foreach ($data['aliases'] as $alias) {
102
                $aliases[] = $alias;
103
            }
104
        }
105
        $markdownExtensions = [];
106
        if (array_key_exists('markdown_extensions', $data) && is_array($data['markdown_extensions'])) {
107
            foreach ($data['markdown_extensions'] as $markdownExtension) {
108
                $markdownExtensions[] = $markdownExtension;
109
            }
110
        }
111
        $relatedSites = [];
112 View Code Duplication
        if (array_key_exists('related_sites', $data) && is_array($data['related_sites'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
113
            foreach ($data['related_sites'] as $relatedSite) {
114
                $relatedSites[] = RelatedSite::fromJson($relatedSite);
115
            }
116
        }
117
118
        $instance = new self();
119
        $instance
120
            ->setAliases($aliases)
121
            ->setApiSiteParameter(array_key_exists('api_site_parameter', $data) ? $data['api_site_parameter'] : null)
122
            ->setAudience(array_key_exists('audience', $data) ? $data['audience'] : null)
123
            ->setLaunchDate(
124
                array_key_exists('launch_date', $data)
125
                    ? new \DateTimeImmutable('@' . $data['launch_date'])
126
                    : null
127
            )
128
            ->setMarkdownExtensions($markdownExtensions)
129
            ->setName(array_key_exists('name', $data) ? $data['name'] : null)
130
            ->setStyling(array_key_exists('styling', $data) ? $data['styling'] : null)
131
            ->setTwitterAccount(array_key_exists('twitter_account', $data) ? $data['twitter_account'] : null)
132
            ->setClosedBetaDate(
133
                array_key_exists('closed_beta_date', $data)
134
                    ? new \DateTimeImmutable('@' . $data['closed_beta_date'])
135
                    : null
136
            )
137
            ->setOpenBetaDate(
138
                array_key_exists('open_beta_date', $data)
139
                    ? new \DateTimeImmutable('@' . $data['open_beta_date'])
140
                    : null
141
            )
142
            ->setRelatedSites($relatedSites)
143
            ->setSiteState(array_key_exists('site_state', $data) ? $data['site_state'] : null)
144
            ->setSiteType(array_key_exists('site_type', $data) ? $data['site_type'] : null)
145
            ->setSiteUrl(array_key_exists('site_url', $data) ? $data['site_url'] : null)
146
            ->setFaviconUrl(array_key_exists('favicon_url', $data) ? $data['favicon_url'] : null)
147
            ->setHighResIconUrl(array_key_exists('high_res_icon_url', $data) ? $data['high_res_icon_url'] : null)
148
            ->setIconUrl(array_key_exists('icon_url', $data) ? $data['icon_url'] : null)
149
            ->setLogoUrl(array_key_exists('logo_url', $data) ? $data['logo_url'] : null);
150
151
        return $instance;
152
    }
153
154
    public function setAliases(array $aliases = [])
155
    {
156
        $this->aliases = $aliases;
157
158
        return $this;
159
    }
160
161
    public function getAliases()
162
    {
163
        return $this->aliases;
164
    }
165
166
    public function getApiSiteParameter()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
167
    {
168
        return $this->apiSiteParameter;
169
    }
170
171
    public function setApiSiteParameter($apiSiteParameter)
172
    {
173
        $this->apiSiteParameter = $apiSiteParameter;
174
175
        return $this;
176
    }
177
178
    public function getAudience()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
179
    {
180
        return $this->audience;
181
    }
182
183
    public function setAudience($audience)
184
    {
185
        $this->audience = $audience;
186
187
        return $this;
188
    }
189
190
    public function getLaunchDate()
191
    {
192
        return $this->launchDate;
193
    }
194
195
    public function setLaunchDate(\DateTimeInterface $launchDate = null)
196
    {
197
        $this->launchDate = $launchDate;
198
199
        return $this;
200
    }
201
202
    public function getMarkdownExtensions()
203
    {
204
        return $this->markdownExtensions;
205
    }
206
207
    public function setMarkdownExtensions(array $markdownExtensions = [])
208
    {
209
        $this->markdownExtensions = $markdownExtensions;
210
211
        return $this;
212
    }
213
214
    public function getName()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
215
    {
216
        return $this->name;
217
    }
218
219
    public function setName($name)
220
    {
221
        $this->name = $name;
222
223
        return $this;
224
    }
225
226
    public function getStyling()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
227
    {
228
        return $this->styling;
229
    }
230
231
    public function setStyling($styling)
232
    {
233
        $this->styling = $styling;
234
235
        return $this;
236
    }
237
238
    public function getTwitterAccount()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
239
    {
240
        return $this->twitterAccount;
241
    }
242
243
    public function setTwitterAccount($twitterAccount)
244
    {
245
        $this->twitterAccount = $twitterAccount;
246
247
        return $this;
248
    }
249
250
    public function getHighResIconUrl()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
251
    {
252
        return $this->highResIconUrl;
253
    }
254
255
    public function setHighResIconUrl($highResIconUrl)
256
    {
257
        $this->highResIconUrl = $highResIconUrl;
258
259
        return $this;
260
    }
261
262
    public function setClosedBetaDate(\DateTimeInterface $closedBetaDate = null)
263
    {
264
        $this->closedBetaDate = $closedBetaDate;
265
266
        return $this;
267
    }
268
269
    public function getClosedBetaDate()
270
    {
271
        return $this->closedBetaDate;
272
    }
273
274
    public function setOpenBetaDate(\DateTimeInterface $openBetaDate = null)
275
    {
276
        $this->openBetaDate = $openBetaDate;
277
278
        return $this;
279
    }
280
281
    public function getOpenBetaDate()
282
    {
283
        return $this->openBetaDate;
284
    }
285
286
    public function setRelatedSites(array $relatedSites = [])
287
    {
288
        $this->relatedSites = $relatedSites;
289
290
        return $this;
291
    }
292
293
    public function getRelatedSites()
294
    {
295
        return $this->relatedSites;
296
    }
297
298
    public function setSiteState($siteState)
299
    {
300
        if (in_array($siteState, self::SITE_STATES, true)) {
301
            $this->siteState = $siteState;
302
        }
303
304
        return $this;
305
    }
306
307
    public function getSiteState()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
308
    {
309
        return $this->siteState;
310
    }
311
312
    public function setSiteType($siteType)
313
    {
314
        if (in_array($siteType, self::SITE_TYPES, true)) {
315
            $this->siteType = $siteType;
316
        }
317
318
        return $this;
319
    }
320
321
    public function getSiteType()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
322
    {
323
        return $this->siteType;
324
    }
325
326
    public function setSiteUrl($siteUrl)
327
    {
328
        $this->siteUrl = $siteUrl;
329
330
        return $this;
331
    }
332
333
    public function getSiteUrl()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
334
    {
335
        return $this->siteUrl;
336
    }
337
338
    public function setFaviconUrl($faviconUrl)
339
    {
340
        $this->faviconUrl = $faviconUrl;
341
342
        return $this;
343
    }
344
345
    public function getFaviconUrl()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
346
    {
347
        return $this->faviconUrl;
348
    }
349
350
    public function setHighResolutionIconUrl($highResIconUrl)
351
    {
352
        $this->highResIconUrl = $highResIconUrl;
353
354
        return $this;
355
    }
356
357
    public function getHighResolutionIconUrl()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
358
    {
359
        return $this->highResIconUrl;
360
    }
361
362
    public function setIconUrl($iconUrl)
363
    {
364
        $this->iconUrl = $iconUrl;
365
366
        return $this;
367
    }
368
369
    public function getIconUrl()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
370
    {
371
        return $this->iconUrl;
372
    }
373
374
    public function setLogoUrl($logoUrl)
375
    {
376
        $this->logoUrl = $logoUrl;
377
378
        return $this;
379
    }
380
381
    public function getLogoUrl()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
382
    {
383
        return $this->logoUrl;
384
    }
385
}
386