Completed
Push — v2 ( e6c7b3...40717e )
by Beñat
06:35
created

Site::getClosedBetaDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 4
rs 10
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
 * Copyright (c) 2014-2016 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
namespace BenatEspina\StackExchangeApiClient\Model;
13
14
/**
15
 * The migration info model class.
16
 *
17
 * @author Beñat Espiña <[email protected]>
18
 */
19
class Site implements Model
20
{
21
    const SITE_STATES = ['closed_beta', 'linked_meta', 'normal', 'open_beta'];
22
    const SITE_TYPES = ['main_site', 'meta_site'];
23
24
    protected $aliases;
25
    protected $apiSiteParameter;
26
    protected $audience;
27
    protected $launchDate;
28
    protected $markdownExtensions;
29
    protected $name;
30
    protected $styling;
31
    protected $twitterAccount;
32
    protected $closedBetaDate;
33
    protected $openBetaDate;
34
    protected $relatedSites;
35
    protected $siteState;
36
    protected $siteType;
37
    protected $siteUrl;
38
    protected $faviconUrl;
39
    protected $highResIconUrl;
40
    protected $iconUrl;
41
    protected $logoUrl;
42
43
    public static function fromProperties(
44
        array $aliases,
45
        $apiSiteParameter,
46
        $audience,
47
        \DateTimeInterface $launchDate,
48
        array $markdownExtensions,
49
        $name,
50
        $styling,
51
        $twitterAccount,
52
        $closedBetaDate,
53
        $openBetaDate,
54
        array $relatedSites,
55
        $siteState,
56
        $siteType,
57
        $siteUrl,
58
        $faviconUrl,
59
        $highResIconUrl,
60
        $iconUrl,
61
        $logoUrl
62
    ) {
63
        $instance = new self();
64
        $instance
65
            ->setAliases($aliases)
66
            ->setApiSiteParameter($apiSiteParameter)
67
            ->setAudience($audience)
68
            ->setLaunchDate($launchDate)
69
            ->setMarkdownExtensions($markdownExtensions)
70
            ->setName($name)
71
            ->setStyling($styling)
72
            ->setTwitterAccount($twitterAccount)
73
            ->setClosedBetaDate($closedBetaDate)
74
            ->setOpenBetaDate($openBetaDate)
75
            ->setRelatedSites($relatedSites)
76
            ->setSiteState($siteState)
77
            ->setSiteType($siteType)
78
            ->setSiteUrl($siteUrl)
79
            ->setFaviconUrl($faviconUrl)
80
            ->setHighResIconUrl($highResIconUrl)
81
            ->setIconUrl($iconUrl)
82
            ->setLogoUrl($logoUrl);
83
84
        return $instance;
85
    }
86
87
    public static function fromJson(array $data)
88
    {
89
        $aliases = [];
90
        if (array_key_exists('aliases', $data) && is_array($data['aliases'])) {
91
            foreach ($data['aliases'] as $alias) {
92
                $aliases[] = $alias;
93
            }
94
        }
95
        $markdownExtensions = [];
96
        if (array_key_exists('markdown_extensions', $data) && is_array($data['markdown_extensions'])) {
97
            foreach ($data['markdown_extensions'] as $markdownExtension) {
98
                $markdownExtensions[] = $markdownExtension;
99
            }
100
        }
101
        $relatedSites = [];
102 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...
103
            foreach ($data['related_sites'] as $relatedSite) {
104
                $relatedSites[] = RelatedSite::fromJson($relatedSite);
105
            }
106
        }
107
108
        $instance = new self();
109
        $instance
110
            ->setAliases($aliases)
111
            ->setApiSiteParameter(array_key_exists('api_site_parameter', $data) ? $data['api_site_parameter'] : null)
112
            ->setAudience(array_key_exists('audience', $data) ? $data['audience'] : null)
113
            ->setLaunchDate(
114
                array_key_exists('launch_date', $data)
115
                    ? new \DateTimeImmutable('@' . $data['launch_date'])
116
                    : null
117
            )
118
            ->setMarkdownExtensions($markdownExtensions)
119
            ->setName(array_key_exists('name', $data) ? $data['name'] : null)
120
            ->setStyling(array_key_exists('styling', $data) ? $data['styling'] : null)
121
            ->setTwitterAccount(array_key_exists('twitter_account', $data) ? $data['twitter_account'] : null)
122
            ->setClosedBetaDate(
123
                array_key_exists('closed_beta_date', $data)
124
                    ? new \DateTimeImmutable('@' . $data['closed_beta_date'])
125
                    : null
126
            )
127
            ->setOpenBetaDate(
128
                array_key_exists('open_beta_date', $data)
129
                    ? new \DateTimeImmutable('@' . $data['open_beta_date'])
130
                    : null
131
            )
132
            ->setRelatedSites($relatedSites)
133
            ->setSiteState(array_key_exists('site_state', $data) ? $data['site_state'] : null)
134
            ->setSiteType(array_key_exists('site_type', $data) ? $data['site_type'] : null)
135
            ->setSiteUrl(array_key_exists('site_url', $data) ? $data['site_url'] : null)
136
            ->setFaviconUrl(array_key_exists('favicon_url', $data) ? $data['favicon_url'] : null)
137
            ->setHighResIconUrl(array_key_exists('high_res_icon_url', $data) ? $data['high_res_icon_url'] : null)
138
            ->setIconUrl(array_key_exists('icon_url', $data) ? $data['icon_url'] : null)
139
            ->setLogoUrl(array_key_exists('logo_url', $data) ? $data['logo_url'] : null);
140
141
        return $instance;
142
    }
