Completed
Push — master ( ca3f3f...3c943f )
by Michael
03:20
created

PublisherGroupPermHandler::checkRight()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 9.2
cc 4
eloc 14
nc 4
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 32 and the first side effect is on line 25.

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
 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
 *  Publisher class
14
 *
15
 * @copyright       The XUUPS Project http://sourceforge.net/projects/xuups/
16
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
17
 * @package         Publisher
18
 * @since           1.0
19
 * @author          trabis <[email protected]>
20
 * @version         $Id: groupperm.php 10374 2012-12-12 23:39:48Z trabis $
21
 */
22
23
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
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...
24
25
include_once $GLOBALS['xoops']->path('kernel/groupperm.php');
26
27
include_once dirname(__DIR__) . '/include/common.php';
28
29
/**
30
 * Class PublisherGroupPermHandler
31
 */
32
class PublisherGroupPermHandler extends XoopsGroupPermHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
33
{
34
    /**
35
     * Check permission
36
     *
37
     * @param string              $gpermName    Name of permission
38
     * @param int                 $gpermItemId  ID of an item
39
     * @param int          /array $gpermGroupId A group ID or an array of group IDs
40
     * @param int                 $gpermModId   ID of a module
41
     *
42
     * @return bool TRUE if permission is enabled
43
     */
44
    public function checkRight($gpermName, $gpermItemId, $gpermGroupId, $gpermModId = 1)
45
    {
46
        $criteria = new CriteriaCompo(new Criteria('gperm_modid', $gpermModId));
47
        $criteria->add(new Criteria('gperm_name', $gpermName));
48
        $gpermItemId = (int)$gpermItemId;
49
        if ($gpermItemId > 0) {
50
            $criteria->add(new Criteria('gperm_itemid', $gpermItemId));
51
        }
52
        if (is_array($gpermGroupId)) {
53
            $criteria2 = new CriteriaCompo();
54
            foreach ($gpermGroupId as $gid) {
55
                $criteria2->add(new Criteria('gperm_groupid', $gid), 'OR');
56
            }
57
            $criteria->add($criteria2);
58
        } else {
59
            $criteria->add(new Criteria('gperm_groupid', $gpermGroupId));
60
        }
61
        return $this->getCount($criteria) > 0;
62
    }
63
}
64