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 main_controller 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 main_controller, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 15 | class main_controller  | 
            ||
| 16 | { | 
            ||
| 17 | protected $auth;  | 
            ||
| 18 | protected $config;  | 
            ||
| 19 | protected $container;  | 
            ||
| 20 | protected $extension_manager;  | 
            ||
| 21 | protected $helper;  | 
            ||
| 22 | protected $ppde_entity_currency;  | 
            ||
| 23 | protected $ppde_entity_donation_pages;  | 
            ||
| 24 | protected $ppde_entity_transactions;  | 
            ||
| 25 | protected $ppde_operator_currency;  | 
            ||
| 26 | protected $ppde_operator_donation_pages;  | 
            ||
| 27 | protected $ppde_operator_transactions;  | 
            ||
| 28 | protected $request;  | 
            ||
| 29 | protected $template;  | 
            ||
| 30 | protected $user;  | 
            ||
| 31 | protected $root_path;  | 
            ||
| 32 | protected $php_ext;  | 
            ||
| 33 | /** @var array */  | 
            ||
| 34 | protected $ext_meta = array();  | 
            ||
| 35 | /** @var string */  | 
            ||
| 36 | protected $ext_name;  | 
            ||
| 37 | /** @var string */  | 
            ||
| 38 | private $donation_body;  | 
            ||
| 39 | /** @var array */  | 
            ||
| 40 | private $donation_content_data;  | 
            ||
| 41 | /** @var string */  | 
            ||
| 42 | private $return_args_url;  | 
            ||
| 43 | /** @var string */  | 
            ||
| 44 | private $u_action;  | 
            ||
| 45 | |||
| 46 | /**  | 
            ||
| 47 | * Constructor  | 
            ||
| 48 | *  | 
            ||
| 49 | * @param \phpbb\auth\auth $auth Auth object  | 
            ||
| 50 | * @param \phpbb\config\config $config Config object  | 
            ||
| 51 | * @param ContainerInterface $container Service container interface  | 
            ||
| 52 | * @param \phpbb\extension\manager $extension_manager An instance of the phpBB extension  | 
            ||
| 53 | * manager  | 
            ||
| 54 | * @param \phpbb\controller\helper $helper Controller helper object  | 
            ||
| 55 | * @param \skouat\ppde\entity\currency $ppde_entity_currency Currency entity object  | 
            ||
| 56 | * @param \skouat\ppde\entity\donation_pages $ppde_entity_donation_pages Donation pages entity object  | 
            ||
| 57 | * @param \skouat\ppde\entity\transactions $ppde_entity_transactions Transactions log entity object  | 
            ||
| 58 | * @param \skouat\ppde\operators\currency $ppde_operator_currency Currency operator object  | 
            ||
| 59 | * @param \skouat\ppde\operators\donation_pages $ppde_operator_donation_pages Donation pages operator object  | 
            ||
| 60 | * @param \skouat\ppde\operators\transactions $ppde_operator_transactions Transactions log operator object  | 
            ||
| 61 | * @param \phpbb\request\request $request Request object  | 
            ||
| 62 | * @param \phpbb\template\template $template Template object  | 
            ||
| 63 | * @param \phpbb\user $user User object  | 
            ||
| 64 | * @param string $root_path phpBB root path  | 
            ||
| 65 | * @param string $php_ext phpEx  | 
            ||
| 66 | *  | 
            ||
| 67 | * @return \skouat\ppde\controller\main_controller  | 
            ||
| 68 | * @access public  | 
            ||
| 69 | */  | 
            ||
| 70 | public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, ContainerInterface $container, \phpbb\extension\manager $extension_manager, \phpbb\controller\helper $helper, \skouat\ppde\entity\currency $ppde_entity_currency, \skouat\ppde\entity\donation_pages $ppde_entity_donation_pages, \skouat\ppde\entity\transactions $ppde_entity_transactions, \skouat\ppde\operators\currency $ppde_operator_currency, \skouat\ppde\operators\donation_pages $ppde_operator_donation_pages, \skouat\ppde\operators\transactions $ppde_operator_transactions, \phpbb\request\request $request, \phpbb\template\template $template, \phpbb\user $user, $root_path, $php_ext)  | 
            ||
