Completed
Push — master ( 9d3fbd...af269e )
by Michael
09:48
created

oledrion_top.php ➔ b_oledrion_top_edit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 16

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 1
dl 21
loc 21
rs 9.3142
c 0
b 0
f 0
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * oledrion
14
 *
15
 * @copyright   {@link https://xoops.org/ XOOPS Project}
16
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
17
 * @author      Hervé Thouzard (http://www.herve-thouzard.com/)
18
 */
19
/**
20
 * Affiche les produits les plus vus
21
 * @param $options
22
 * @return array|bool
23
 */
24 View Code Duplication
function b_oledrion_top_show($options)
0 ignored issues
show
Duplication introduced by
This function 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...
25
{
26
    // '10|0';  // Voir 10 produits, pour toutes les catégories ou une catégorie particulière
27
    global $xoopsConfig, $xoTheme;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
28
    include XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php';
29
    $products   = $block = array();
0 ignored issues
show
Unused Code introduced by
$products is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
30
    $start      = 0;
31
    $limit      = $options[0];
32
    $categoyrId = $options[1];
33
    $oledrion_shelf_parameters->resetDefaultValues()->setProductsType('mostviewed')->setStart($start)->setLimit($limit)->setSort('product_hits')->setOrder('DESC')->setCategory($categoyrId);
0 ignored issues
show
Bug introduced by
The variable $oledrion_shelf_parameters does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
34
    $products = $oledrion_shelf->getProducts($oledrion_shelf_parameters);
0 ignored issues
show
Bug introduced by
The variable $oledrion_shelf does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
35
    if (isset($products['lastTitle'])) {
36
        unset($products['lastTitle']);
37
    }
38
    if (count($products) > 0) {
39
        $block['nostock_msg']    = OledrionUtility::getModuleOption('nostock_msg');
40
        $block['block_products'] = $products;
41
        $xoTheme->addStylesheet(OLEDRION_URL . 'assets/css/oledrion.css');
42
43
        return $block;
44
    } else { // La liste des produits est introuvable (on ne trouve pas les produits vendus dans le stock des produits)
45
46
        return false;
47
    }
48
}
49
50
/**
51
 * Paramètres du bloc
52
 * @param $options
53
 * @return string
54
 */
55 View Code Duplication
function b_oledrion_top_edit($options)
0 ignored issues
show
Duplication introduced by
This function 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...
56
{
57
    // '10|0';  // Voir 10 produits, pour toutes les catégories
58
    global $xoopsConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
59
    include XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php';
60
    require_once OLEDRION_PATH . 'class/tree.php';
61
    $tblCategories         = array();
0 ignored issues
show
Unused Code introduced by
$tblCategories is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
62
    $tblCategories         = $h_oledrion_cat->getAllCategories(new Oledrion_parameters());
0 ignored issues
show
Bug introduced by
The variable $h_oledrion_cat does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
63
    $mytree                = new Oledrion_XoopsObjectTree($tblCategories, 'cat_cid', 'cat_pid');
64
    $form                  = '';
65
    $checkeds              = array('', '');
66
    $checkeds[$options[1]] = 'checked';
67
    $form                  .= "<table border='0'>";
68
    $form                  .= '<tr><td>' . _MB_OLEDRION_PRODUCTS_CNT . "</td><td><input type='text' name='options[]' id='options' value='" . $options[0] . "'></td></tr>";
69
    //$form .= '<tr><td>'._MB_OLEDRION_SORT_ORDER."</td><td><input type='radio' name='options[]' id='options[]' value='0' ".$checkeds[0].">"._MB_OLEDRION_SORT_1." <input type='radio' name='options[]' id='options[]' value='1' ".$checkeds[1].">"._MB_OLEDRION_SORT_2.'</td></tr>';
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
70
    $select = $mytree->makeSelBox('options[]', 'cat_title', '-', $options[1], _MB_OLEDRION_ALL_CATEGORIES);
0 ignored issues
show
Deprecated Code introduced by
The method Oledrion_XoopsObjectTree::makeSelBox() has been deprecated with message: since 2.5.9, please use makeSelectElement()

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
71
    $form   .= '<tr><td>' . _MB_OLEDRION_CATEGORY . '</td><td>' . $select . '</td></tr>';
72
    $form   .= '</table>';
73
74
    return $form;
75
}
76
77
/**
78
 * Bloc à la volée
79
 * @param $options
80
 */
81 View Code Duplication
function b_oledrion_top_show_duplicatable($options)
0 ignored issues
show
Duplication introduced by
This function 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...
82
{
83
    $options = explode('|', $options);
84
    $block   = b_oledrion_top_show($options);
85
86
    $tpl = new XoopsTpl();
87
    $tpl->assign('block', $block);
88
    $tpl->display('db:oledrion_block_top.tpl');
89
}
90