Issues (5)

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.

src/CacheItem.php (3 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
namespace Psr6NullCache;
3
4
use Psr\Cache\CacheItemInterface;
5
use DateTimeInterface;
6
use DateInterval;
7
use DateTime;
8
9
final class CacheItem implements CacheItemInterface
10
{
11
12
    /**
13
     *
14
     * @var string
15
     */
16
    private $key;
17
18
    /**
19
     *
20
     * @var mixed
21
     */
22
    private $value;
23
24
    /**
25
     *
26
     * @var boolean
27 5
     */
28
    private $isHit;
29 5
30 5
    /**
31 5
     *
32 5
     * @var null DateTimeInterface
33
     */
34
    private $expires;
35
36
    public function __construct($key, $value, $isHit, DateTimeInterface $expires = null)
37
    {
38
        $this->key = $key;
39
        $this->value = $value;
40
        $this->isHit = (bool) $isHit;
41
        $this->expires = $expires;
0 ignored issues
show
Documentation Bug introduced by
It seems like $expires can also be of type object<DateTimeInterface>. However, the property $expires is declared as type null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
42 2
    }
43
44 2
    /**
45
     * Returns the key for the current cache item.
46
     *
47
     * The key is loaded by the Implementing Library, but should be available to
48
     * the higher level callers when needed.
49
     *
50
     * @return string The key string for this cache item.
51
     */
52
    public function getKey()
53
    {
54
        return $this->key;
55
    }
56
57
    /**
58 3
     * Retrieves the value of the item from the cache associated with this object's key.
59
     *
60 3
     * The value returned must be identical to the value originally stored by set().
61
     *
62
     * If isHit() returns false, this method MUST return null. Note that null
63
     * is a legitimate cached value, so the isHit() method SHOULD be used to
64
     * differentiate between "null value was found" and "no value was found."
65
     *
66
     * @return mixed The value corresponding to this cache item's key, or null if not found.
67
     */
68
    public function get()
69
    {
70
        if ($this->isHit() !== true) {
71 2
            return null;
72
        }
73 2
        
74
        return $this->value;
75
    }
76
77
    public function setIsHit($mode = true)
78
    {
79
        $this->isHit = $mode;
80
    }
81
82
    /**
83
     * Confirms if the cache item lookup resulted in a cache hit.
84
     *
85
     * Note: This method MUST NOT have a race condition between calling isHit()
86
     * and calling get().
87
     *
88 1
     * @return bool True if the request resulted in a cache hit. False otherwise.
89
     */
90 1
    public function isHit()
91
    {
92 1
        return $this->isHit;
93
    }
94
95
    /**
96
     *
97
     * @return DateTimeInterface null
98
     */
99
    public function getExpires()
100
    {
101
        return $this->expires;
102
    }
103
104
    /**
105
     * Sets the value represented by this cache item.
106 1
     *
107
     * The $value argument may be any item that can be serialized by PHP,
108 1
     * although the method of serialization is left up to the Implementing
109
     * Library.
110
     *
111
     * @param mixed $value
112
     *            The serializable value to be stored.
113
     *            
114
     * @return static The invoked object.
115
     */
116
    public function set($value)
117
    {
118
        $this->value = $value;
119
        
120
        return $this;
121
    }
122
123 1
    /**
124
     * Sets the expiration time for this cache item.
125 1
     *
126
     * @param \DateTimeInterface $expires
127
     *            The point in time after which the item MUST be considered expired.
128
     *            If null is passed explicitly, a default value MAY be used. If none is set,
129
     *            the value should be stored permanently or for as long as the
130
     *            implementation allows.
131
     *            
132
     * @return static The called object.
133
     */
134
    public function expiresAt($expires)
135
    {
136
        if ($expires instanceof DateTimeInterface) {
137
            $this->expires = $expires;
0 ignored issues
show
Documentation Bug introduced by
It seems like $expires of type object<DateTimeInterface> is incompatible with the declared type null of property $expires.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
138
        } else {
139
            $this->expires = null;
140
        }
141
        
142
        return $this;
143
    }
144
145
    /**
146
     * Sets the expiration time for this cache item.
147
     *
148
     * @param int|\DateInterval $time
149
     *            The period of time from the present after which the item MUST be considered
150
     *            expired. An integer parameter is understood to be the time in seconds until
151
     *            expiration. If null is passed explicitly, a default value MAY be used.
152
     *            If none is set, the value should be stored permanently or for as long as the
153
     *            implementation allows.
154
     *            
155
     * @return static The called object.
156
     */
157
    public function expiresAfter($time)
158
    {
159
        if ($time instanceof DateInterval) {
160
            $expires = new DateTime();
161
            $expires->add($time);
162
            
163
            $this->expires = $expires;
0 ignored issues
show
Documentation Bug introduced by
It seems like $expires of type object<DateTime> is incompatible with the declared type null of property $expires.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
164
        } elseif (is_numeric($time)) {
165
            $expires = new DateTime('now +' . $time . ' seconds');
166
            
167
            $this->expires = $expires;
168
        } else {
169
            $this->expires = null;
170
        }
171
        
172
        return $this;
173
    }
174
}
175