Total Complexity | 40 |
Total Lines | 313 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like WebPage 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 WebPage, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | class WebPage extends TdObject |
||
15 | { |
||
16 | public const TYPE_NAME = 'webPage'; |
||
17 | |||
18 | /** |
||
19 | * Original URL of the link. |
||
20 | */ |
||
21 | protected string $url; |
||
22 | |||
23 | /** |
||
24 | * URL to display. |
||
25 | */ |
||
26 | protected string $displayUrl; |
||
27 | |||
28 | /** |
||
29 | * Type of the web page. Can be: article, photo, audio, video, document, profile, app, or something else. |
||
30 | */ |
||
31 | protected string $type; |
||
32 | |||
33 | /** |
||
34 | * Short name of the site (e.g., Google Docs, App Store). |
||
35 | */ |
||
36 | protected string $siteName; |
||
37 | |||
38 | /** |
||
39 | * Title of the content. |
||
40 | */ |
||
41 | protected string $title; |
||
42 | |||
43 | /** |
||
44 | * Description of the content. |
||
45 | */ |
||
46 | protected string $description; |
||
47 | |||
48 | /** |
||
49 | * Image representing the content; may be null. |
||
50 | */ |
||
51 | protected ?Photo $photo; |
||
52 | |||
53 | /** |
||
54 | * URL to show in the embedded preview. |
||
55 | */ |
||
56 | protected string $embedUrl; |
||
57 | |||
58 | /** |
||
59 | * MIME type of the embedded preview, (e.g., text/html or video/mp4). |
||
60 | */ |
||
61 | protected string $embedType; |
||
62 | |||
63 | /** |
||
64 | * Width of the embedded preview. |
||
65 | */ |
||
66 | protected int $embedWidth; |
||
67 | |||
68 | /** |
||
69 | * Height of the embedded preview. |
||
70 | */ |
||
71 | protected int $embedHeight; |
||
72 | |||
73 | /** |
||
74 | * Duration of the content, in seconds. |
||
75 | */ |
||
76 | protected int $duration; |
||
77 | |||
78 | /** |
||
79 | * Author of the content. |
||
80 | */ |
||
81 | protected string $author; |
||
82 | |||
83 | /** |
||
84 | * Preview of the content as an animation, if available; may be null. |
||
85 | */ |
||
86 | protected ?Animation $animation; |
||
87 | |||
88 | /** |
||
89 | * Preview of the content as an audio file, if available; may be null. |
||
90 | */ |
||
91 | protected ?Audio $audio; |
||
92 | |||
93 | /** |
||
94 | * Preview of the content as a document, if available (currently only available for small PDF files and ZIP archives); may be null. |
||
95 | */ |
||
96 | protected ?Document $document; |
||
97 | |||
98 | /** |
||
99 | * Preview of the content as a sticker for small WEBP files, if available; may be null. |
||
100 | */ |
||
101 | protected ?Sticker $sticker; |
||
102 | |||
103 | /** |
||
104 | * Preview of the content as a video, if available; may be null. |
||
105 | */ |
||
106 | protected ?Video $video; |
||
107 | |||
108 | /** |
||
109 | * Preview of the content as a video note, if available; may be null. |
||
110 | */ |
||
111 | protected ?VideoNote $videoNote; |
||
112 | |||
113 | /** |
||
114 | * Preview of the content as a voice note, if available; may be null. |
||
115 | */ |
||
116 | protected ?VoiceNote $voiceNote; |
||
117 | |||
118 | /** |
||
119 | * Version of instant view, available for the web page (currently can be 1 or 2), 0 if none. |
||
120 | */ |
||
121 | protected int $instantViewVersion; |
||
122 | |||
123 | public function __construct( |
||
167 | } |
||
168 | |||
169 | public static function fromArray(array $array): WebPage |
||
170 | { |
||
171 | return new static( |
||
172 | $array['url'], |
||
173 | $array['display_url'], |
||
174 | $array['type'], |
||
175 | $array['site_name'], |
||
176 | $array['title'], |
||
177 | $array['description'], |
||
178 | (isset($array['photo']) ? TdSchemaRegistry::fromArray($array['photo']) : null), |
||
179 | $array['embed_url'], |
||
180 | $array['embed_type'], |
||
181 | $array['embed_width'], |
||
182 | $array['embed_height'], |
||
183 | $array['duration'], |
||
184 | $array['author'], |
||
185 | (isset($array['animation']) ? TdSchemaRegistry::fromArray($array['animation']) : null), |
||
186 | (isset($array['audio']) ? TdSchemaRegistry::fromArray($array['audio']) : null), |
||
187 | (isset($array['document']) ? TdSchemaRegistry::fromArray($array['document']) : null), |
||
188 | (isset($array['sticker']) ? TdSchemaRegistry::fromArray($array['sticker']) : null), |
||
189 | (isset($array['video']) ? TdSchemaRegistry::fromArray($array['video']) : null), |
||
190 | (isset($array['video_note']) ? TdSchemaRegistry::fromArray($array['video_note']) : null), |
||
191 | (isset($array['voice_note']) ? TdSchemaRegistry::fromArray($array['voice_note']) : null), |
||
192 | $array['instant_view_version'], |
||
193 | ); |
||
194 | } |
||
195 | |||
196 | public function typeSerialize(): array |
||
197 | { |
||
198 | return [ |
||
199 | '@type' => static::TYPE_NAME, |
||
200 | 'url' => $this->url, |
||
201 | 'display_url' => $this->displayUrl, |
||
202 | 'type' => $this->type, |
||
203 | 'site_name' => $this->siteName, |
||
204 | 'title' => $this->title, |
||
205 | 'description' => $this->description, |
||
206 | 'photo' => (isset($this->photo) ? $this->photo : null), |
||
207 | 'embed_url' => $this->embedUrl, |
||
208 | 'embed_type' => $this->embedType, |
||
209 | 'embed_width' => $this->embedWidth, |
||
210 | 'embed_height' => $this->embedHeight, |
||
211 | 'duration' => $this->duration, |
||
212 | 'author' => $this->author, |
||
213 | 'animation' => (isset($this->animation) ? $this->animation : null), |
||
214 | 'audio' => (isset($this->audio) ? $this->audio : null), |
||
215 | 'document' => (isset($this->document) ? $this->document : null), |
||
216 | 'sticker' => (isset($this->sticker) ? $this->sticker : null), |
||
217 | 'video' => (isset($this->video) ? $this->video : null), |
||
218 | 'video_note' => (isset($this->videoNote) ? $this->videoNote : null), |
||
219 | 'voice_note' => (isset($this->voiceNote) ? $this->voiceNote : null), |
||
220 | 'instant_view_version' => $this->instantViewVersion, |
||
221 | ]; |
||
222 | } |
||
223 | |||
224 | public function getUrl(): string |
||
225 | { |
||
226 | return $this->url; |
||
227 | } |
||
228 | |||
229 | public function getDisplayUrl(): string |
||
232 | } |
||
233 | |||
234 | public function getType(): string |
||
235 | { |
||
236 | return $this->type; |
||
237 | } |
||
238 | |||
239 | public function getSiteName(): string |
||
240 | { |
||
241 | return $this->siteName; |
||
242 | } |
||
243 | |||
244 | public function getTitle(): string |
||
245 | { |
||
246 | return $this->title; |
||
247 | } |
||
248 | |||
249 | public function getDescription(): string |
||
250 | { |
||
251 | return $this->description; |
||
252 | } |
||
253 | |||
254 | public function getPhoto(): ?Photo |
||
255 | { |
||
256 | return $this->photo; |
||
257 | } |
||
258 | |||
259 | public function getEmbedUrl(): string |
||
260 | { |
||
261 | return $this->embedUrl; |
||
262 | } |
||
263 | |||
264 | public function getEmbedType(): string |
||
265 | { |
||
266 | return $this->embedType; |
||
267 | } |
||
268 | |||
269 | public function getEmbedWidth(): int |
||
270 | { |
||
271 | return $this->embedWidth; |
||
272 | } |
||
273 | |||
274 | public function getEmbedHeight(): int |
||
275 | { |
||
276 | return $this->embedHeight; |
||
277 | } |
||
278 | |||
279 | public function getDuration(): int |
||
280 | { |
||
281 | return $this->duration; |
||
282 | } |
||
283 | |||
284 | public function getAuthor(): string |
||
285 | { |
||
286 | return $this->author; |
||
287 | } |
||
288 | |||
289 | public function getAnimation(): ?Animation |
||
290 | { |
||
291 | return $this->animation; |
||
292 | } |
||
293 | |||
294 | public function getAudio(): ?Audio |
||
295 | { |
||
296 | return $this->audio; |
||
297 | } |
||
298 | |||
299 | public function getDocument(): ?Document |
||
302 | } |
||
303 | |||
304 | public function getSticker(): ?Sticker |
||
305 | { |
||
306 | return $this->sticker; |
||
307 | } |
||
308 | |||
309 | public function getVideo(): ?Video |
||
310 | { |
||
311 | return $this->video; |
||
312 | } |
||
313 | |||
314 | public function getVideoNote(): ?VideoNote |
||
317 | } |
||
318 | |||
319 | public function getVoiceNote(): ?VoiceNote |
||
322 | } |
||
323 | |||
324 | public function getInstantViewVersion(): int |
||
325 | { |
||
326 | return $this->instantViewVersion; |
||
327 | } |
||
328 | } |
||
329 |