NotesController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fetchNotes() 0 10 2
A checkPrivilege() 0 25 5
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 NotesController
30
 */
31
class NotesController extends Controller
32
{
33
    /**
34
     * @param                                      $countNotes
35
     * @param \CriteriaElement|\CriteriaCompo|null $criteria
36
     * @return bool|array
37
     */
38
    public function fetchNotes(
39
        $countNotes,
40
        $criteria
41
    ) {
42
        $notes = $this->notesFactory->getNotes($countNotes, $criteria);
43
        if ($notes) {
44
            return $notes;
45
        }
46
47
        return false;
48
    }
49
50
    /**
51
     * @param string $privilegeType
52
     * @return bool|void
53
     */
54
    public function checkPrivilege(
55
        $privilegeType = ''
56
    ) {
57
        if (0 === $this->helper->getConfig('enable_notes')) {
58
            \redirect_header('index.php?uid=' . $this->owner->getVar('uid'), 3, \_MD_SUICO_NOTES_ENABLED_NOT);
59
        }
60
        if ('sendNotes' === $privilegeType) {
61
            $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

61
            $criteria = new Criteria('config_uid', /** @scrutinizer ignore-type */ $this->owner->getVar('uid'));
Loading history...
62
            if (1 === $this->configsFactory->getCount($criteria)) {
63
                $configs = $this->configsFactory->getObjects($criteria);
64
                $config  = $configs[0]->getVar('sendNotes');
0 ignored issues
show
Unused Code introduced by
The assignment to $config is dead and can be removed.
Loading history...
65
            }
66
        }
67
        $criteria = new Criteria('config_uid', $this->owner->getVar('uid'));
68
        if (1 === $this->configsFactory->getCount($criteria)) {
69
            $configs = $this->configsFactory->getObjects($criteria);
70
            $config  = $configs[0]->getVar('notes');
71
            /*
72
            if (!$this->checkPrivilegeLevel($config)) {
73
                \redirect_header('index.php?uid=' . $this->owner->getVar('uid'), 10, sprintf(_MD_SUICO_NOPRIVILEGE,'Notes'));
74
            }
75
            */
76
        }
77
78
        return true;
79
    }
80
}
81