tableBlock::tableBlock()   F
last analyzed

Complexity

Conditions 27
Paths 1032

Size

Total Lines 57
Code Lines 41

Duplication

Lines 5
Ratio 8.77 %

Importance

Changes 0
Metric Value
cc 27
eloc 41
nc 1032
nop 1
dl 5
loc 57
rs 3.417
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
/**
3
  * osCommerce Online Merchant
4
  *
5
  * @copyright (c) 2016 osCommerce; https://www.oscommerce.com
6
  * @license MIT; https://www.oscommerce.com/license/mit.txt
7
  */
8
9
  class tableBlock {
10
    var $table_border = '0';
11
    var $table_width = '100%';
12
    var $table_cellspacing = '0';
13
    var $table_cellpadding = '2';
14
    var $table_parameters = '';
15
    var $table_row_parameters = '';
16
    var $table_data_parameters = '';
17
18
    function tableBlock($contents) {
19
      $tableBox_string = '';
20
21
      $form_set = false;
22
      if (isset($contents['form'])) {
23
        $tableBox_string .= $contents['form'] . "\n";
24
        $form_set = true;
25
        array_shift($contents);
26
      }
27
28
      $tableBox_string .= '<table border="' . $this->table_border . '" width="' . $this->table_width . '" cellspacing="' . $this->table_cellspacing . '" cellpadding="' . $this->table_cellpadding . '"';
29
      if (tep_not_null($this->table_parameters)) $tableBox_string .= ' ' . $this->table_parameters;
30
      $tableBox_string .= '>' . "\n";
31
32
      for ($i=0, $n=sizeof($contents); $i<$n; $i++) {
33
        $tableBox_string .= '  <tr';
34
        if (tep_not_null($this->table_row_parameters)) $tableBox_string .= ' ' . $this->table_row_parameters;
35 View Code Duplication
        if (isset($contents[$i]['params']) && tep_not_null($contents[$i]['params'])) $tableBox_string .= ' ' . $contents[$i]['params'];
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...
36
        $tableBox_string .= '>' . "\n";
37
38
        if (isset($contents[$i][0]) && is_array($contents[$i][0])) {
39
          for ($x=0, $y=sizeof($contents[$i]); $x<$y; $x++) {
40
            if (isset($contents[$i][$x]['text']) && tep_not_null($contents[$i][$x]['text'])) {
41
              $tableBox_string .= '    <td';
42 View Code Duplication
              if (isset($contents[$i][$x]['align']) && tep_not_null($contents[$i][$x]['align'])) $tableBox_string .= ' align="' . $contents[$i][$x]['align'] . '"';
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...
43
              if (isset($contents[$i][$x]['params']) && tep_not_null($contents[$i][$x]['params'])) {
44
                $tableBox_string .= ' ' . $contents[$i][$x]['params'];
45
              } elseif (tep_not_null($this->table_data_parameters)) {
46
                $tableBox_string .= ' ' . $this->table_data_parameters;
47
              }
48
              $tableBox_string .= '>';
49 View Code Duplication
              if (isset($contents[$i][$x]['form']) && tep_not_null($contents[$i][$x]['form'])) $tableBox_string .= $contents[$i][$x]['form'];
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...
50
              $tableBox_string .= $contents[$i][$x]['text'];
51 View Code Duplication
              if (isset($contents[$i][$x]['form']) && tep_not_null($contents[$i][$x]['form'])) $tableBox_string .= '</form>';
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...
52
              $tableBox_string .= '</td>' . "\n";
53
            }
54
          }
55
        } else {
56
          $tableBox_string .= '    <td';
57 View Code Duplication
          if (isset($contents[$i]['align']) && tep_not_null($contents[$i]['align'])) $tableBox_string .= ' align="' . $contents[$i]['align'] . '"';
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...
58
          if (isset($contents[$i]['params']) && tep_not_null($contents[$i]['params'])) {
59
            $tableBox_string .= ' ' . $contents[$i]['params'];
60
          } elseif (tep_not_null($this->table_data_parameters)) {
61
            $tableBox_string .= ' ' . $this->table_data_parameters;
62
          }
63
          $tableBox_string .= '>' . $contents[$i]['text'] . '</td>' . "\n";
64
        }
65
66
        $tableBox_string .= '  </tr>' . "\n";
67
      }
68
69
      $tableBox_string .= '</table>' . "\n";
70
71
      if ($form_set == true) $tableBox_string .= '</form>' . "\n";
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
72
73
      return $tableBox_string;
74
    }
75
  }
76
?>
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...
77