| Total Complexity | 40 |
| Total Lines | 468 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like ChatMember 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 ChatMember, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class ChatMember |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Information about the user |
||
| 17 | * |
||
| 18 | * @var User |
||
| 19 | */ |
||
| 20 | private $user; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * The member's status in the chat. Can be "creator", "administrator", "member", "restricted", "left" or "kicked" |
||
| 24 | * |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | private $status; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Optional. Owner and administrators only. Custom title for this user |
||
| 31 | * |
||
| 32 | * @var string|null |
||
| 33 | */ |
||
| 34 | private $custom_title; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Optional. Owner and administrators only. True, if the user's presence in the chat is hidden |
||
| 38 | * |
||
| 39 | * @since zanzara 0.5.0, Telegram Bot Api 5.0 |
||
| 40 | * |
||
| 41 | * @var bool|null |
||
| 42 | */ |
||
| 43 | private $is_anonymous; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Optional. Restricted and kicked only. Date when restrictions will be lifted for this user; unix time |
||
| 47 | * |
||
| 48 | * @var int|null |
||
| 49 | */ |
||
| 50 | private $until_date; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Optional. Administrators only. True, if the bot is allowed to edit administrator privileges of that user |
||
| 54 | * |
||
| 55 | * @var bool|null |
||
| 56 | */ |
||
| 57 | private $can_be_edited; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Optional. Administrators only. True, if the administrator can post in the channel; channels only |
||
| 61 | * |
||
| 62 | * @var bool|null |
||
| 63 | */ |
||
| 64 | private $can_post_messages; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Optional. Administrators only. True, if the administrator can edit messages of other users and can pin messages; |
||
| 68 | * channels only |
||
| 69 | * |
||
| 70 | * @var bool|null |
||
| 71 | */ |
||
| 72 | private $can_edit_messages; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Optional. Administrators only. True, if the administrator can delete messages of other users |
||
| 76 | * |
||
| 77 | * @var bool|null |
||
| 78 | */ |
||
| 79 | private $can_delete_messages; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Optional. Administrators only. True, if the administrator can restrict, ban or unban chat members |
||
| 83 | * |
||
| 84 | * @var bool|null |
||
| 85 | */ |
||
| 86 | private $can_restrict_members; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Optional. Administrators only. True, if the administrator can add new administrators with a subset of his own |
||
| 90 | * privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that |
||
| 91 | * were appointed by the user) |
||
| 92 | * |
||
| 93 | * @var bool|null |
||
| 94 | */ |
||
| 95 | private $can_promote_members; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Optional. Administrators and restricted only. True, if the user is allowed to change the chat title, photo and other |
||
| 99 | * settings |
||
| 100 | * |
||
| 101 | * @var bool|null |
||
| 102 | */ |
||
| 103 | private $can_change_info; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Optional. Administrators and restricted only. True, if the user is allowed to invite new users to the chat |
||
| 107 | * |
||
| 108 | * @var bool|null |
||
| 109 | */ |
||
| 110 | private $can_invite_users; |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Optional. Administrators and restricted only. True, if the user is allowed to pin messages; groups and supergroups only |
||
| 114 | * |
||
| 115 | * @var bool|null |
||
| 116 | */ |
||
| 117 | private $can_pin_messages; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Optional. Restricted only. True, if the user is a member of the chat at the moment of the request |
||
| 121 | * |
||
| 122 | * @var bool|null |
||
| 123 | */ |
||
| 124 | private $is_member; |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Optional. Restricted only. True, if the user is allowed to send text messages, contacts, locations and venues |
||
| 128 | * |
||
| 129 | * @var bool|null |
||
| 130 | */ |
||
| 131 | private $can_send_messages; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Optional. Restricted only. True, if the user is allowed to send audios, documents, photos, videos, video notes and |
||
| 135 | * voice notes |
||
| 136 | * |
||
| 137 | * @var bool|null |
||
| 138 | */ |
||
| 139 | private $can_send_media_messages; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Optional. Restricted only. True, if the user is allowed to send polls |
||
| 143 | * |
||
| 144 | * @var bool|null |
||
| 145 | */ |
||
| 146 | private $can_send_polls; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Optional. Restricted only. True, if the user is allowed to send animations, games, stickers and use inline bots |
||
| 150 | * |
||
| 151 | * @var bool|null |
||
| 152 | */ |
||
| 153 | private $can_send_other_messages; |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Optional. Restricted only. True, if the user is allowed to add web page previews to their messages |
||
| 157 | * |
||
| 158 | * @var bool|null |
||
| 159 | */ |
||
| 160 | private $can_add_web_page_previews; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @return User |
||
| 164 | */ |
||
| 165 | public function getUser(): User |
||
| 166 | { |
||
| 167 | return $this->user; |
||
| 168 | } |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @param User $user |
||
| 172 | */ |
||
| 173 | public function setUser(User $user): void |
||
| 174 | { |
||
| 175 | $this->user = $user; |
||
| 176 | } |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @return string |
||
| 180 | */ |
||
| 181 | public function getStatus(): string |
||
| 182 | { |
||
| 183 | return $this->status; |
||
| 184 | } |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @param string $status |
||
| 188 | */ |
||
| 189 | public function setStatus(string $status): void |
||
| 190 | { |
||
| 191 | $this->status = $status; |
||
| 192 | } |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @return string|null |
||
| 196 | */ |
||
| 197 | public function getCustomTitle(): ?string |
||
| 198 | { |
||
| 199 | return $this->custom_title; |
||
| 200 | } |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @param string|null $custom_title |
||
| 204 | */ |
||
| 205 | public function setCustomTitle(?string $custom_title): void |
||
| 206 | { |
||
| 207 | $this->custom_title = $custom_title; |
||
| 208 | } |
||
| 209 | |||
| 210 | /** |
||
| 211 | * @return int|null |
||
| 212 | */ |
||
| 213 | public function getUntilDate(): ?int |
||
| 214 | { |
||
| 215 | return $this->until_date; |
||
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @param int|null $until_date |
||
| 220 | */ |
||
| 221 | public function setUntilDate(?int $until_date): void |
||
| 222 | { |
||
| 223 | $this->until_date = $until_date; |
||
| 224 | } |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @return bool|null |
||
| 228 | */ |
||
| 229 | public function getCanBeEdited(): ?bool |
||
| 230 | { |
||
| 231 | return $this->can_be_edited; |
||
| 232 | } |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @param bool|null $can_be_edited |
||
| 236 | */ |
||
| 237 | public function setCanBeEdited(?bool $can_be_edited): void |
||
| 238 | { |
||
| 239 | $this->can_be_edited = $can_be_edited; |
||
| 240 | } |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @return bool|null |
||
| 244 | */ |
||
| 245 | public function getCanPostMessages(): ?bool |
||
| 246 | { |
||
| 247 | return $this->can_post_messages; |
||
| 248 | } |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @param bool|null $can_post_messages |
||
| 252 | */ |
||
| 253 | public function setCanPostMessages(?bool $can_post_messages): void |
||
| 256 | } |
||
| 257 | |||
| 258 | /** |
||
| 259 | * @return bool|null |
||
| 260 | */ |
||
| 261 | public function getCanEditMessages(): ?bool |
||
| 262 | { |
||
| 263 | return $this->can_edit_messages; |
||
| 264 | } |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @param bool|null $can_edit_messages |
||
| 268 | */ |
||
| 269 | public function setCanEditMessages(?bool $can_edit_messages): void |
||
| 270 | { |
||
| 271 | $this->can_edit_messages = $can_edit_messages; |
||
| 272 | } |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @return bool|null |
||
| 276 | */ |
||
| 277 | public function getCanDeleteMessages(): ?bool |
||
| 278 | { |
||
| 279 | return $this->can_delete_messages; |
||
| 280 | } |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @param bool|null $can_delete_messages |
||
| 284 | */ |
||
| 285 | public function setCanDeleteMessages(?bool $can_delete_messages): void |
||
| 286 | { |
||
| 287 | $this->can_delete_messages = $can_delete_messages; |
||
| 288 | } |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @return bool|null |
||
| 292 | */ |
||
| 293 | public function getCanRestrictMembers(): ?bool |
||
| 294 | { |
||
| 295 | return $this->can_restrict_members; |
||
| 296 | } |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @param bool|null $can_restrict_members |
||
| 300 | */ |
||
| 301 | public function setCanRestrictMembers(?bool $can_restrict_members): void |
||
| 302 | { |
||
| 303 | $this->can_restrict_members = $can_restrict_members; |
||
| 304 | } |
||
| 305 | |||
| 306 | /** |
||
| 307 | * @return bool|null |
||
| 308 | */ |
||
| 309 | public function getCanPromoteMembers(): ?bool |
||
| 310 | { |
||
| 311 | return $this->can_promote_members; |
||
| 312 | } |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @param bool|null $can_promote_members |
||
| 316 | */ |
||
| 317 | public function setCanPromoteMembers(?bool $can_promote_members): void |
||
| 318 | { |
||
| 319 | $this->can_promote_members = $can_promote_members; |
||
| 320 | } |
||
| 321 | |||
| 322 | /** |
||
| 323 | * @return bool|null |
||
| 324 | */ |
||
| 325 | public function getCanChangeInfo(): ?bool |
||
| 326 | { |
||
| 327 | return $this->can_change_info; |
||
| 328 | } |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @param bool|null $can_change_info |
||
| 332 | */ |
||
| 333 | public function setCanChangeInfo(?bool $can_change_info): void |
||
| 334 | { |
||
| 335 | $this->can_change_info = $can_change_info; |
||
| 336 | } |
||
| 337 | |||
| 338 | /** |
||
| 339 | * @return bool|null |
||
| 340 | */ |
||
| 341 | public function getCanInviteUsers(): ?bool |
||
| 342 | { |
||
| 343 | return $this->can_invite_users; |
||
| 344 | } |
||
| 345 | |||
| 346 | /** |
||
| 347 | * @param bool|null $can_invite_users |
||
| 348 | */ |
||
| 349 | public function setCanInviteUsers(?bool $can_invite_users): void |
||
| 350 | { |
||
| 351 | $this->can_invite_users = $can_invite_users; |
||
| 352 | } |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @return bool|null |
||
| 356 | */ |
||
| 357 | public function getCanPinMessages(): ?bool |
||
| 358 | { |
||
| 359 | return $this->can_pin_messages; |
||
| 360 | } |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @param bool|null $can_pin_messages |
||
| 364 | */ |
||
| 365 | public function setCanPinMessages(?bool $can_pin_messages): void |
||
| 366 | { |
||
| 367 | $this->can_pin_messages = $can_pin_messages; |
||
| 368 | } |
||
| 369 | |||
| 370 | /** |
||
| 371 | * @return bool|null |
||
| 372 | */ |
||
| 373 | public function getIsMember(): ?bool |
||
| 374 | { |
||
| 375 | return $this->is_member; |
||
| 376 | } |
||
| 377 | |||
| 378 | /** |
||
| 379 | * @param bool|null $is_member |
||
| 380 | */ |
||
| 381 | public function setIsMember(?bool $is_member): void |
||
| 382 | { |
||
| 383 | $this->is_member = $is_member; |
||
| 384 | } |
||
| 385 | |||
| 386 | /** |
||
| 387 | * @return bool|null |
||
| 388 | */ |
||
| 389 | public function getCanSendMessages(): ?bool |
||
| 392 | } |
||
| 393 | |||
| 394 | /** |
||
| 395 | * @param bool|null $can_send_messages |
||
| 396 | */ |
||
| 397 | public function setCanSendMessages(?bool $can_send_messages): void |
||
| 398 | { |
||
| 399 | $this->can_send_messages = $can_send_messages; |
||
| 400 | } |
||
| 401 | |||
| 402 | /** |
||
| 403 | * @return bool|null |
||
| 404 | */ |
||
| 405 | public function getCanSendMediaMessages(): ?bool |
||
| 406 | { |
||
| 407 | return $this->can_send_media_messages; |
||
| 408 | } |
||
| 409 | |||
| 410 | /** |
||
| 411 | * @param bool|null $can_send_media_messages |
||
| 412 | */ |
||
| 413 | public function setCanSendMediaMessages(?bool $can_send_media_messages): void |
||
| 414 | { |
||
| 415 | $this->can_send_media_messages = $can_send_media_messages; |
||
| 416 | } |
||
| 417 | |||
| 418 | /** |
||
| 419 | * @return bool|null |
||
| 420 | */ |
||
| 421 | public function getCanSendPolls(): ?bool |
||
| 422 | { |
||
| 423 | return $this->can_send_polls; |
||
| 424 | } |
||
| 425 | |||
| 426 | /** |
||
| 427 | * @param bool|null $can_send_polls |
||
| 428 | */ |
||
| 429 | public function setCanSendPolls(?bool $can_send_polls): void |
||
| 432 | } |
||
| 433 | |||
| 434 | /** |
||
| 435 | * @return bool|null |
||
| 436 | */ |
||
| 437 | public function getCanSendOtherMessages(): ?bool |
||
| 438 | { |
||
| 439 | return $this->can_send_other_messages; |
||
| 440 | } |
||
| 441 | |||
| 442 | /** |
||
| 443 | * @param bool|null $can_send_other_messages |
||
| 444 | */ |
||
| 445 | public function setCanSendOtherMessages(?bool $can_send_other_messages): void |
||
| 446 | { |
||
| 447 | $this->can_send_other_messages = $can_send_other_messages; |
||
| 448 | } |
||
| 449 | |||
| 450 | /** |
||
| 451 | * @return bool|null |
||
| 452 | */ |
||
| 453 | public function getCanAddWebPagePreviews(): ?bool |
||
| 454 | { |
||
| 455 | return $this->can_add_web_page_previews; |
||
| 456 | } |
||
| 457 | |||
| 458 | /** |
||
| 459 | * @param bool|null $can_add_web_page_previews |
||
| 460 | */ |
||
| 461 | public function setCanAddWebPagePreviews(?bool $can_add_web_page_previews): void |
||
| 462 | { |
||
| 463 | $this->can_add_web_page_previews = $can_add_web_page_previews; |
||
| 464 | } |
||
| 465 | |||
| 466 | /** |
||
| 467 | * @return bool|null |
||
| 468 | */ |
||
| 469 | public function getIsAnonymous(): ?bool |
||
| 472 | } |
||
| 473 | |||
| 474 | /** |
||
| 475 | * @param bool|null $is_anonymous |
||
| 476 | */ |
||
| 477 | public function setIsAnonymous(?bool $is_anonymous): void |
||
| 478 | { |
||
| 479 | $this->is_anonymous = $is_anonymous; |
||
| 480 | } |
||
| 481 | |||
| 482 | } |