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 close details model class. |
16
|
|
|
* |
17
|
|
|
* @author Beñat Espiña <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class CloseDetails implements Model |
20
|
|
|
{ |
21
|
|
|
protected $byUsers; |
22
|
|
|
protected $description; |
23
|
|
|
protected $onHold; |
24
|
|
|
protected $originalQuestions; |
25
|
|
|
protected $reason; |
26
|
|
|
|
27
|
|
|
public static function fromProperties( |
28
|
|
|
array $byUsers, |
29
|
|
|
$description, |
30
|
|
|
$onHold, |
31
|
|
|
array $originalQuestions, |
32
|
|
|
$reason |
33
|
|
|
) { |
34
|
|
|
$instance = new self(); |
35
|
|
|
$instance |
36
|
|
|
->setByUsers($byUsers) |
37
|
|
|
->setDescription($description) |
38
|
|
|
->setOnHold($onHold) |
39
|
|
|
->setOriginalQuestions($originalQuestions) |
40
|
|
|
->setReason($reason); |
41
|
|
|
|
42
|
|
|
return $instance; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public static function fromJson(array $data) |
46
|
|
|
{ |
47
|
|
|
$instance = new self(); |
48
|
|
|
|
49
|
|
|
$byUsers = []; |
50
|
|
View Code Duplication |
if (array_key_exists('by_users', $data) && is_array($data['by_users'])) { |
|
|
|
|
51
|
|
|
foreach ($data['by_users'] as $byUser) { |
52
|
|
|
$byUsers[] = ShallowUser::fromJson($byUser); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
$originalQuestions = []; |
56
|
|
View Code Duplication |
if (array_key_exists('original_questions', $data) && is_array($data['original_questions'])) { |
|
|
|
|
57
|
|
|
foreach ($data['original_questions'] as $originalQuestion) { |
58
|
|
|
$originalQuestions[] = ShallowUser::fromJson($originalQuestion); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$instance |
|
|
|
|
63
|
|
|
->setByUsers($byUsers) |
64
|
|
|
->setDescription(array_key_exists('description', $data) ? $data['description'] : null) |
65
|
|
|
->setOnHold(array_key_exists('on_hold', $data) ? $data['on_hold'] : null) |
66
|
|
|
->setOriginalQuestions($originalQuestions) |
67
|
|
|
->setCanFlag(array_key_exists('reason', $data) ? $data['reason'] : null); |
68
|
|
|
|
69
|
|
|
return $instance; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function setByUsers(array $byUsers = []) |
73
|
|
|
{ |
74
|
|
|
$this->byUsers = $byUsers; |
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getByUsers() |
80
|
|
|
{ |
81
|
|
|
return $this->byUsers; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function setDescription($description) |
85
|
|
|
{ |
86
|
|
|
$this->description = $description; |
87
|
|
|
|
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getDescription() |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
return $this->description; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function setOnHold($onHold) |
97
|
|
|
{ |
98
|
|
|
$this->onHold = $onHold; |
99
|
|
|
|
100
|
|
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function isOnHold() |
|
|
|
|
104
|
|
|
{ |
105
|
|
|
return $this->onHold; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function setOriginalQuestions(array $originalQuestions = []) |
109
|
|
|
{ |
110
|
|
|
$this->originalQuestions = $originalQuestions; |
111
|
|
|
|
112
|
|
|
return $this; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function getOriginalQuestions() |
116
|
|
|
{ |
117
|
|
|
return $this->originalQuestions; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function setReason($reason) |
121
|
|
|
{ |
122
|
|
|
$this->reason = $reason; |
123
|
|
|
|
124
|
|
|
return $this; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function getReason() |
|
|
|
|
128
|
|
|
{ |
129
|
|
|
return $this->reason; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
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.