Completed
Branch master (55a138)
by Michael
03:21
created

Perm   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getHandler() 0 9 2
A _getUserGroup() 0 8 2
A getAuthorizedCat() 0 17 4
A isAllowed() 0 6 1
1
<?php namespace XoopsModules\Extcal;
2
3
// defined('XOOPS_ROOT_PATH') || exit('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...
4
5
/**
6
 * Class Perm.
7
 */
8
class Perm
9
{
10
    /**
11
     * @return Perm
12
     */
13
    public static function getHandler()
14
    {
15
        static $permHandler;
16
        if (!isset($permHandler)) {
17
            $permHandler = new self();
18
        }
19
20
        return $permHandler;
21
    }
22
23
    /**
24
     * @param $user
25
     *
26
     * @return string
27
     */
28
    public function _getUserGroup(&$user)
29
    {
30
        if (is_a($user, 'XoopsUser')) {
31
            return $user->getGroups();
32
        } else {
33
            return XOOPS_GROUP_ANONYMOUS;
34
        }
35
    }
36
37
    /**
38
     * @param $user
39
     * @param           $perm
40
     *
41
     * @return bool
42
     */
43
    public function getAuthorizedCat($user, $perm)
44
    {
45
        static $authorizedCat;
46
        $userId = $user ? $user->getVar('uid') : 0;
47
        if (!isset($authorizedCat[$perm][$userId])) {
48
            $groupPermHandler = xoops_getHandler('groupperm');
49
            /** @var XoopsModuleHandler $moduleHandler */
50
            $moduleHandler = xoops_getHandler('module');
51
            $module        = $moduleHandler->getByDirname('extcal');
52
            if (!$module) {
53
                return false;
54
            }
55
            $authorizedCat[$perm][$userId] = $groupPermHandler->getItemIds($perm, $this->_getUserGroup($user), $module->getVar('mid'));
56
        }
57
58
        return $authorizedCat[$perm][$userId];
59
    }
60
61
    /**
62
     * @param $user
63
     * @param $perm
64
     * @param $catId
65
     *
66
     * @return bool
67
     */
68
    public function isAllowed(&$user, $perm, $catId)
69
    {
70
        $autorizedCat = $this->getAuthorizedCat($user, $perm);
71
72
        return in_array($catId, $autorizedCat);
73
    }
74
}
75