Completed
Push — master ( 85914a...2ce878 )
by Harald
06:39 queued 03:01
created

bm_languages   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 98
Duplicated Lines 13.27 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 13
loc 98
rs 10
c 0
b 0
f 0
wmc 12
lcom 1
cbo 3

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 13 13 3
A execute() 0 21 4
A isEnabled() 0 3 1
A check() 0 3 1
B install() 0 35 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) 2015 osCommerce
9
10
  Released under the GNU General Public License
11
*/
12
13
  use OSC\OM\HTML;
14
  use OSC\OM\OSCOM;
15
  use OSC\OM\Registry;
16
17
  class bm_languages {
18
    var $code = 'bm_languages';
19
    var $group = 'boxes';
20
    var $title;
21
    var $description;
22
    var $sort_order;
23
    var $enabled = false;
24
25
    protected $lang;
26
27 View Code Duplication
    function __construct() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
28
      $this->lang = Registry::get('Language');
29
30
      $this->title = MODULE_BOXES_LANGUAGES_TITLE;
31
      $this->description = MODULE_BOXES_LANGUAGES_DESCRIPTION;
32
33
      if ( defined('MODULE_BOXES_LANGUAGES_STATUS') ) {
34
        $this->sort_order = MODULE_BOXES_LANGUAGES_SORT_ORDER;
35
        $this->enabled = (MODULE_BOXES_LANGUAGES_STATUS == 'True');
36
37
        $this->group = ((MODULE_BOXES_LANGUAGES_CONTENT_PLACEMENT == 'Left Column') ? 'boxes_column_left' : 'boxes_column_right');
38
      }
39
    }
40
41
    function execute() {
42
      global $PHP_SELF, $oscTemplate;
43
44
      if (substr(basename($PHP_SELF), 0, 8) != 'checkout') {
45
        $languages = $this->lang->getAll();
46
47
        if (count($languages) > 1) {
48
          $languages_string = '';
49
50
          foreach ($languages as $code => $value) {
51
            $languages_string .= ' <a href="' . OSCOM::link($PHP_SELF, tep_get_all_get_params(array('language', 'currency')) . 'language=' . $code) . '">' . HTML::image('includes/languages/' . $value['directory'] . '/images/' . $value['image'], $value['name'], NULL, NULL, NULL, false) . '</a> ';
0 ignored issues
show
Documentation introduced by
array('language', 'currency') is of type array<integer,string,{"0":"string","1":"string"}>, but the function expects a string.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
52
          }
53
54
          ob_start();
55
          include('includes/modules/boxes/templates/languages.php');
56
          $data = ob_get_clean();
57
58
          $oscTemplate->addBlock($data, $this->group);
59
        }
60
      }
61
    }
62
63
    function isEnabled() {
64
      return $this->enabled;
65
    }
66
67
    function check() {
68
      return defined('MODULE_BOXES_LANGUAGES_STATUS');
69
    }
70
71
    function install() {
72
      $OSCOM_Db = Registry::get('Db');
73
74
      $OSCOM_Db->save('configuration', [
75
        'configuration_title' => 'Enable Languages Module',
76
        'configuration_key' => 'MODULE_BOXES_LANGUAGES_STATUS',
77
        'configuration_value' => 'True',
78
        'configuration_description' => 'Do you want to add the module to your shop?',
79
        'configuration_group_id' => '6',
80
        'sort_order' => '1',
81
        'set_function' => 'tep_cfg_select_option(array(\'True\', \'False\'), ',
82
        'date_added' => 'now()'
83
      ]);
84
85
      $OSCOM_Db->save('configuration', [
86
        'configuration_title' => 'Content Placement',
87
        'configuration_key' => 'MODULE_BOXES_LANGUAGES_CONTENT_PLACEMENT',
88
        'configuration_value' => 'Right Column',
89
        'configuration_description' => 'Should the module be loaded in the left or right column?',
90
        'configuration_group_id' => '6',
91
        'sort_order' => '1',
92
        'set_function' => 'tep_cfg_select_option(array(\'Left Column\', \'Right Column\'), ',
93
        'date_added' => 'now()'
94
      ]);
95
96
      $OSCOM_Db->save('configuration', [
97
        'configuration_title' => 'Sort Order',
98
        'configuration_key' => 'MODULE_BOXES_LANGUAGES_SORT_ORDER',
99
        'configuration_value' => '0',
100
        'configuration_description' => 'Sort order of display. Lowest is displayed first.',
101
        'configuration_group_id' => '6',
102
        'sort_order' => '0',
103
        'date_added' => 'now()'
104
      ]);
105
    }
106
107
    function remove() {
108
      return Registry::get('Db')->exec('delete from :table_configuration where configuration_key in ("' . implode('", "', $this->keys()) . '")');
109
    }
110
111
    function keys() {
112
      return array('MODULE_BOXES_LANGUAGES_STATUS', 'MODULE_BOXES_LANGUAGES_CONTENT_PLACEMENT', 'MODULE_BOXES_LANGUAGES_SORT_ORDER');
113
    }
114
  }
115
116