143
144
    public function setAliases(array $aliases = [])
145
    {
146
        $this->aliases = $aliases;
147
148
        return $this;
149
    }
150
151
    public function getAliases()
152
    {
153
        return $this->aliases;
154
    }
155
156
    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...
157
    {
158
        return $this->apiSiteParameter;
159
    }
160
161
    public function setApiSiteParameter($apiSiteParameter)
162
    {
163
        $this->apiSiteParameter = $apiSiteParameter;
164
165
        return $this;
166
    }
167
168
    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...
169
    {
170
        return $this->audience;
171
    }
172
173
    public function setAudience($audience)
174
    {
175
        $this->audience = $audience;
176
177
        return $this;
178
    }
179
180
    public function getLaunchDate()
181
    {
182
        return $this->launchDate;
183
    }
184
185
    public function setLaunchDate(\DateTimeInterface $launchDate = null)
186
    {
187
        $this->launchDate = $launchDate;
188
189
        return $this;
190
    }
191
192
    public function getMarkdownExtensions()
193
    {
194
        return $this->markdownExtensions;
195
    }
196
197
    public function setMarkdownExtensions(array $markdownExtensions = [])
198
    {
199
        $this->markdownExtensions = $markdownExtensions;
200
201
        return $this;
202
    }
203
204
    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...
205
    {
206
        return $this->name;
207
    }
208
209
    public function setName($name)
210
    {
211
        $this->name = $name;
212
213
        return $this;
214
    }
215
216
    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...
217
    {
218
        return $this->styling;
219
    }
220
221
    public function setStyling($styling)
222
    {
223
        $this->styling = $styling;
224
225
        return $this;
226
    }
227
228
    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...
229
    {
230
        return $this->twitterAccount;
231
    }
232
233
    public function setTwitterAccount($twitterAccount)
234
    {
235
        $this->twitterAccount = $twitterAccount;
236
237
        return $this;
238
    }
239
240
    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...
241
    {
242
        return $this->highResIconUrl;
243
    }
244
245
    public function setHighResIconUrl($highResIconUrl)
246
    {
247
        $this->highResIconUrl = $highResIconUrl;
248
249
        return $this;
250
    }
251
252
    public function setClosedBetaDate(\DateTimeInterface $closedBetaDate = null)
253
    {
254
        $this->closedBetaDate = $closedBetaDate;
255
256
        return $this;
257
    }
258
259
    public function getClosedBetaDate()
260
    {
261
        return $this->closedBetaDate;
262
    }
263
264
    public function setOpenBetaDate(\DateTimeInterface $openBetaDate = null)
265
    {
266
        $this->openBetaDate = $openBetaDate;
267
268
        return $this;
269
    }
270
271
    public function getOpenBetaDate()
272
    {
273
        return $this->openBetaDate;
274
    }
275
276
    public function setRelatedSites(array $relatedSites = [])
277
    {
278
        $this->relatedSites = $relatedSites;
279
280
        return $this;
281
    }
282
283
    public function getRelatedSites()
284
    {
285
        return $this->relatedSites;
286
    }
287
288
    public function setSiteState($siteState)
289
    {
290
        if (in_array($siteState, self::SITE_STATES, true)) {
291
            $this->siteState = $siteState;
292
        }
293
294
        return $this;
295
    }
296
297
    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...
298
    {
299
        return $this->siteState;
300
    }
301
302
    public function setSiteType($siteType)
303
    {
304
        if (in_array($siteType, self::SITE_TYPES, true)) {
305
            $this->siteType = $siteType;
306
        }
307
308
        return $this;
309
    }
310
311
    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...
312
    {
313
        return $this->siteType;
314
    }
315
316
    public function setSiteUrl($siteUrl)
317
    {
318
        $this->siteUrl = $siteUrl;
319
320
        return $this;
321
    }
322
323
    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...
324
    {
325
        return $this->siteUrl;
326
    }
327
328
    public function setFaviconUrl($faviconUrl)
329
    {
330
        $this->faviconUrl = $faviconUrl;
331
332
        return $this;
333
    }
334
335
    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...
336
    {
337
        return $this->faviconUrl;
338
    }
339
340
    public function setHighResolutionIconUrl($highResIconUrl)
341
    {
342
        $this->highResIconUrl = $highResIconUrl;
343
344
        return $this;
345
    }
346
347
    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...
348
    {
349
        return $this->highResIconUrl;
350
    }
351
352
    public function setIconUrl($iconUrl)
353
    {
354
        $this->iconUrl = $iconUrl;
355
356
        return $this;
357
    }
358
359
    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...
360
    {
361
        return $this->iconUrl;
362
    }
363
364
    public function setLogoUrl($logoUrl)
365
    {
366
        $this->logoUrl = $logoUrl;
367
368
        return $this;
369
    }
370
371
    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...
372
    {
373
        return $this->logoUrl;
374
    }
375
}
376