customer.php ➔ editEquipmentCustomer()   B
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 30
Code Lines 23

Duplication

Lines 30
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
eloc 23
nc 6
nop 1
dl 30
loc 30
rs 8.5806
c 0
b 0
f 0
1
<?php
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
*/
12
/**
13
 * Module: Equipment
14
 *
15
 * @category        Module
16
 * @package         equipment
17
 * @author          XOOPS Development Team <[email protected]> - <http://xoops.org>
18
 * @copyright       {@link https://xoops.org/ XOOPS Project}
19
 * @license         GPL 2.0 or later
20
 * @link            https://xoops.org/
21
 * @since           1.0.0
22
 */
23
24
require_once dirname(__DIR__) . '/class/utility.php';
25
/**
26
 * @param $options
27
 *
28
 * @return array
29
 */
30
function showEquipmentCustomer($options)
31
{
32
    require_once dirname(__DIR__) . '/class/customer.php';
33
    $moduleDirName = basename(dirname(__DIR__));
34
    //$myts = MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
35
36
    $block         = array();
37
    $blockType     = $options[0];
38
    $customerCount = $options[1];
39
    //$titleLenght = $options[2];
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
40
41
    /** @var XoopsObjectHandler $customerHandler */
42
    $customerHandler = xoops_getModuleHandler('customer', $moduleDirName);
43
    $criteria        = new CriteriaCompo();
44
    array_shift($options);
45
    array_shift($options);
46
    array_shift($options);
47
    if ($blockType) {
48
        $criteria->add(new Criteria('id', 0, '!='));
49
        $criteria->setSort('id');
50
        $criteria->setOrder('ASC');
51
    }
52
53
    $criteria->setLimit($customerCount);
54
    $customerArray = $customerHandler->getAll($criteria);
55
    foreach (array_keys($customerArray) as $i) {
0 ignored issues
show
Unused Code introduced by
This foreach statement is empty and can be removed.

This check looks for foreach loops that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

Consider removing the loop.

Loading history...
56
    }
57
58
    return $block;
59
}
60
61
/**
62
 * @param $options
63
 *
64
 * @return string
65
 */
66 View Code Duplication
function editEquipmentCustomer($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...
67
{
68
    require_once dirname(__DIR__) . '/class/customer.php';
69
    $moduleDirName = basename(dirname(__DIR__));
70
71
    $form = MB_EQUIPMENT_DISPLAY;
72
    $form .= "<input type='hidden' name='options[0]' value='" . $options[0] . "' />";
73
    $form .= "<input name='options[1]' size='5' maxlength='255' value='" . $options[1] . "' type='text' />&nbsp;<br>";
74
    $form .= MB_EQUIPMENT_TITLELENGTH . " : <input name='options[2]' size='5' maxlength='255' value='" . $options[2] . "' type='text' /><br><br>";
75
76
    /** @var XoopsObjectHandler $'. customer . 'Handler */
77
    $customerHandler = xoops_getModuleHandler('customer', $moduleDirName);
78
    $criteria        = new CriteriaCompo();
79
    array_shift($options);
80
    array_shift($options);
81
    array_shift($options);
82
    $criteria->add(new Criteria('id', 0, '!='));
83
    $criteria->setSort('id');
84
    $criteria->setOrder('ASC');
85
    $customerArray = $customerHandler->getAll($criteria);
86
    $form          .= MB_EQUIPMENT_CATTODISPLAY . "<br><select name='options[]' multiple='multiple' size='5'>";
87
    $form          .= "<option value='0' " . (in_array(0, $options) === false ? '' : "selected='selected'") . '>' . MB_EQUIPMENT_ALLCAT . '</option>';
88
    foreach (array_keys($customerArray) as $i) {
89
        $id   = $customerArray[$i]->getVar('id');
90
        $form .= "<option value='" . $id . "' " . (in_array($id, $options) === false ? '' : "selected='selected'") . '>' . $customerArray[$i]->getVar('last') . '</option>';
91
    }
92
    $form .= '</select>';
93
94
    return $form;
95
}
96