Completed
Push — master ( 047d50...4f5633 )
by Michael
02:19
created

PublicCategoryHandler   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 95
rs 10
c 0
b 0
f 0
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getPermHandler() 0 3 1
B createCat() 0 58 7
A hasValidParent() 0 6 1
1
<?php namespace XoopsModules\Extgallery;
2
3
/**
4
 * ExtGallery Class Manager
5
 *
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
 *
13
 * @copyright   {@link https://xoops.org/ XOOPS Project}
14
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
15
 * @author      Zoullou (http://www.zoullou.net)
16
 * @package     ExtGallery
17
 */
18
19
use XoopsModules\Extgallery;
20
21
// 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...
22
23
24
/**
25
 * Class Extgallery\PublicCategoryHandler
26
 */
27
class PublicCategoryHandler extends Extgallery\CategoryHandler
28
{
29
    /**
30
     * Extgallery\PublicCategoryHandler constructor.
31
     * @param \XoopsDatabase $db
32
     */
33
    public function __construct(\XoopsDatabase $db)
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...
34
    {
35
        parent::__construct($db, 'public');
36
    }
37
38
    /**
39
     * @param $data
40
     *
41
     * @return bool
42
     */
43
    public function createCat($data)
44
    {
45
        /** @var Extgallery\PublicCategory $cat */
46
        $cat = $this->create();
47
        $cat->setVars($data);
48
49
        if (!$this->hasValidParent($cat)) {
50
            return false;
51
        }
52
53
        $this->insert($cat, true);
54
        $this->rebuild();
55
56
        $criteria = new \CriteriaCompo();
0 ignored issues
show
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...
57
        $criteria->setSort('cat_id');
58
        $criteria->setOrder('DESC');
59
        $criteria->setLimit(1);
60
61
        $cat =& $this->getObjects($criteria);
62
        $cat = $cat[0];
63
64
        $moduleId = $GLOBALS['xoopsModule']->getVar('mid');
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleId is dead and can be removed.
Loading history...
65
66
        // Retriving permission mask
67
        /** @var \XoopsGroupPermHandler $gpermHandler */
68
        $gpermHandler = xoops_getHandler('groupperm');
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

68
        $gpermHandler = /** @scrutinizer ignore-call */ xoops_getHandler('groupperm');
Loading history...
69
        $moduleId     = $GLOBALS['xoopsModule']->getVar('mid');
70
        $groups       = $GLOBALS['xoopsUser']->getGroups();
71
72
        $criteria = new \CriteriaCompo();
73
        $criteria->add(new \Criteria('gperm_name', 'extgallery_public_mask'));
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...
74
        $criteria->add(new \Criteria('gperm_modid', $moduleId));
75
        $permMask = $gpermHandler->getObjects($criteria);
76
77
        // Retriving group list
78
        /** @var \XoopsMemberHandler $memberHandler */
79
        $memberHandler = xoops_getHandler('member');
80
        $glist         = $memberHandler->getGroupList();
81
82
        // Applying permission mask
83
        $permArray       = include XOOPS_ROOT_PATH . '/modules/extgallery/include/perm.php';
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Extgallery\XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
84
        $modulePermArray = $permArray['modulePerm'];
85
        $pluginPermArray = $permArray['pluginPerm'];
86
87
        foreach ($permMask as $perm) {
88
            foreach ($modulePermArray as $permMask) {
89
                if ($perm->getVar('gperm_itemid') == $permMask['maskId']) {
90
                    $gpermHandler->addRight($permMask['name'], $cat->getVar('cat_id'), $perm->getVar('gperm_groupid'), $moduleId);
91
                }
92
            }
93
94
            foreach ($pluginPermArray as $permMask) {
95
                if ($perm->getVar('gperm_itemid') == $permMask['maskId']) {
96
                    $gpermHandler->addRight($permMask['name'], $cat->getVar('cat_id'), $perm->getVar('gperm_groupid'), $moduleId);
97
                }
98
            }
99
        }
100
        return true;
101
    }
102
103
    /**
104
     * @param \XoopsObject $cat
105
     *
106
     * @return bool
107
     */
108
    public function hasValidParent(\XoopsObject $cat = null)
0 ignored issues
show
Bug introduced by
The type XoopsObject 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...
109
    {
110
        // Check if haven't photo in parent category (parent category isn't an album)
111
        $parentCat = $this->get($cat->getVar('cat_pid'));
0 ignored issues
show
Bug introduced by
The method getVar() does not exist on null. ( Ignorable by Annotation )

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

111
        $parentCat = $this->get($cat->/** @scrutinizer ignore-call */ getVar('cat_pid'));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
112
113
        return !$this->_isAlbum($parentCat);
114
    }
115
116
    /**
117
     * @return Extgallery\PublicPermHandler
118
     */
119
    public function getPermHandler()
120
    {
121
        return Extgallery\PublicPermHandler::getInstance();
122
    }
123
}
124