Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Util 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 Util, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 24 | class Util  | 
            ||
| 25 | { | 
            ||
| 26 | const AUTO_REFUND_REASON_VALIDATION = 1;  | 
            ||
| 27 | const AUTO_REFUND_REASON_INACTIVE = 2;  | 
            ||
| 28 | const AUTO_REFUND_REASON_TYPE = 3;  | 
            ||
| 29 | const AUTO_REFUND_REASON_BRAND = 4;  | 
            ||
| 30 | const AUTO_REFUND_REASON_REJECTED = 5;  | 
            ||
| 31 | const AUTO_REFUND_REASON_MALWARE = 6;  | 
            ||
| 32 | const AUTO_REFUND_REASON_PHISHING = 7;  | 
            ||
| 33 | const AUTO_REFUND_REASON_SAFE_BROWSING = 8;  | 
            ||
| 34 | const AUTO_REFUND_REASON_AUTHORITY = 9;  | 
            ||
| 35 | const AUTO_REFUND_REASON_PRICE = 10;  | 
            ||
| 36 | const AUTO_REFUND_REASON_OTHER = 11;  | 
            ||
| 37 | |||
| 38 | const COMODO_AUTO_REFUND_URL = 'https://secure.trust-provider.com/products/!AutoRefund';  | 
            ||
| 39 | const COMODO_AUTO_APPLY_URL = 'https://secure.trust-provider.com/products/!AutoApplySSL';  | 
            ||
| 40 | const COMODO_AUTO_REVOKE_URL = 'https://secure.trust-provider.com/products/!AutoRevokeSSL';  | 
            ||
| 41 | const COMODO_DCV_MAIL_URL = 'https://secure.trust-provider.com/products/!GetDCVEmailAddressList';  | 
            ||
| 42 | const COMODO_DCV_RESEND_URL = 'https://secure.trust-provider.com/products/!ResendDCVEmail';  | 
            ||
| 43 | const COMODO_AUTO_UPDATE_DCV_URL = 'https://secure.trust-provider.com/products/!AutoUpdateDCV';  | 
            ||
| 44 | const COMODO_PROVIDE_EV_DETAILS_URL = 'https://secure.trust-provider.com/products/!ProvideEVDetails';  | 
            ||
| 45 | const COMODO_MDC_DOMAIN_DETAILS_URL = 'https://secure.trust-provider.com/products/!GetMDCDomainDetails';  | 
            ||
| 46 | const COMODO_AUTO_REPLACE_URL = 'https://secure.trust-provider.com/products/!AutoReplaceSSL';  | 
            ||
| 47 | const COMODO_COLLECT_SSL_URL = 'https://secure.trust-provider.com/products/download/CollectSSL';  | 
            ||
| 48 | const COMODO_UPDATE_USER_EV_CLICK_THROUGH = 'https://secure.trust-provider.com/products/!UpdateUserEvClickThrough';  | 
            ||
| 49 | const COMODO_WEB_HOST_REPORT = 'https://secure.trust-provider.com/products/!WebHostReport';  | 
            ||
| 50 | const COMODO_SSLCHECKER = 'https://secure.trust-provider.com/sslchecker';  | 
            ||
| 51 | const COMODO_DCV_CODE_URL = 'https://secure.trust-provider.com/products/EnterDCVCode2';  | 
            ||
| 52 | |||
| 53 | /**  | 
            ||
| 54 | * @var CommunicationAdapter  | 
            ||
| 55 | */  | 
            ||
| 56 | protected $communicationAdapter;  | 
            ||
| 57 | |||
| 58 | /**  | 
            ||
| 59 | * @var ImapAdapter  | 
            ||
| 60 | */  | 
            ||
| 61 | protected $imapAdapter;  | 
            ||
| 62 | |||
| 63 | /**  | 
            ||
| 64 | * @var ImapHelper  | 
            ||
| 65 | */  | 
            ||
| 66 | protected $imapHelper;  | 
            ||
| 67 | |||
| 68 | /**  | 
            ||
| 69 | * Constructs the Util with a communicationAdapter  | 
            ||
| 70 | *  | 
            ||
| 71 | * @param CommunicationAdapter|null $communicationAdapter  | 
            ||
| 72 | * @param ImapAdapter|null $imapAdapter  | 
            ||
| 73 | * @param ImapHelper|null $imapHelper  | 
            ||
| 74 | */  | 
            ||
| 75 | public function __construct(CommunicationAdapter $communicationAdapter, ImapAdapter $imapAdapter, ImapHelper $imapHelper)  | 
            ||
| 81 | |||
| 82 | |||
| 83 | /**  | 
            ||
| 84 | * @return CommunicationAdapter  | 
            ||
| 85 | */  | 
            ||
| 86 | public function getCommunicationAdapter()  | 
            ||
| 90 | |||
| 91 | /**  | 
            ||
| 92 | * @param CommunicationAdapter $communicationAdapter  | 
            ||
| 93 | *  | 
            ||
| 94 | * @return Util  | 
            ||
| 95 | */  | 
            ||
| 96 | public function setCommunicationAdapter(CommunicationAdapter $communicationAdapter)  | 
            ||
| 102 | |||
| 103 | /**  | 
            ||
| 104 | * @return ImapHelper  | 
            ||
| 105 | */  | 
            ||
| 106 | public function getImapHelper()  | 
            ||
| 110 | |||
| 111 | /**  | 
            ||
| 112 | * @param ImapHelper $imapHelper  | 
            ||
| 113 | *  | 
            ||
| 114 | * @return Util  | 
            ||
| 115 | */  | 
            ||
| 116 | public function setImapHelper(ImapHelper $imapHelper)  | 
            ||
| 122 | |||
| 123 | /**  | 
            ||
| 124 | * @return ImapAdapter  | 
            ||
| 125 | */  | 
            ||
| 126 | public function getImapAdapter()  | 
            ||
| 130 | |||
| 131 | /**  | 
            ||
| 132 | * @param ImapAdapter $imapAdapter  | 
            ||
| 133 | *  | 
            ||
| 134 | * @return Util  | 
            ||
| 135 | */  | 
            ||
| 136 | public function setImapAdapter(ImapAdapter $imapAdapter)  | 
            ||
| 142 | |||
| 143 | /**  | 
            ||
| 144 | * Refunds a ordered certificate  | 
            ||
| 145 | *  | 
            ||
| 146 | * @param array $params  | 
            ||
| 147 | *  | 
            ||
| 148 | * @return bool  | 
            ||
| 149 | *  | 
            ||
| 150 | * @throws AccountException  | 
            ||
| 151 | * @throws ArgumentException  | 
            ||
| 152 | * @throws CSRException  | 
            ||
| 153 | * @throws RequestException  | 
            ||
| 154 | * @throws UnknownApiException  | 
            ||
| 155 | * @throws UnknownException  | 
            ||
| 156 | */  | 
            ||
| 157 | public function autoRefund(array $params)  | 
            ||
| 177 | |||
| 178 | /**  | 
            ||
| 179 | * Function apply for a certificate  | 
            ||
| 180 | *  | 
            ||
| 181 | * See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/  | 
            ||
| 182 | *  | 
            ||
| 183 | * @param array $params  | 
            ||
| 184 | *  | 
            ||
| 185 | * @return AutoApplyResult  | 
            ||
| 186 | * @throws Model\Exception\AccountException  | 
            ||
| 187 | * @throws Model\Exception\ArgumentException  | 
            ||
| 188 | * @throws Model\Exception\CSRException  | 
            ||
| 189 | * @throws Model\Exception\RequestException  | 
            ||
| 190 | * @throws Model\Exception\UnknownApiException  | 
            ||
| 191 | * @throws Model\Exception\UnknownException  | 
            ||
| 192 | */  | 
            ||
| 193 | public function autoApplySSL(array $params)  | 
            ||
| 231 | |||
| 232 | /**  | 
            ||
| 233 | * @param array $params  | 
            ||
| 234 | *  | 
            ||
| 235 | * @return UpdateUserEvClickThroughResult  | 
            ||
| 236 | * @throws AccountException  | 
            ||
| 237 | * @throws ArgumentException  | 
            ||
| 238 | * @throws CSRException  | 
            ||
| 239 | * @throws RequestException  | 
            ||
| 240 | * @throws UnknownApiException  | 
            ||
| 241 | * @throws UnknownException  | 
            ||
| 242 | */  | 
            ||
| 243 | public function updateUserEvClickThrough(array $params)  | 
            ||
| 266 | |||
| 267 | /**  | 
            ||
| 268 | * Function update for a certificate  | 
            ||
| 269 | *  | 
            ||
| 270 | * See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/  | 
            ||
| 271 | *  | 
            ||
| 272 | * @param array $params  | 
            ||
| 273 | *  | 
            ||
| 274 | * @return AutoReplaceResult  | 
            ||
| 275 | * @throws Model\Exception\AccountException  | 
            ||
| 276 | * @throws Model\Exception\ArgumentException  | 
            ||
| 277 | * @throws Model\Exception\CSRException  | 
            ||
| 278 | * @throws Model\Exception\RequestException  | 
            ||
| 279 | * @throws Model\Exception\UnknownApiException  | 
            ||
| 280 | * @throws Model\Exception\UnknownException  | 
            ||
| 281 | */  | 
            ||
| 282 | public function autoReplaceSSL(array $params)  | 
            ||
| 313 | |||
| 314 | /**  | 
            ||
| 315 | * Function to revoke order  | 
            ||
| 316 | *  | 
            ||
| 317 | * See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/  | 
            ||
| 318 | *  | 
            ||
| 319 | * @param array $params  | 
            ||
| 320 | *  | 
            ||
| 321 | * @return bool  | 
            ||
| 322 | * @throws Model\Exception\AccountException  | 
            ||
| 323 | * @throws Model\Exception\ArgumentException  | 
            ||
| 324 | * @throws Model\Exception\RequestException  | 
            ||
| 325 | * @throws Model\Exception\UnknownApiException  | 
            ||
| 326 | * @throws Model\Exception\UnknownException  | 
            ||
| 327 | */  | 
            ||
| 328 | public function autoRevokeSSL(array $params)  | 
            ||
| 339 | |||
| 340 | /**  | 
            ||
| 341 | * Function to auto update dcv  | 
            ||
| 342 | *  | 
            ||
| 343 | * See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/  | 
            ||
| 344 | *  | 
            ||
| 345 | * @param array $params  | 
            ||
| 346 | *  | 
            ||
| 347 | * @return bool  | 
            ||
| 348 | * @throws Model\Exception\AccountException  | 
            ||
| 349 | * @throws Model\Exception\ArgumentException  | 
            ||
| 350 | * @throws Model\Exception\RequestException  | 
            ||
| 351 | * @throws Model\Exception\UnknownApiException  | 
            ||
| 352 | * @throws Model\Exception\UnknownException  | 
            ||
| 353 | */  | 
            ||
| 354 | public function autoUpdateDCV(array $params)  | 
            ||
| 362 | |||
| 363 | /**  | 
            ||
| 364 | * Function to get details of a certificate  | 
            ||
| 365 | *  | 
            ||
| 366 | * See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/  | 
            ||
| 367 | *  | 
            ||
| 368 | * @param array $params  | 
            ||
| 369 | *  | 
            ||
| 370 | * @return CollectSslResult  | 
            ||
| 371 | * @throws Model\Exception\AccountException  | 
            ||
| 372 | * @throws Model\Exception\ArgumentException  | 
            ||
| 373 | * @throws Model\Exception\CSRException  | 
            ||
| 374 | * @throws Model\Exception\RequestException  | 
            ||
| 375 | * @throws Model\Exception\UnknownApiException  | 
            ||
| 376 | * @throws Model\Exception\UnknownException  | 
            ||
| 377 | */  | 
            ||
| 378 | public function collectSsl(array $params)  | 
            ||
| 424 | |||
| 425 | /**  | 
            ||
| 426 | * Function to resend the DCV Email  | 
            ||
| 427 | *  | 
            ||
| 428 | * See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/  | 
            ||
| 429 | *  | 
            ||
| 430 | * @param array $params  | 
            ||
| 431 | *  | 
            ||
| 432 | * @return bool  | 
            ||
| 433 | * @throws Model\Exception\AccountException  | 
            ||
| 434 | * @throws Model\Exception\ArgumentException  | 
            ||
| 435 | * @throws Model\Exception\RequestException  | 
            ||
| 436 | * @throws Model\Exception\UnknownApiException  | 
            ||
| 437 | * @throws Model\Exception\UnknownException  | 
            ||
| 438 | */  | 
            ||
| 439 | public function resendDCVEMail(array $params)  | 
            ||
| 448 | |||
| 449 | /**  | 
            ||
| 450 | * @param array $params  | 
            ||
| 451 | *  | 
            ||
| 452 | * @deprecated Comodo support told this function doesn't have any effect anymore  | 
            ||
| 453 | *  | 
            ||
| 454 | * @return bool  | 
            ||
| 455 | * @throws Model\Exception\AccountException  | 
            ||
| 456 | * @throws Model\Exception\ArgumentException  | 
            ||
| 457 | * @throws Model\Exception\CSRException  | 
            ||
| 458 | * @throws Model\Exception\RequestException  | 
            ||
| 459 | * @throws Model\Exception\UnknownApiException  | 
            ||
| 460 | * @throws Model\Exception\UnknownException  | 
            ||
| 461 | */  | 
            ||
| 462 | public function provideEVDetails(array $params)  | 
            ||
| 470 | |||
| 471 | /**  | 
            ||
| 472 | * Function to get the DCV e-mail address-list  | 
            ||
| 473 | *  | 
            ||
| 474 | * See documentation of params at https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/  | 
            ||
| 475 | *  | 
            ||
| 476 | * @param array $params  | 
            ||
| 477 | *  | 
            ||
| 478 | * @return GetDCVEMailAddressListResult  | 
            ||
| 479 | * @throws AccountException  | 
            ||
| 480 | * @throws ArgumentException  | 
            ||
| 481 | * @throws CSRException  | 
            ||
| 482 | * @throws RequestException  | 
            ||
| 483 | * @throws UnknownApiException  | 
            ||
| 484 | * @throws UnknownException  | 
            ||
| 485 | */  | 
            ||
| 486 | public function getDCVEMailAddressList(array $params)  | 
            ||
| 524 | |||
| 525 | /**  | 
            ||
| 526 | * Function to get details of a order-number (this API support just one domain)  | 
            ||
| 527 | *  | 
            ||
| 528 | * https://secure.comodo.net/api/pdf/webhostreseller/sslcertificates/GetMDCDomainDetails%20v1.00.pdf  | 
            ||
| 529 | *  | 
            ||
| 530 | * @param array $params  | 
            ||
| 531 | *  | 
            ||
| 532 | * @return GetMDCDomainDetailsResult  | 
            ||
| 533 | *  | 
            ||
| 534 | * @throws Model\Exception\AccountException  | 
            ||
| 535 | * @throws Model\Exception\ArgumentException  | 
            ||
| 536 | * @throws Model\Exception\CSRException  | 
            ||
| 537 | * @throws Model\Exception\RequestException  | 
            ||
| 538 | * @throws Model\Exception\UnknownApiException  | 
            ||
| 539 | * @throws Model\Exception\UnknownException  | 
            ||
| 540 | */  | 
            ||
| 541 | View Code Duplication | public function getMDCDomainDetails(array $params)  | 
            |
| 565 | |||
| 566 | /**  | 
            ||
| 567 | * Function to do a sslcheck  | 
            ||
| 568 | *  | 
            ||
| 569 | * https://secure.comodo.net/api/pdf/latest/SSLChecker.pdf  | 
            ||
| 570 | *  | 
            ||
| 571 | * @param array $params  | 
            ||
| 572 | *  | 
            ||
| 573 | * @return GetMDCDomainDetailsResult  | 
            ||
| 574 | *  | 
            ||
| 575 | * @throws Model\Exception\AccountException  | 
            ||
| 576 | * @throws Model\Exception\ArgumentException  | 
            ||
| 577 | * @throws Model\Exception\CSRException  | 
            ||
| 578 | * @throws Model\Exception\RequestException  | 
            ||
| 579 | * @throws Model\Exception\UnknownApiException  | 
            ||
| 580 | * @throws Model\Exception\UnknownException  | 
            ||
| 581 | */  | 
            ||
| 582 | public function sslChecker(array $params)  | 
            ||
| 636 | |||
| 637 | /**  | 
            ||
| 638 | * Function to call WebHostReport api  | 
            ||
| 639 | *  | 
            ||
| 640 | * https://secure.comodo.net/products/!WebHostReport  | 
            ||
| 641 | *  | 
            ||
| 642 | * Details for params usage:  | 
            ||
| 643 | * https://secure.comodo.net/api/pdf/latest/WebHostReport.pdf  | 
            ||
| 644 | *  | 
            ||
| 645 | * @param array $params  | 
            ||
| 646 | *  | 
            ||
| 647 | * @return WebHostReportResult  | 
            ||
| 648 | *  | 
            ||
| 649 | * @throws Model\Exception\AccountException  | 
            ||
| 650 | * @throws Model\Exception\ArgumentException  | 
            ||
| 651 | * @throws Model\Exception\CSRException  | 
            ||
| 652 | * @throws Model\Exception\RequestException  | 
            ||
| 653 | * @throws Model\Exception\UnknownApiException  | 
            ||
| 654 | * @throws Model\Exception\UnknownException  | 
            ||
| 655 | */  | 
            ||
| 656 | View Code Duplication |     public function webHostReport(array $params) { | 
            |
| 678 | |||
| 679 | /**  | 
            ||
| 680 | * Function to enter the DCV code, coming from DCV E-Mail  | 
            ||
| 681 | *  | 
            ||
| 682 | * @param array $params  | 
            ||
| 683 | *  | 
            ||
| 684 | * @return bool  | 
            ||
| 685 | * @throws Model\Exception\UnknownException  | 
            ||
| 686 | * @throws Model\Exception\ArgumentException  | 
            ||
| 687 | */  | 
            ||
| 688 | public function enterDCVCode(array $params)  | 
            ||
| 715 | |||
| 716 | /**  | 
            ||
| 717 | * @param string $domainName  | 
            ||
| 718 | * @param null $orderNumbers  | 
            ||
| 719 | * @param \Closure $callbackFunction  | 
            ||
| 720 | *  | 
            ||
| 721 | * @return array  | 
            ||
| 722 | */  | 
            ||
| 723 | public function getMails($domainName, $orderNumbers = null, \Closure $callbackFunction = null)  | 
            ||
| 743 | |||
| 744 | /**  | 
            ||
| 745 | * @param bool $markProcessed  | 
            ||
| 746 | * @param \Closure $callbackFunction  | 
            ||
| 747 | *  | 
            ||
| 748 | * @return array  | 
            ||
| 749 | */  | 
            ||
| 750 | public function getUnprocessedMails($markProcessed = true, \Closure $callbackFunction = null)  | 
            ||
| 764 | |||
| 765 | /**  | 
            ||
| 766 | * Function to create an exception for API errorcodes  | 
            ||
| 767 | *  | 
            ||
| 768 | * @param array|mixed $responseArray  | 
            ||
| 769 | *  | 
            ||
| 770 | * @return AccountException|ArgumentException|CSRException|RequestException|UnknownApiException|UnknownException  | 
            ||
| 771 | *  | 
            ||
| 772 | * @SuppressWarnings(PHPMD.CyclomaticComplexity)  | 
            ||
| 773 | */  | 
            ||
| 774 | protected function createException($responseArray)  | 
            ||
| 848 | |||
| 849 | /**  | 
            ||
| 850 | * @param CollectSslResult $object  | 
            ||
| 851 | * @param array $arr  | 
            ||
| 852 | * @param array $timestampFields  | 
            ||
| 853 | *  | 
            ||
| 854 | * @return $this  | 
            ||
| 855 | */  | 
            ||
| 856 | protected function fill(CollectSslResult $object, array $arr, array $timestampFields = array())  | 
            ||
| 873 | |||
| 874 | /**  | 
            ||
| 875 | * @param string $url  | 
            ||
| 876 | * @param array $params  | 
            ||
| 877 | * @param int $type  | 
            ||
| 878 | *  | 
            ||
| 879 | * @return bool  | 
            ||
| 880 | * @throws AccountException  | 
            ||
| 881 | * @throws ArgumentException  | 
            ||
| 882 | * @throws CSRException  | 
            ||
| 883 | * @throws RequestException  | 
            ||
| 884 | * @throws UnknownApiException  | 
            ||
| 885 | * @throws UnknownException  | 
            ||
| 886 | */  | 
            ||
| 887 | protected function sendBooleanRequest($url, array $params, $type)  | 
            ||
| 904 | }  | 
            ||
| 905 | 
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.