| Conditions | 13 |
| Paths | 130 |
| Total Lines | 51 |
| Code Lines | 29 |
| Lines | 4 |
| Ratio | 7.84 % |
| 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 |
||
| 26 | function cm_account_braintree_cards() { |
||
| 27 | global $language; |
||
| 28 | |||
| 29 | $this->_app = new OSCOM_Braintree(); |
||
| 30 | $this->_app->loadLanguageFile('shop/account_cards_page.php'); |
||
| 31 | |||
| 32 | $this->code = get_class($this); |
||
| 33 | $this->group = basename(dirname(__FILE__)); |
||
| 34 | |||
| 35 | $this->title = $this->_app->getDef('account_braintree_cards_title'); |
||
| 36 | $this->description = $this->_app->getDef('account_braintree_cards_description') . '<div align="center">' . $this->_app->drawButton($this->_app->getDef('accouint_braintree_cards_legacy_admin_app_button'), tep_href_link('braintree.php', 'action=configure&module=CC'), 'primary', null, true) . '</div>'; |
||
| 37 | |||
| 38 | if ( defined('MODULE_CONTENT_ACCOUNT_BRAINTREE_CARDS_SORT_ORDER') ) { |
||
| 39 | $this->sort_order = MODULE_CONTENT_ACCOUNT_BRAINTREE_CARDS_SORT_ORDER; |
||
| 40 | $this->enabled = defined('OSCOM_APP_PAYPAL_BRAINTREE_CC_STATUS') && in_array(OSCOM_APP_PAYPAL_BRAINTREE_CC_STATUS, array('1', '0')) ? true : false; |
||
| 41 | } |
||
| 42 | |||
| 43 | $this->public_title = $this->_app->getDef('account_braintree_cards_link_title'); |
||
|
|
|||
| 44 | |||
| 45 | $braintree_enabled = false; |
||
| 46 | |||
| 47 | if ( defined('MODULE_PAYMENT_INSTALLED') && tep_not_null(MODULE_PAYMENT_INSTALLED) && in_array('braintree_cc.php', explode(';', MODULE_PAYMENT_INSTALLED)) ) { |
||
| 48 | if ( !class_exists('braintree_cc') ) { |
||
| 49 | include(DIR_FS_CATALOG . 'includes/languages/' . $language . '/modules/payment/braintree_cc.php'); |
||
| 50 | include(DIR_FS_CATALOG . 'includes/modules/payment/braintree_cc.php'); |
||
| 51 | } |
||
| 52 | |||
| 53 | $braintree_cc = new braintree_cc(); |
||
| 54 | |||
| 55 | if ( $braintree_cc->enabled ) { |
||
| 56 | if ( defined('OSCOM_APP_PAYPAL_BRAINTREE_CC_STATUS') ) { |
||
| 57 | $braintree_enabled = true; |
||
| 58 | |||
| 59 | View Code Duplication | if ( OSCOM_APP_PAYPAL_BRAINTREE_CC_STATUS == '0' ) { |
|
| 60 | $this->title .= ' [Sandbox]'; |
||
| 61 | $this->public_title .= ' (' . $braintree_cc->code . '; Sandbox)'; |
||
| 62 | } |
||
| 63 | |||
| 64 | if (OSCOM_APP_PAYPAL_BRAINTREE_CC_CC_TOKENS == '0') { |
||
| 65 | $braintree_enabled = false; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | if ( $braintree_enabled !== true ) { |
||
| 72 | $this->enabled = false; |
||
| 73 | |||
| 74 | $this->description = '<div class="secWarning">' . $this->_app->getDef('account_braintree_cards_error_main_module') . '</div>' . $this->description; |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 114 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: