Issues (15)

Security Analysis    no request data  

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.

Cache.php (4 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
2
/**
3
 * Cache Class.
4
 *
5
 * @package SugiPHP.Cache
6
 * @author  Plamen Popov <[email protected]>
7
 * @license http://opensource.org/licenses/mit-license.php (MIT License)
8
 */
9
10
namespace SugiPHP\Cache;
11
12
class Cache
13
{
14
    /**
15
     * The driver used by a cache.
16
     * @var StoreInterface
17
     */
18
    protected $driver;
19
20
    /**
21
     * Key prefix to use.
22
     *
23
     * @var string
24
     */
25
    protected $prefix = "";
26
27
    /**
28
     * Class constructor.
29
     *
30
     * @param StoreInterface $driver
31
     */
32
    public function __construct(StoreInterface $driver)
33
    {
34
        $this->driver = $driver;
35
    }
36
37
    /**
38
     * Sets key prefix.
39
     *
40
     * @param string $prefix
41
     */
42
    public function setPrefix($prefix)
43
    {
44
        $this->prefix = $prefix;
45
    }
46
47
    /**
48
     * Returns key prefix.
49
     *
50
     * @return string
51
     */
52
    public function getPrefix()
53
    {
54
        return $this->prefix;
55
    }
56
57
    /**
58
     * Stores an item in the cache for a specified period of time only if it is not already stored.
59
     * Cache::add() is similar to Cache::set(), but the operation fails if the key already exists.
60
     *
61
     * @param string  $key
62
     * @param mixed  $value The value to be stored.
63
     * @param integer $ttl Time to live in seconds. 0 means to store it for a maximum time possible
64
     *
65
     * @return boolean TRUE if the value is set, FALSE on failure
66
     */
67
    public function add($key, $value, $ttl = 0)
68
    {
69
        $key = $this->prefix.$key;
70
71
        return $this->driver->add($key, $value, $ttl);
72
    }
73
74
    /**
75
     * Stores an item in the data store
76
     * Cache::set() is similar to Cache::add(), but the operation will not fail if the key already exist.
77
     *
78
     * @param string $key The key under which to store the value
79
     * @param mixed $value The value to store
80
     * @param integer $ttl Expiration time in seconds, after which the value is invalidated (deleted)
81
     *
82
     * @return boolean TRUE on success or FALSE on failure
83
     */
84
    public function set($key, $value, $ttl = 0)
85
    {
86
        $key = $this->prefix.$key;
87
88
        return $this->driver->set($key, $value, $ttl);
89
    }
90
91
    /**
92
     * Fetches a stored variable from the cache
93
     *
94
     * @param string $key The key used to store the value
95
     *
96
     * @return mixed Returns NULL if the key does not exist in the store or the value was expired (see $ttl)
97
     */
98
    public function get($key, $defaultValue = null)
99
    {
100
        $key = $this->prefix.$key;
101
        $result = $this->driver->get($key);
102
103
        return is_null($result) ? $defaultValue : $result;
104
    }
105
106
    /**
107
     * Checks if the key exists
108
     *
109
     * @param string $key
110
     *
111
     * @return boolean TRUE if the key exists, otherwise FALSE
112
     */
113
    public function has($key)
114
    {
115
        $key = $this->prefix.$key;
116
117
        return $this->driver->has($key);
118
    }
119
120
    /**
121
     * Removes a stored variable from the cache
122
     *
123
     * @param string $key
124
     */
125
    public function delete($key)
126
    {
127
        $key = $this->prefix.$key;
128
129
        $this->driver->delete($key);
130
    }
131
132
    /**
133
     * Invalidate all items in the cache
134
     */
135
    public function flush()
136
    {
137
        $this->driver->flush();
138
    }
139
140
    /**
141
     * Increment numeric item's value.
142
     * If there is no such key or the stored value is not numeric FALSE is returned
143
     *
144
     * @param string $key
145
     * @param integer $step
146
     *
147
     * @return integer|false Returns the new incremented value or FALSE on failure
148
     */
149 View Code Duplication
    public function inc($key, $step = 1)
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...
150
    {
151
        $key = $this->prefix.$key;
152
153
        if ($this->driver instanceof IncrementorInterface) {
154
            return $this->driver->inc($key, $step);
155
        }
156
157
        $value = $this->driver->get($key);
158
        if (is_null($value) || !is_numeric($value)) {
159
            return false;
160
        }
161
        $newValue = $value + $step;
162
163
        return ($this->driver->set($key, $newValue)) ? $newValue : false;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->driver->set($key,...e) ? $newValue : false; of type integer|double|false adds the type double to the return on line 163 which is incompatible with the return type documented by SugiPHP\Cache\Cache::inc of type integer|false.
Loading history...
164
    }
165
166
    /**
167
     * Decrements numeric item's value.
168
     * If there is no such key or the stored value is not numeric FALSE is returned
169
     *
170
     * @param string $key
171
     * @param integer $step
172
     *
173
     * @return integer|false Returns the new decremented value or FALSE on failure
174
     */
175 View Code Duplication
    public function dec($key, $step = 1)
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...
176
    {
177
        $key = $this->prefix.$key;
178
179
        if ($this->driver instanceof IncrementorInterface) {
180
            return $this->driver->dec($key, $step);
181
        }
182
183
        $value = $this->driver->get($key);
184
        if (is_null($value) || !is_numeric($value)) {
185
            return false;
186
        }
187
        $newValue = $value - $step;
188
189
        return ($this->driver->set($key, $newValue)) ? $newValue : false;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->driver->set($key,...e) ? $newValue : false; of type integer|double|false adds the type double to the return on line 189 which is incompatible with the return type documented by SugiPHP\Cache\Cache::dec of type integer|false.
Loading history...
190
    }
191
}
192