Issues (273)

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.

src/Model/CachedModel.php (1 issue)

Severity

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
2
/**
3
 * This file allows models to be cached to prevent unnecessary queries to the database
4
 *
5
 * @package    BZiON\Models
6
 * @license    https://github.com/allejo/bzion/blob/master/LICENSE.md GNU General Public License Version 3
7
 */
8
9
/**
10
 * A database object with the ability to be cached in the memory
11
 * @package    BZiON\Models
12
 */
13
abstract class CachedModel extends BaseModel
14
{
15
    /**
16
     * {@inheritdoc}
17
     *
18
     * @return static
19
     */
20 77
    public static function get($id)
21
    {
22 77
        if (is_object($id)) {
23 2
            return parent::get($id);
24
        }
25
26 76
        $cache = Service::getModelCache();
27 76
        $id = (int) $id;
28
29 76
        if (!$cache) {
30
            // There is no cache, just get the model
31
            return parent::get($id);
32
        }
33
34 76
        if ($model = self::getFromCache($id)) {
35
            // The model exists in the cache, return that to the caller
36 76
            return $model;
37
        } else {
38 76
            return parent::get($id)->storeInCache();
39
        }
40
    }
41
42
    /**
43
     * Find out whether a model exists in the cache
44
     *
45
     * @param  int  $id The ID of the model
46
     * @return bool     True if the model exists in the cache
47
     */
48 76
    private static function existsInCache($id)
49
    {
50 76
        $cache = Service::getModelCache();
51
52 76
        if (!$cache) {
53
            return false;
54
        }
55
56 76
        return $cache->has(get_called_class(), $id);
57
    }
58
59
    /**
60
     * Get a model from the cache
61
     *
62
     * @param  int         $id The ID of the model
63
     * @return static|null     The model if it's found, null if it doesn't exist
64
     */
65 76
    private static function getFromCache($id)
66
    {
67 76
        if (!self::existsInCache($id)) {
68 76
            return null;
69
        }
70
71 76
        return Service::getModelCache()->get(get_called_class(), $id);
72
    }
73
74
    /**
75
     * Store the model in the cache
76
     *
77
     * @return self
78
     */
79 76
    protected function storeInCache()
80
    {
81 76
        if (!Service::getModelCache()) {
82
            return $this;
83
        }
84
85 76
        Service::getModelCache()->save($this);
0 ignored issues
show
$this of type object<CachedModel> is not a sub-type of object<Model>. It seems like you assume a child class of the class CachedModel to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
86
87 76
        return $this;
88
    }
89
90
    /**
91
     * Fetch a model's data from the database again
92
     * @return static The new model
93
     */
94 76
    public function refresh()
95
    {
96 76
        $this->getFromDatabase();
97
98 76
        return $this;
99
    }
100
101
    /**
102
     * Get a model's data from the database
103
     */
104 76
    private function getFromDatabase()
105
    {
106 76
        self::__construct($this->id);
107
108 76
        if ($this->loaded) {
109
            // Reload the lazy parameters of the model if they're loaded already
110 76
            $this->lazyLoad(true);
111
        }
112 76
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117 76
    protected static function create($params, $now = null, $table = '')
118
    {
119 76
        $model = parent::create($params, $now, $table);
120 76
        $model->storeInCache();
121
122 76
        return $model;
123
    }
124
}
125