| 89 | |||
| 90 | public function handle()  | 
            ||
| 136 | |||
| 137 | public function donorlist_handle()  | 
            ||
| 262 | |||
| 263 | /**  | 
            ||
| 264 | * @return bool  | 
            ||
| 265 | * @access public  | 
            ||
| 266 | */  | 
            ||
| 267 | public function can_use_ppde()  | 
            ||
| 271 | |||
| 272 | /**  | 
            ||
| 273 | * @return bool  | 
            ||
| 274 | * @access public  | 
            ||
| 275 | */  | 
            ||
| 276 | public function can_view_ppde_donorlist()  | 
            ||
| 280 | |||
| 281 | /**  | 
            ||
| 282 | * @param string $set_return_args_url  | 
            ||
| 283 | *  | 
            ||
| 284 | * @return null  | 
            ||
| 285 | * @access private  | 
            ||
| 286 | */  | 
            ||
| 287 | private function set_return_args_url($set_return_args_url)  | 
            ||
| 309 | |||
| 310 | /**  | 
            ||
| 311 | * Get content of current donation pages  | 
            ||
| 312 | *  | 
            ||
| 313 | * @param string $return_args_url  | 
            ||
| 314 | *  | 
            ||
| 315 | * @return array  | 
            ||
| 316 | * @access private  | 
            ||
| 317 | */  | 
            ||
| 318 | private function get_donation_content_data($return_args_url)  | 
            ||
| 324 | |||
| 325 | /**  | 
            ||
| 326 | * Build pull down menu options of available currency  | 
            ||
| 327 | *  | 
            ||
| 328 | * @param int $config_value Currency identifier; default: 0  | 
            ||
| 329 | *  | 
            ||
| 330 | * @return null  | 
            ||
| 331 | * @access public  | 
            ||
| 332 | */  | 
            ||
| 333 | public function build_currency_select_menu($config_value = 0)  | 
            ||
| 353 | |||
| 354 | /**  | 
            ||
| 355 | * Build pull down menu options of available currency value  | 
            ||
| 356 | *  | 
            ||
| 357 | * @return string List of currency value set in ACP for dropdown menu  | 
            ||
| 358 | * @access private  | 
            ||
| 359 | */  | 
            ||
| 360 | private function build_currency_value_select_menu()  | 
            ||
| 378 | |||
| 379 | /**  | 
            ||
| 380 | * Get dropbox config value  | 
            ||
| 381 | *  | 
            ||
| 382 | * @return bool  | 
            ||
| 383 | * @access private  | 
            ||
| 384 | */  | 
            ||
| 385 | private function get_dropbox_status()  | 
            ||
| 389 | |||
| 390 | /**  | 
            ||
| 391 | * Force dropbox value to integer  | 
            ||
| 392 | *  | 
            ||
| 393 | * @param int $value  | 
            ||
| 394 | *  | 
            ||
| 395 | * @return int  | 
            ||
| 396 | */  | 
            ||
| 397 | private function settype_dropbox_int_value($value = 0)  | 
            ||
| 406 | |||
| 407 | /**  | 
            ||
| 408 | * Build PayPal hidden fields  | 
            ||
| 409 | *  | 
            ||
| 410 | * @return string PayPal hidden field needed to fill PayPal forms  | 
            ||
| 411 | * @access private  | 
            ||
| 412 | */  | 
            ||
| 413 | private function paypal_hidden_fields()  | 
            ||
| 429 | |||
| 430 | /**  | 
            ||
| 431 | * Get PayPal account id  | 
            ||
| 432 | *  | 
            ||
| 433 | * @return string $this Paypal account Identifier  | 
            ||
| 434 | * @access private  | 
            ||
| 435 | */  | 
            ||
| 436 | private function get_account_id()  | 
            ||
