Total Complexity | 43 |
Total Lines | 282 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Complex classes like Event often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Event, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
8 | class Event implements Resource |
||
9 | { |
||
10 | /** |
||
11 | * Resource Payload. |
||
12 | * |
||
13 | * @var object |
||
14 | */ |
||
15 | private $data; |
||
16 | |||
17 | /** |
||
18 | * Class Constructor. |
||
19 | * |
||
20 | * @param string $fullName |
||
21 | * @param boolean $init |
||
22 | */ |
||
23 | public function __construct(string $fullName, bool $init = true) |
||
28 | } |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Factory Method. |
||
33 | * |
||
34 | * @param object $object |
||
35 | * @return \LiveStream\Resources\Event|null |
||
36 | */ |
||
37 | public static function fromObject(?object $object): ?Event |
||
38 | { |
||
39 | if ($object == null) return null; |
||
40 | |||
41 | $instance = new static(false); |
||
|
|||
42 | $instance->data = $object; |
||
43 | return $instance; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Magic Setter Method |
||
48 | * |
||
49 | * @param string $key |
||
50 | * @param mixed $value |
||
51 | * @return void |
||
52 | */ |
||
53 | public function __set(string $key, $value): void |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Magic Getter Method |
||
60 | * |
||
61 | * @param string $key |
||
62 | * @return void |
||
63 | */ |
||
64 | public function __get(string $key) |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Magic Method Isset. |
||
71 | * |
||
72 | * @param string $key |
||
73 | * @return boolean |
||
74 | */ |
||
75 | public function __isset(string $key) |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * Set Full Name. |
||
82 | * |
||
83 | * @param string $fullName |
||
84 | * @return \LiveStream\Resources\Event |
||
85 | */ |
||
86 | public function setFullName(string $fullName): Event |
||
87 | { |
||
88 | $this->data->fullName = $fullName; |
||
89 | return $this; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Get Full Name. |
||
94 | * |
||
95 | * @return string|null |
||
96 | */ |
||
97 | public function getFullName(): ?string |
||
98 | { |
||
99 | return $this->data->fullName ?? null; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Set Event Start Time. |
||
104 | * |
||
105 | * @param string $strtime |
||
106 | * @return \LiveStream\Resources\Event |
||
107 | */ |
||
108 | public function setStartTime(string $strtime): Event |
||
109 | { |
||
110 | $this->data->startTime = date('c', strtotime($strtime)); |
||
111 | return $this; |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Get Start Time |
||
116 | * |
||
117 | * @return string |
||
118 | */ |
||
119 | public function getStartTime(): ?string |
||
120 | { |
||
121 | return $this->data->startTime ?? null; |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * Set End Time |
||
126 | * |
||
127 | * @param string $strtime |
||
128 | * @return \LiveStream\Resources\Event |
||
129 | */ |
||
130 | public function setEndTime(string $strtime): Event |
||
131 | { |
||
132 | $this->data->endTime = date('c', strtotime($strtime)); |
||
133 | return $this; |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * Get End Time. |
||
138 | * |
||
139 | * @return string |
||
140 | */ |
||
141 | public function getEndTime(): ?string |
||
142 | { |
||
143 | return $this->data->endTime ?? null; |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * Set Is Draft. |
||
148 | * |
||
149 | * @param boolean $isDraft |
||
150 | * |
||
151 | * @return \LiveStream\Resources\Event |
||
152 | */ |
||
153 | public function setIsDraft(bool $isDraft = true): Event |
||
154 | { |
||
155 | $this->data->draft = $isDraft; |
||
156 | return $this; |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * Get Is Draft. |
||
161 | * |
||
162 | * @return boolean |
||
163 | */ |
||
164 | public function isDraft(): bool |
||
165 | { |
||
166 | return $this->data->draft ?? true; |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * Set Event Short Name. |
||
171 | * |
||
172 | * @param string $shortName |
||
173 | * @return Event |
||
174 | */ |
||
175 | public function setShortName(string $shortName): Event |
||
176 | { |
||
177 | $this->data->shortName = $shortName; |
||
178 | return $this; |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * Get Event Short Name. |
||
183 | * |
||
184 | * @return string|null |
||
185 | */ |
||
186 | public function getShortName(): ?string |
||
187 | { |
||
188 | return $this->data->shortName ?? null; |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * Set Event Description |
||
193 | * |
||
194 | * @param string $description |
||
195 | * @return Event |
||
196 | */ |
||
197 | public function setDescription(string $description): Event |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * Get Description. |
||
205 | * |
||
206 | * @return string|null |
||
207 | */ |
||
208 | public function getDescription(): ?string |
||
209 | { |
||
210 | return $this->data->description ?? null; |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * Add Event Tag |
||
215 | * |
||
216 | * @param string $tag |
||
217 | * @return \LiveStream\Resources\Event |
||
218 | */ |
||
219 | public function addTag(string $tag): Event |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * Get Tags. |
||
230 | * |
||
231 | * @return string |
||
232 | */ |
||
233 | public function getTags(): string |
||
236 | } |
||
237 | |||
238 | /** |
||
239 | * Resource Interface Method: Get Resource as FormURLEncoded String. |
||
240 | * |
||
241 | * @return string |
||
242 | */ |
||
243 | public function getRawBody(): string |
||
280 | } |
||
281 | |||
282 | /** |
||
283 | * Undocumented function |
||
284 | * |
||
285 | * @return string |
||
286 | */ |
||
287 | public function getContentType(): string |
||
292 |