Completed
Push — 23 ( 09d773...16ee8e )
by Harald
11s
created

cm_account_braintree_cards   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 96
Duplicated Lines 4.17 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 4
loc 96
rs 10
c 0
b 0
f 0
wmc 20
lcom 1
cbo 2

7 Methods

Rating   Name   Duplication   Size   Complexity  
C cm_account_braintree_cards() 4 51 13
A execute() 0 7 1
A isEnabled() 0 3 1
A check() 0 10 2
A install() 0 3 1
A remove() 0 3 1
A keys() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

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:

1
<?php
2
/*
3
  $Id$
4
5
  osCommerce, Open Source E-Commerce Solutions
6
  http://www.oscommerce.com
7
8
  Copyright (c) 2014 osCommerce
9
10
  Released under the GNU General Public License
11
*/
12
13
  if ( !class_exists('OSCOM_Braintree') ) {
14
    include(DIR_FS_CATALOG . 'includes/apps/braintree/OSCOM_Braintree.php');
15
  }
16
17
  class cm_account_braintree_cards {
18
    var $code;
19
    var $group;
20
    var $title;
21
    var $description;
22
    var $sort_order;
23
    var $enabled = false;
24
    var $_app;
25
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');
0 ignored issues
show
Bug introduced by
The property public_title does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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' ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
78
    function execute() {
79
      global $oscTemplate;
80
81
      $oscTemplate->_data['account']['account']['links']['braintree_cards'] = array('title' => $this->public_title,
82
                                                                                    'link' => tep_href_link('ext/modules/content/account/braintree/cards.php', '', 'SSL'),
83
                                                                                    'icon' => 'newwin');
84
    }
85
86
    function isEnabled() {
87
      return $this->enabled;
88
    }
89
90
    function check() {
91
      $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'OSCOM_APP_PAYPAL_BRAINTREE_CC_STATUS'");
92
      if ( tep_db_num_rows($check_query) ) {
93
        $check = tep_db_fetch_array($check_query);
94
95
        return tep_not_null($check['configuration_value']);
96
      }
97
98
      return false;
99
    }
100
101
    function install() {
102
      tep_redirect(tep_href_link('braintree.php', 'action=configure'));
103
    }
104
105
    function remove() {
106
      tep_redirect(tep_href_link('braintree.php', 'action=configure'));
107
    }
108
109
    function keys() {
110
      return array('MODULE_CONTENT_ACCOUNT_BRAINTREE_CARDS_SORT_ORDER');
111
    }
112
  }
113
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
114