IndexController::checkPrivilege()   A
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 32
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 32
rs 9.2222
c 0
b 0
f 0
cc 6
nc 8
nop 1
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Suico;
4
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
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
15
use Criteria;
16
17
/**
18
 * @category        Module
19
 * @copyright       {@link https://xoops.org/ XOOPS Project}
20
 * @license         GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
21
 * @author          Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
22
 */
23
require_once XOOPS_ROOT_PATH . '/kernel/object.php';
24
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
25
require_once XOOPS_ROOT_PATH . '/class/criteria.php';
26
require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
27
28
/**
29
 * Class IndexController
30
 */
31
class IndexController extends Controller
32
{
33
    /**
34
     * @param string|null $section
35
     * @return int|void
36
     */
37
    public function checkPrivilege($section = null)
38
    {
39
        global $xoopsModuleConfig;
40
        if ('' === \trim($section)) {
0 ignored issues
show
Bug introduced by
It seems like $section can also be of type null; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

40
        if ('' === \trim(/** @scrutinizer ignore-type */ $section)) {
Loading history...
41
            return -1;
42
        }
43
        $configsectionname = 'enable_' . $section;
44
        if (\array_key_exists($configsectionname, $xoopsModuleConfig)) {
45
            if (0 === $this->helper->getConfig($configsectionname)) {
46
                return -1;
47
            }
48
        }
49
        //  if ($section=="Notes" && $xoopsModuleConfig['enable_notes']==0){
50
        //          return false;
51
        //      }
52
        //      if ($section=="pictures" && $xoopsModuleConfig['enable_pictures']==0){
53
        //          return false;
54
        //      }
55
        //
56
        //      if ($section=="pictures" && $xoopsModuleConfig['enable_pictures']==0){
57
        //          return false;
58
        //      }
59
        $criteria = new Criteria('config_uid', $this->owner->getVar('uid'));
0 ignored issues
show
Bug introduced by
It seems like $this->owner->getVar('uid') can also be of type array and array; however, parameter $value of Criteria::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

59
        $criteria = new Criteria('config_uid', /** @scrutinizer ignore-type */ $this->owner->getVar('uid'));
Loading history...
60
        if (1 === $this->configsFactory->getCount($criteria)) {
61
            $configs = $this->configsFactory->getObjects($criteria);
62
            $config  = $configs[0]->getVar($section);
63
            if (!$this->checkPrivilegeLevel($config)) {
64
                return 0;
65
            }
66
        }
67
68
        return 1;
69
    }
70
}
71