| 440 | |||
| 441 | /**  | 
            ||
| 442 | * Check if Sandbox is enabled  | 
            ||
| 443 | *  | 
            ||
| 444 | * @return bool  | 
            ||
| 445 | * @access public  | 
            ||
| 446 | */  | 
            ||
| 447 | public function use_sandbox()  | 
            ||
| 451 | |||
| 452 | /**  | 
            ||
| 453 | * Check if IPN is enabled  | 
            ||
| 454 | *  | 
            ||
| 455 | * @return bool  | 
            ||
| 456 | * @access public  | 
            ||
| 457 | */  | 
            ||
| 458 | public function use_ipn()  | 
            ||
| 462 | |||
| 463 | /**  | 
            ||
| 464 | * Generate PayPal return URL  | 
            ||
| 465 | *  | 
            ||
| 466 | * @param string $arg  | 
            ||
| 467 | *  | 
            ||
| 468 | * @return string  | 
            ||
| 469 | * @access private  | 
            ||
| 470 | */  | 
            ||
| 471 | private function generate_paypal_return_url($arg)  | 
            ||
| 475 | |||
| 476 | /**  | 
            ||
| 477 | * Generate PayPal return notify URL  | 
            ||
| 478 | *  | 
            ||
| 479 | * @return string  | 
            ||
| 480 | * @access private  | 
            ||
| 481 | */  | 
            ||
| 482 | private function generate_paypal_notify_return_url()  | 
            ||
| 486 | |||
| 487 | /**  | 
            ||
| 488 | * Get PayPal URL  | 
            ||
| 489 | * Used in form and in IPN process  | 
            ||
| 490 | *  | 
            ||
| 491 | * @param bool $is_test_ipn  | 
            ||
| 492 | *  | 
            ||
| 493 | * @return string  | 
            ||
| 494 | * @access public  | 
            ||
| 495 | */  | 
            ||
| 496 | public function get_paypal_url($is_test_ipn = false)  | 
            ||
| 500 | |||
| 501 | /**  | 
            ||
| 502 | * Assign statistics vars to the template  | 
            ||
| 503 | *  | 
            ||
| 504 | * @return null  | 
            ||
| 505 | * @access public  | 
            ||
| 506 | */  | 
            ||
| 507 | public function display_stats()  | 
            ||
| 528 | |||
| 529 | /**  | 
            ||
| 530 | * Get default currency symbol  | 
            ||
| 531 | *  | 
            ||
| 532 | * @param int $id  | 
            ||
| 533 | *  | 
            ||
| 534 | * @return array  | 
            ||
| 535 | * @access public  | 
            ||
| 536 | */  | 
            ||
| 537 | public function get_default_currency_data($id = 0)  | 
            ||
| 541 | |||
| 542 | /**  | 
            ||
| 543 | * Retrieve the language key for donation goal  | 
            ||
| 544 | *  | 
            ||
| 545 | * @param string $currency_symbol Currency symbol  | 
            ||
| 546 | * @param bool $on_left Symbol position  | 
            ||
| 547 | *  | 
            ||
| 548 | * @return string  | 
            ||
| 549 | * @access public  | 
            ||
| 550 | */  | 
            ||
| 551 | public function get_ppde_goal_langkey($currency_symbol, $on_left = true)  | 
            ||
| 568 | |||
| 569 | /**  | 
            ||
| 570 | * Put the currency on the left or on the right of the amount  | 
            ||
| 571 | *  | 
            ||
| 572 | * @param int $value  | 
            ||
| 573 | * @param string $currency  | 
            ||
| 574 | * @param bool $on_left  | 
            ||
| 575 | *  | 
            ||
| 576 | * @return string  | 
            ||
| 577 | */  | 
            ||
| 578 | private function get_amount($value, $currency, $on_left = true)  | 
            ||
