Passed
Pull Request — master (#18)
by Michael
02:01
created

Links   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 69
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getHooks() 0 18 4
A checkAccess() 0 11 3
A __construct() 0 18 1
1
<?php namespace XoopsModules\Mymenus;
2
3
/*
4
 You may not change or alter any portion of this comment or credits
5
 of supporting developers from this source code or any supporting source code
6
 which is considered copyrighted (c) material of the original comment or credit authors.
7
8
 This program is distributed in the hope that it will be useful,
9
 but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * @copyright       XOOPS Project (https://xoops.org)
15
 * @license         http://www.gnu.org/licenses/gpl-2.0.html GNU Public License
16
 * @package         Mymenus
17
 * @since           1.0
18
 * @author          trabis <[email protected]>
19
 */
20
21
use XoopsModules\Mymenus;
22
23
defined('XOOPS_ROOT_PATH') || die('Restricted access');
24
25
//require  dirname(__DIR__) . '/include/common.php';
26
27
/**
28
 * Class Links
29
 */
30
class Links extends \XoopsObject
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...
31
{
32
    /**
33
     * @var Links
34
     * @access private
35
     */
36
    private $helper;
37
    private $db;
38
39
    /**
40
     * constructor
41
     */
42
    public function __construct()
43
    {
44
        /** @var \XoopsModules\Mymenus\Helper $this->helper */
45
        $this->helper = \XoopsModules\Mymenus\Helper::getInstance();
46
        $this->db      = \XoopsDatabaseFactory::getDatabaseConnection();
0 ignored issues
show
Bug introduced by
The type XoopsDatabaseFactory 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...
47
        $this->initVar('id', XOBJ_DTYPE_INT);
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Mymenus\XOBJ_DTYPE_INT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
48
        $this->initVar('pid', XOBJ_DTYPE_INT);
49
        $this->initVar('mid', XOBJ_DTYPE_INT);
50
        $this->initVar('title', XOBJ_DTYPE_TXTBOX);
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Mymenus\XOBJ_DTYPE_TXTBOX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
51
        $this->initVar('alt_title', XOBJ_DTYPE_TXTBOX);
52
        $this->initVar('visible', XOBJ_DTYPE_INT, true);
53
        $this->initVar('link', XOBJ_DTYPE_TXTBOX);
54
        $this->initVar('weight', XOBJ_DTYPE_INT, 255);
55
        $this->initVar('target', XOBJ_DTYPE_TXTBOX);
56
        $this->initVar('groups', XOBJ_DTYPE_ARRAY, serialize([XOOPS_GROUP_ANONYMOUS, XOOPS_GROUP_USERS]));
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Mymenus\XOOPS_GROUP_ANONYMOUS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant XoopsModules\Mymenus\XOOPS_GROUP_USERS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant XoopsModules\Mymenus\XOBJ_DTYPE_ARRAY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
57
        $this->initVar('hooks', XOBJ_DTYPE_ARRAY, serialize([]));
58
        $this->initVar('image', XOBJ_DTYPE_TXTBOX);
59
        $this->initVar('css', XOBJ_DTYPE_TXTBOX);
60
    }
61
62
    /**
63
     * @return bool
64
     */
65
    public function checkAccess()
66
    {
67
        $hooks              = $this->getHooks();
68
        $hooks['mymenus'][] = 'checkAccess';
69
        foreach ($hooks as $hookName => $hook) {
70
            if (!mymenusHook($hookName, 'checkAccess', ['links' => $this])) {
0 ignored issues
show
Bug introduced by
The function mymenusHook 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

70
            if (!/** @scrutinizer ignore-call */ mymenusHook($hookName, 'checkAccess', ['links' => $this])) {
Loading history...
71
                return false;
72
            }
73
        }
74
75
        return true;
76
    }
77
78
    /**
79
     * @return array
80
     */
81
    public function getHooks()
82
    {
83
        $ret  = [];
84
        $data = $this->getVar('hooks', 'n');
85
        if (!$data) {
86
            return $ret;
87
        }
88
        $lines = explode("\n", $data);
89
        foreach ($lines as $line) {
90
            $line   = trim($line);
91
            $line   = explode('|', $line);
92
            $hook   = trim($line[0]);
93
            $method = isset($line[1]) ? trim($line[1]) : '';
94
            //$info = explode(',', trim($line[0]));
95
            $ret[$hook][] = $method;
96
        }
97
98
        return $ret;
99
    }
100
}
101