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

sb_google_plus_one   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 143
Duplicated Lines 55.24 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 79
loc 143
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 3

9 Methods

Rating   Name   Duplication   Size   Complexity  
B getOutput() 0 27 2
A isEnabled() 0 3 1
A getIcon() 0 3 1
A getPublicTitle() 0 3 1
A check() 0 3 1
A install() 67 67 1
A remove() 0 3 1
A keys() 0 3 1
A __construct() 12 12 2

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 sb_google_plus_one {
18
    var $code = 'sb_google_plus_one';
19
    var $title;
20
    var $description;
21
    var $sort_order;
22
    var $icon;
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_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_TITLE;
31
      $this->public_title = MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_PUBLIC_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...
32
      $this->description = MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_DESCRIPTION;
33
34
      if ( defined('MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_STATUS') ) {
35
        $this->sort_order = MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_SORT_ORDER;
36
        $this->enabled = (MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_STATUS == 'True');
37
      }
38
    }
39
40
    function getOutput() {
41
      $output = '<div class="g-plusone" data-href="' . OSCOM::link('product_info.php', 'products_id=' . $_GET['products_id'], false) . '" data-size="' . strtolower(MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_SIZE) . '" data-annotation="' . strtolower(MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_ANNOTATION) . '"';
42
43
      if (MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_ANNOTATION == 'Inline') {
44
        $output.= ' data-width="' . (int)MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_WIDTH . '" data-align="' . strtolower(MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_ALIGN) . '"';
45
      }
46
47
      $output .= '></div>';
48
49
      $output .= '<script>
50
  if ( typeof window.___gcfg == "undefined" ) {
51
    window.___gcfg = { };
52
  }
53
54
  if ( typeof window.___gcfg.lang == "undefined" ) {
55
    window.___gcfg.lang = "' . HTML::outputProtected($this->lang->get('code')) . '";
56
  }
57
58
  (function() {
59
    var po = document.createElement(\'script\'); po.type = \'text/javascript\'; po.async = true;
60
    po.src = \'https://apis.google.com/js/plusone.js\';
61
    var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(po, s);
62
  })();
63
</script>';
64
65
      return $output;
66
    }
67
68
    function isEnabled() {
69
      return $this->enabled;
70
    }
71
72
    function getIcon() {
73
      return $this->icon;
74
    }
75
76
    function getPublicTitle() {
77
      return $this->public_title;
78
    }
79
80
    function check() {
81
      return defined('MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_STATUS');
82
    }
83
84 View Code Duplication
    function install() {
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...
85
      $OSCOM_Db = Registry::get('Db');
86
87
      $OSCOM_Db->save('configuration', [
88
        'configuration_title' => 'Enable Google+ +1 Button Module',
89
        'configuration_key' => 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_STATUS',
90
        'configuration_value' => 'True',
91
        'configuration_description' => 'Do you want to allow products to be recommended through Google+ +1 Button?',
92
        'configuration_group_id' => '6',
93
        'sort_order' => '1',
94
        'set_function' => 'tep_cfg_select_option(array(\'True\', \'False\'), ',
95
        'date_added' => 'now()'
96
      ]);
97
98
      $OSCOM_Db->save('configuration', [
99
        'configuration_title' => 'Button Size',
100
        'configuration_key' => 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_SIZE',
101
        'configuration_value' => 'Small',
102
        'configuration_description' => 'Sets the size of the button.',
103
        'configuration_group_id' => '6',
104
        'sort_order' => '1',
105
        'set_function' => 'tep_cfg_select_option(array(\'Small\', \'Medium\', \'Standard\', \'Tall\'), ',
106
        'date_added' => 'now()'
107
      ]);
108
109
      $OSCOM_Db->save('configuration', [
110
        'configuration_title' => 'Annotation',
111
        'configuration_key' => 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_ANNOTATION',
112
        'configuration_value' => 'None',
113
        'configuration_description' => 'The annotation to display next to the button.',
114
        'configuration_group_id' => '6',
115
        'sort_order' => '1',
116
        'set_function' => 'tep_cfg_select_option(array(\'None\', \'Bubble\', \'Inline\'), ',
117
        'date_added' => 'now()'
118
      ]);
119
120
      $OSCOM_Db->save('configuration', [
121
        'configuration_title' => 'Inline Width',
122
        'configuration_key' => 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_WIDTH',
123
        'configuration_value' => '120',
124
        'configuration_description' => 'The width of the inline annotation in pixels (minimum 120).',
125
        'configuration_group_id' => '6',
126
        'sort_order' => '1',
127
        'date_added' => 'now()'
128
      ]);
129
130
      $OSCOM_Db->save('configuration', [
131
        'configuration_title' => 'Inline Alignment',
132
        'configuration_key' => 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_ALIGN',
133
        'configuration_value' => 'Left',
134
        'configuration_description' => 'The alignment of the inline annotation.',
135
        'configuration_group_id' => '6',
136
        'sort_order' => '1',
137
        'set_function' => 'tep_cfg_select_option(array(\'Left\', \'Right\'), ',
138
        'date_added' => 'now()'
139
      ]);
140
141
      $OSCOM_Db->save('configuration', [
142
        'configuration_title' => 'Sort Order',
143
        'configuration_key' => 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_SORT_ORDER',
144
        'configuration_value' => '0',
145
        'configuration_description' => 'Sort order of display. Lowest is displayed first.',
146
        'configuration_group_id' => '6',
147
        'sort_order' => '0',
148
        'date_added' => 'now()'
149
      ]);
150
    }
151
152
    function remove() {
153
      return Registry::get('Db')->exec('delete from :table_configuration where configuration_key in ("' . implode('", "', $this->keys()) . '")');
154
    }
155
156
    function keys() {
157
      return array('MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_STATUS', 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_SIZE', 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_ANNOTATION', 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_WIDTH', 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_ALIGN', 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_ONE_SORT_ORDER');
158
    }
159
  }
160
?>
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...
161