Passed
Push — master ( 2744eb...81ba93 )
by Michael
02:46
created

myDeleteByModule()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 6
nop 4
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 16 and the first side effect is on line 34.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/**
4
 * Module: SmartFAQ
5
 * Author: The SmartFactory <www.smartfactory.ca>
6
 * Licence: GNU
7
 * @param       $db
8
 * @param       $gperm_modid
9
 * @param  null $gperm_name
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $gperm_name is correct as it would always require null to be passed?
Loading history...
Documentation Bug introduced by
Are you sure the doc-type for parameter $gperm_itemid is correct as it would always require null to be passed?
Loading history...
10
 * @param  null $gperm_itemid
11
 * @return bool
12
 */
13
14
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
15
16
function myDeleteByModule(\XoopsDatabase $db, $gperm_modid, $gperm_name = null, $gperm_itemid = null)
0 ignored issues
show
Bug introduced by
The type XoopsDatabase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
{
18
    $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', (int)$gperm_modid));
0 ignored issues
show
Bug introduced by
The type Criteria was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The type CriteriaCompo was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
    if (null !== $gperm_name) {
20
        $criteria->add(new \Criteria('gperm_name', $gperm_name));
21
        if (null !== $gperm_itemid) {
22
            $criteria->add(new \Criteria('gperm_itemid', (int)$gperm_itemid));
23
        }
24
    }
25
    $sql = 'DELETE FROM ' . $db->prefix('group_permission') . ' ' . $criteria->renderWhere();
26
    if (!$result = $db->query($sql)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
27
        return false;
28
    }
29
30
    return true;
31
}
32
33
// require_once __DIR__ . '/../../../include/cp_header.php'; GIJ
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% 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...
34
$modid = \Xmf\Request::getInt('modid', 1, 'POST');
0 ignored issues
show
Bug introduced by
The type Xmf\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
// we dont want system module permissions to be changed here ( 1 -> 0 GIJ)
36
if ($modid <= 0 || !is_object($xoopsUser) || !$xoopsUser->isAdmin($modid)) {
37
    redirect_header(XOOPS_URL . '/user.php', 1, _NOPERM);
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant _NOPERM was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
    /** @scrutinizer ignore-call */ 
38
    redirect_header(XOOPS_URL . '/user.php', 1, _NOPERM);
Loading history...
38
}
39
/** @var XoopsModuleHandler $moduleHandler */
40
$moduleHandler = xoops_getHandler('module');
0 ignored issues
show
Bug introduced by
The function xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
$moduleHandler = /** @scrutinizer ignore-call */ xoops_getHandler('module');
Loading history...
41
$module        = $moduleHandler->get($modid);
42
if (!is_object($module) || !$module->getVar('isactive')) {
43
    redirect_header(XOOPS_URL . '/admin.php', 1, _MODULENOEXIST);
0 ignored issues
show
Bug introduced by
The constant _MODULENOEXIST was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
44
}
45
$memberHandler = xoops_getHandler('member');
46
$group_list    =& $memberHandler->getGroupList();
47
if (is_array($_POST['perms']) && !empty($_POST['perms'])) {
48
    $gpermHandler = xoops_getHandler('groupperm');
49
    foreach ($_POST['perms'] as $perm_name => $perm_data) {
50
        foreach ($perm_data['itemname'] as $item_id => $item_name) {
51
            // checking code
52
            // echo "<pre>" ;
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...
53
            // var_dump( $_POST['perms'] ) ;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
54
            // exit ;
55
            if (false !== myDeleteByModule($gpermHandler->db, $modid, $perm_name, $item_id)) {
56
                if (empty($perm_data['groups'])) {
57
                    continue;
58
                }
59
                foreach ($perm_data['groups'] as $group_id => $item_ids) {
60
                    //              foreach ($item_ids as $item_id => $selected) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% 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...
61
                    $selected = isset($item_ids[$item_id]) ? $item_ids[$item_id] : 0;
62
                    if (1 == $selected) {
63
                        // make sure that all parent ids are selected as well
64
                        if ('' != $perm_data['parents'][$item_id]) {
65
                            $parent_ids = explode(':', $perm_data['parents'][$item_id]);
66
                            foreach ($parent_ids as $pid) {
67
                                if (0 != $pid && !in_array($pid, array_keys($item_ids))) {
68
                                    // one of the parent items were not selected, so skip this item
69
                                    $msg[] = sprintf(_MD_AM_PERMADDNG, '<b>' . $perm_name . '</b>', '<b>' . $perm_data['itemname'][$item_id] . '</b>', '<b>' . $group_list[$group_id] . '</b>') . ' (' . _MD_AM_PERMADDNGP . ')';
0 ignored issues
show
Bug introduced by
The constant _MD_AM_PERMADDNG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant _MD_AM_PERMADDNGP was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
70
                                    continue 2;
71
                                }
72
                            }
73
                        }
74
                        $gperm = $gpermHandler->create();
75
                        $gperm->setVar('gperm_groupid', $group_id);
76
                        $gperm->setVar('gperm_name', $perm_name);
77
                        $gperm->setVar('gperm_modid', $modid);
78
                        $gperm->setVar('gperm_itemid', $item_id);
79
                        if (!$gpermHandler->insert($gperm)) {
80
                            $msg[] = sprintf(_MD_AM_PERMADDNG, '<b>' . $perm_name . '</b>', '<b>' . $perm_data['itemname'][$item_id] . '</b>', '<b>' . $group_list[$group_id] . '</b>');
81
                        } else {
82
                            $msg[] = sprintf(_MD_AM_PERMADDOK, '<b>' . $perm_name . '</b>', '<b>' . $perm_data['itemname'][$item_id] . '</b>', '<b>' . $group_list[$group_id] . '</b>');
0 ignored issues
show
Bug introduced by
The constant _MD_AM_PERMADDOK was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
83
                        }
84
                        unset($gperm);
85
                    }
86
                }
87
            } else {
88
                $msg[] = sprintf(_MD_AM_PERMRESETNG, $module->getVar('name'));
0 ignored issues
show
Bug introduced by
The constant _MD_AM_PERMRESETNG was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
89
            }
90
        }
91
    }
92
}
93
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% 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...
94
$backlink = XOOPS_URL.'/admin.php';
95
if ($module->getVar('hasadmin')) {
96
    $adminindex = $module->getInfo('adminindex');
97
    if ($adminindex) {
98
        $backlink = XOOPS_URL.'/modules/'.$module->getVar('dirname').'/'.$adminindex;
99
    }
100
}
101
102
$msg[] = '<br><br><a href="'.$backlink.'">'._BACK.'</a>';
103
xoops_cp_header();
104
xoops_result($msg);
105
xoops_cp_footer();  GIJ */
106