| Conditions | 54 |
| Paths | 232 |
| Total Lines | 204 |
| Code Lines | 175 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 312 | public function getRepresent($needLink = false): string |
||
| 313 | { |
||
| 314 | if ($this->id === null) { |
||
| 315 | return $this->t('mo_NewElement'); |
||
| 316 | } |
||
| 317 | |||
| 318 | switch (static::class) { |
||
| 319 | case AsteriskManagerUsers::class: |
||
| 320 | $name = '<i class="asterisk icon"></i> ' . $this->username; |
||
| 321 | break; |
||
| 322 | case CallQueueMembers::class: |
||
| 323 | $name = $this->Extensions->getRepresent(); |
||
| 324 | break; |
||
| 325 | case CallQueues::class: |
||
| 326 | $name = '<i class="users icon"></i> ' |
||
| 327 | . $this->t('mo_CallQueueShort4Dropdown') . ': ' |
||
| 328 | . $this->name; |
||
| 329 | break; |
||
| 330 | case ConferenceRooms::class: |
||
| 331 | $name = '<i class="phone volume icon"></i> ' |
||
| 332 | . $this->t('mo_ConferenceRoomsShort4Dropdown') . ': ' |
||
| 333 | . $this->name; |
||
| 334 | break; |
||
| 335 | case CustomFiles::class: |
||
| 336 | $name = "<i class='file icon'></i> {$this->filepath}"; |
||
| 337 | break; |
||
| 338 | case DialplanApplications::class: |
||
| 339 | $name = '<i class="php icon"></i> ' |
||
| 340 | . $this->t('mo_ApplicationShort4Dropdown') . ': ' |
||
| 341 | . $this->name; |
||
| 342 | break; |
||
| 343 | case ExtensionForwardingRights::class: |
||
| 344 | $name = $this->Extensions->getRepresent(); |
||
| 345 | break; |
||
| 346 | case Extensions::class: |
||
| 347 | // Для внутреннего номера бывают разные представления |
||
| 348 | if ($this->userid > 0) { |
||
| 349 | if ($this->type === 'EXTERNAL') { |
||
| 350 | $icon = '<i class="icons"><i class="user outline icon"></i><i class="top right corner alternate mobile icon"></i></i>'; |
||
| 351 | } else { |
||
| 352 | $icon = '<i class="icons"><i class="user outline icon"></i></i>'; |
||
| 353 | } |
||
| 354 | $name = ''; |
||
| 355 | if (isset($this->Users->username)) { |
||
| 356 | $name = $this->trimName($this->Users->username); |
||
| 357 | } |
||
| 358 | |||
| 359 | $name = "{$icon} {$name} <{$this->number}>"; |
||
| 360 | } else { |
||
| 361 | switch (strtoupper($this->type)) { |
||
| 362 | case 'CONFERENCE': |
||
| 363 | $name = $this->ConferenceRooms->getRepresent(); |
||
| 364 | break; |
||
| 365 | case 'QUEUE': |
||
| 366 | $name = $this->CallQueues->getRepresent(); |
||
| 367 | break; |
||
| 368 | case 'DIALPLAN APPLICATION': |
||
| 369 | $name = $this->DialplanApplications->getRepresent(); |
||
| 370 | break; |
||
| 371 | case 'IVR MENU': |
||
| 372 | $name = $this->IvrMenu->getRepresent(); |
||
| 373 | break; |
||
| 374 | case 'MODULES': |
||
| 375 | $name = '<i class="puzzle piece icon"></i> ' |
||
| 376 | . $this->t('mo_ModuleShort4Dropdown') |
||
| 377 | . ': ' |
||
| 378 | . $this->callerid; |
||
| 379 | break; |
||
| 380 | case 'EXTERNAL': |
||
| 381 | case 'SIP': |
||
| 382 | default: |
||
| 383 | $name = "{$this->callerid} <{$this->number}>"; |
||
| 384 | } |
||
| 385 | } |
||
| 386 | break; |
||
| 387 | case ExternalPhones::class: |
||
| 388 | $name = $this->Extensions->getRepresent(); |
||
| 389 | break; |
||
| 390 | case Fail2BanRules::class: |
||
| 391 | $name = ''; |
||
| 392 | break; |
||
| 393 | case FirewallRules::class: |
||
| 394 | $name = $this->category; |
||
| 395 | break; |
||
| 396 | case Iax::class: |
||
| 397 | if ($this->disabled > 0) { |
||
| 398 | $name = "<i class='server icon'></i> {$this->description} ({$this->t( 'mo_Disabled' )})"; |
||
| 399 | } else { |
||
| 400 | $name = '<i class="server icon"></i> ' . $this->description; |
||
| 401 | } |
||
| 402 | break; |
||
| 403 | case IvrMenu::class: |
||
| 404 | $name = '<i class="sitemap icon"></i> ' |
||
| 405 | . $this->t('mo_IVRMenuShort4Dropdown') . ': ' |
||
| 406 | . $this->name; |
||
| 407 | break; |
||
| 408 | case IvrMenuActions::class: |
||
| 409 | $name = $this->IvrMenu->name; |
||
| 410 | break; |
||
| 411 | case Codecs::class: |
||
| 412 | $name = $this->name; |
||
| 413 | break; |
||
| 414 | case IaxCodecs::class: |
||
| 415 | $name = $this->codec; |
||
| 416 | break; |
||
| 417 | case IncomingRoutingTable::class: |
||
| 418 | $name = $this->t('mo_RightNumber', ['id' => $this->id]); |
||
| 419 | break; |
||
| 420 | case LanInterfaces::class: |
||
| 421 | $name = $this->name; |
||
| 422 | break; |
||
| 423 | case NetworkFilters::class: |
||
| 424 | $name = '<i class="globe icon"></i> ' . $this->description . '(' |
||
| 425 | . $this->t('fw_PermitNetwork') . ': ' . $this->permit |
||
| 426 | . ')'; |
||
| 427 | break; |
||
| 428 | case OutgoingRoutingTable::class: |
||
| 429 | $name = $this->rulename; |
||
| 430 | break; |
||
| 431 | case OutWorkTimes::class: |
||
| 432 | $name = '<i class="time icon"></i> '; |
||
| 433 | if ( ! empty($this->description)) { |
||
| 434 | $name .= $this->description; |
||
| 435 | } else { |
||
| 436 | $represent = ''; |
||
| 437 | if (is_numeric($this->date_from)) { |
||
| 438 | $represent .= date("d/m/Y", $this->date_from) . '-'; |
||
| 439 | } |
||
| 440 | if (is_numeric($this->date_to)) { |
||
| 441 | $represent .= date("d/m/Y", $this->date_to) . ' '; |
||
| 442 | } |
||
| 443 | if (isset($this->weekday_from)) { |
||
| 444 | $represent .= $this->t(date('D', strtotime("Sunday +{$this->weekday_from} days"))) . '-'; |
||
| 445 | } |
||
| 446 | if (isset($this->weekday_to)) { |
||
| 447 | $represent .= $this->t(date('D', strtotime("Sunday +{$this->weekday_to} days"))) . ' '; |
||
| 448 | } |
||
| 449 | if (isset($this->time_from) || isset($this->time_to)) { |
||
| 450 | $represent .= $this->time_from . ' - ' . $this->time_to . ' '; |
||
| 451 | } |
||
| 452 | $name .= $this->t('repOutWorkTimes', ['represent' => $represent]); |
||
| 453 | } |
||
| 454 | break; |
||
| 455 | case Providers::class: |
||
| 456 | if ($this->type === "IAX") { |
||
| 457 | $name = $this->Iax->getRepresent(); |
||
| 458 | } else { |
||
| 459 | $name = $this->Sip->getRepresent(); |
||
| 460 | } |
||
| 461 | break; |
||
| 462 | case PbxSettings::class: |
||
| 463 | $name = $this->key; |
||
| 464 | break; |
||
| 465 | case PbxExtensionModules::class: |
||
| 466 | $name = '<i class="puzzle piece icon"></i> ' |
||
| 467 | . $this->t('mo_ModuleShort4Dropdown') . ': ' |
||
| 468 | . $this->name; |
||
| 469 | break; |
||
| 470 | case Sip::class: |
||
| 471 | if ($this->Extensions) { // Это внутренний номер? |
||
| 472 | $name = $this->Extensions->getRepresent(); |
||
| 473 | } elseif ($this->Providers) { // Это провайдер |
||
| 474 | if ($this->disabled > 0) { |
||
| 475 | $name = "<i class='server icon'></i> {$this->description} ({$this->t( 'mo_Disabled' )})"; |
||
| 476 | } else { |
||
| 477 | $name = '<i class="server icon"></i> ' |
||
| 478 | . $this->description; |
||
| 479 | } |
||
| 480 | } else { // Что это? |
||
| 481 | $name = $this->description; |
||
| 482 | } |
||
| 483 | break; |
||
| 484 | case SipCodecs::class: |
||
| 485 | $name = $this->codec; |
||
| 486 | break; |
||
| 487 | case Users::class: |
||
| 488 | $name = '<i class="user outline icon"></i> ' . $this->username; |
||
| 489 | break; |
||
| 490 | case SoundFiles::class: |
||
| 491 | $name = '<i class="file audio outline icon"></i> ' |
||
| 492 | . $this->name; |
||
| 493 | break; |
||
| 494 | default: |
||
| 495 | $name = 'Unknown'; |
||
| 496 | |||
| 497 | } |
||
| 498 | |||
| 499 | if ($needLink) { |
||
| 500 | if (empty($name)) { |
||
| 501 | $name = $this->t('repLink'); |
||
| 502 | } |
||
| 503 | $link = $this->getWebInterfaceLink(); |
||
| 504 | $category = explode('\\', static::class)[3]; |
||
| 505 | $result = $this->t( |
||
| 506 | 'rep' . $category, |
||
| 507 | [ |
||
| 508 | 'represent' => "<a href='{$link}'>{$name}</a>", |
||
| 509 | ] |
||
| 510 | ); |
||
| 511 | } else { |
||
| 512 | $result = $name; |
||
| 513 | } |
||
| 514 | |||
| 515 | return $result; |
||
| 516 | } |
||
| 671 | } |