| 582 | |||
| 583 | /**  | 
            ||
| 584 | * Retrieve the language key for donation raised  | 
            ||
| 585 | *  | 
            ||
| 586 | * @param string $currency_symbol Currency symbol  | 
            ||
| 587 | * @param bool $on_left Symbol position  | 
            ||
| 588 | *  | 
            ||
| 589 | * @return string  | 
            ||
| 590 | * @access public  | 
            ||
| 591 | */  | 
            ||
| 592 | public function get_ppde_raised_langkey($currency_symbol, $on_left = true)  | 
            ||
| 605 | |||
| 606 | /**  | 
            ||
| 607 | * Retrieve the language key for donation used  | 
            ||
| 608 | *  | 
            ||
| 609 | * @param string $currency_symbol Currency symbol  | 
            ||
| 610 | * @param bool $on_left Symbol position  | 
            ||
| 611 | *  | 
            ||
| 612 | * @return string  | 
            ||
| 613 | * @access public  | 
            ||
| 614 | */  | 
            ||
| 615 | public function get_ppde_used_langkey($currency_symbol, $on_left = true)  | 
            ||
| 632 | |||
| 633 | /**  | 
            ||
| 634 | * Generate statistics percent for display  | 
            ||
| 635 | *  | 
            ||
| 636 | * @return null  | 
            ||
| 637 | * @access private  | 
            ||
| 638 | */  | 
            ||
| 639 | private function generate_stats_percent()  | 
            ||
| 651 | |||
| 652 | /**  | 
            ||
| 653 | * Assign statistics percent vars to template  | 
            ||
| 654 | *  | 
            ||
| 655 | * @param integer $multiplicand  | 
            ||
| 656 | * @param integer $dividend  | 
            ||
| 657 | * @param string $type  | 
            ||
| 658 | *  | 
            ||
| 659 | * @return null  | 
            ||
| 660 | * @access public  | 
            ||
| 661 | */  | 
            ||
| 662 | private function assign_vars_stats_percent($multiplicand, $dividend, $type = '')  | 
            ||
| 669 | |||
| 670 | /**  | 
            ||
| 671 | * Send data to the template file  | 
            ||
| 672 | *  | 
            ||
| 673 | * @return \Symfony\Component\HttpFoundation\Response  | 
            ||
| 674 | * @access private  | 
            ||
| 675 | */  | 
            ||
| 676 | private function send_data_to_template()  | 
            ||
| 689 | |||
| 690 | /**  | 
            ||
| 691 | * Check if cURL is available  | 
            ||
| 692 | *  | 
            ||
| 693 | * @return bool  | 
            ||
| 694 | * @access public  | 
            ||
| 695 | */  | 
            ||
| 696 | public function check_curl()  | 
            ||
| 716 | |||
| 717 | /**  | 
            ||
| 718 | * Get extension metadata  | 
            ||
| 719 | *  | 
            ||
| 720 | * @return null  | 
            ||
| 721 | * @access protected  | 
            ||
| 722 | */  | 
            ||
| 723 | protected function get_ext_meta()  | 
            ||
| 730 | |||
| 731 | /**  | 
            ||
| 732 | * Load metadata for this extension  | 
            ||
| 733 | *  | 
            ||
| 734 | * @return array  | 
            ||
| 735 | * @access public  | 
            ||
| 736 | */  | 
            ||
| 737 | public function load_metadata()  | 
            ||
| 759 | |||
| 760 | /**  | 
            ||
| 761 | * Retrieve the extension name  | 
            ||
| 762 | *  | 
            ||
| 763 | * @return null  | 
            ||
| 764 | * @access protected  | 
            ||
| 765 | */  | 
            ||
| 766 | protected function retrieve_ext_name()  | 
            ||
| 771 | |||
| 772 | /**  | 
            ||
| 773 | * Check if fsockopen is available  | 
            ||
| 774 | *  | 
            ||
| 775 | * @return bool  | 
            ||
| 776 | * @access public  | 
            ||
| 777 | */  | 
            ||
| 778 | public function check_fsockopen()  | 
            ||
| 793 | }  | 
            ||
| 794 | 
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: