Issues (496)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

class/ObjectsRegistry.php (6 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php namespace XoopsModules\Smartobject;
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      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
16
 * @package
17
 * @since
18
 * @author     XOOPS Development Team
19
 */
20
21
use CriteriaCompo;
22
use XoopsModules\Smartobject;
23
24
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
25
26
/**
27
 * SmartObjects Registry
28
 *
29
 * The SmartObjects Registry is an object containing SmartObject objects that will be reused in the same process
30
 *
31
 * @package SmartObject
32
 * @author  marcan <[email protected]>
33
 * @link    http://smartfactory.ca The SmartFactory
34
 */
35
class ObjectsRegistry
36
{
37
    public $_registryArray;
38
39
    /**
40
     * Access the only instance of this class
41
     *
42
     * @return \XoopsModules\Smartobject\ObjectsRegistry
43
     *
44
     * @static
45
     * @staticvar   object
46
     */
47
    public static function getInstance()
48
    {
49
        static $instance;
50
        if (null === $instance) {
51
            $instance = new static();
52
        }
53
54
        return $instance;
55
    }
56
57
    /**
58
     * Adding objects to the registry
59
     *
60
     * @param  PersistableObjectHandler $handler  of the objects to add
61
     * @param  bool|CriteriaCompo       $criteria to pass to the getObjects method of the handler (with id_as_key)
62
     * @return FALSE                         if an error occured
63
     */
64
    public function addObjectsFromHandler(&$handler, $criteria = false)
65
    {
66 View Code Duplication
        if (method_exists($handler, 'getObjects')) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
            $objects                                                                     = $handler->getObjects($criteria, true);
68
            $this->_registryArray['objects'][$handler->_moduleName][$handler->_itemname] = $objects;
69
70
            return $objects;
71
        } else {
72
            return false;
73
        }
74
    }
75
76
    /**
77
     * Adding objects to the registry from an item name
78
     * This method will fetch the handler of the item / module and call the addObjectsFromHandler
79
     *
80
     * @param  string             $item       name of the item
81
     * @param  bool|string        $modulename name of the module
82
     * @param  bool|CriteriaCompo $criteria   to pass to the getObjects method of the handler (with id_as_key)
83
     * @return FALSE              if an error occured
84
     */
85
    public function addObjectsFromItemName($item, $modulename = false, $criteria = false)
86
    {
87
        if (!$modulename) {
88
            global $xoopsModule;
89
            if (!is_object($xoopsModule)) {
90
                return false;
91
            } else {
92
                $modulename = $xoopsModule->dirname();
93
            }
94
        }
95
        $objectHandler = xoops_getModuleHandler($item, $modulename);
96
97 View Code Duplication
        if (method_exists($objectHandler, 'getObjects')) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
            $objects                                                                                 = $objectHandler->getObjects($criteria, true);
99
            $this->_registryArray['objects'][$objectHandler->_moduleName][$objectHandler->_itemname] = $objects;
100
101
            return $objects;
102
        } else {
103
            return false;
104
        }
105
    }
106
107
    /**
108
     * Fetching objects from the registry
109
     *
110
     * @param string $itemname
111
     * @param string $modulename
112
     *
113
     * @return false|array the requested objects or FALSE if they don't exists in the registry
114
     */
115 View Code Duplication
    public function getObjects($itemname, $modulename)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
116
    {
117
        if (!$modulename) {
118
            global $xoopsModule;
119
            if (!is_object($xoopsModule)) {
120
                return false;
121
            } else {
122
                $modulename = $xoopsModule->dirname();
123
            }
124
        }
125
        if (isset($this->_registryArray['objects'][$modulename][$itemname])) {
126
            return $this->_registryArray['objects'][$modulename][$itemname];
127
        } else {
128
            // if they were not in registry, let's fetch them and add them to the reigistry
129
            $moduleHandler = xoops_getModuleHandler($itemname, $modulename);
130
            if (method_exists($moduleHandler, 'getObjects')) {
131
                $objects = $moduleHandler->getObjects();
132
            }
133
            $this->_registryArray['objects'][$modulename][$itemname] = $objects;
0 ignored issues
show
The variable $objects does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
134
135
            return $objects;
136
        }
137
    }
138
139
    /**
140
     * Fetching objects from the registry, as a list: objectid => identifier
141
     *
142
     * @param string $itemname
143
     * @param string $modulename
144
     *
145
     * @return false|array the requested objects or FALSE if they don't exists in the registry
146
     */
147 View Code Duplication
    public function getList($itemname, $modulename)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
148
    {
149
        if (!$modulename) {
150
            global $xoopsModule;
151
            if (!is_object($xoopsModule)) {
152
                return false;
153
            } else {
154
                $modulename = $xoopsModule->dirname();
155
            }
156
        }
157
        if (isset($this->_registryArray['list'][$modulename][$itemname])) {
158
            return $this->_registryArray['list'][$modulename][$itemname];
159
        } else {
160
            // if they were not in registry, let's fetch them and add them to the reigistry
161
            $moduleHandler = xoops_getModuleHandler($itemname, $modulename);
162
            if (method_exists($moduleHandler, 'getList')) {
163
                $objects = $moduleHandler->getList();
164
            }
165
            $this->_registryArray['list'][$modulename][$itemname] = $objects;
0 ignored issues
show
The variable $objects does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
166
167
            return $objects;
168
        }
169
    }
170
171
    /**
172
     * Retreive a single object
173
     *
174
     * @param string $itemname
175
     * @param string $key
176
     *
177
     * @param  bool  $modulename
178
     * @return false|\XoopsObject the  requestd object or FALSE if they don't exists in the registry
179
     */
180
    public function getSingleObject($itemname, $key, $modulename = false)
181
    {
182
        if (!$modulename) {
183
            global $xoopsModule;
184
            if (!is_object($xoopsModule)) {
185
                return false;
186
            } else {
187
                $modulename = $xoopsModule->dirname();
188
            }
189
        }
190
        if (isset($this->_registryArray['objects'][$modulename][$itemname][$key])) {
191
            return $this->_registryArray['objects'][$modulename][$itemname][$key];
192
        } else {
193
            $objectHandler = xoops_getModuleHandler($itemname, $modulename);
194
            $object        = $objectHandler->get($key);
195
            if (!$object->isNew()) {
196
                return $object;
197
            } else {
198
                return false;
199
            }
200
        }
201
    }
202
}
203