Issues (4)

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/PsrSimpleCache/Pool.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
3
/**
4
 *
5
 * This file is part of the Apix Project.
6
 *
7
 * (c) Franck Cassedanne <franck at ouarz.net>
8
 *
9
 * @license     http://opensource.org/licenses/BSD-3-Clause  New BSD License
10
 *
11
 */
12
13
namespace Apix\SimpleCache\PsrSimpleCache;
14
15
use Apix\Cache\PsrCache\Item as CacheItem;
16
use Psr\SimpleCache\CacheInterface as SimpleCacheInterface;
17
use Psr\Cache\CacheItemPoolInterface as CacheItemPool;
18
use Psr\Cache\InvalidArgumentException as CacheInvalidArgumentException;
19
20
/**
21
 * Provides a PSR-16 (SimpleCache) wrapper to PSR-6 (Cache).
22
 *
23
 * @author Franck Cassedanne <franck at ouarz.net>
24
 */
25
class Pool implements SimpleCacheInterface
26
{
27
28
    /**
29
     * @var CacheItemPool
30
     */
31
    protected $cache_item_pool;
32
33
    /**
34
     * Constructor.
35
     */
36 195
    public function __construct(CacheItemPool $cache_item_pool)
37
    {
38 195
        $this->cache_item_pool = $cache_item_pool;
39 195
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 46 View Code Duplication
    public function get($key, $default = null)
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...
45
    {
46
        try {
47 46
            $item = $this->cache_item_pool->getItem($key);
48 46
        } catch (CacheInvalidArgumentException $e) {
49 38
            self::_rethrow($e);
50
        }
51
52 8
        return $item->isHit() ? $item->get() : $default;
53 1
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 41
    public function getMultiple($keys, $default = null)
59
    {
60 41
        $keys = self::_normalizedKeys($keys);
61
62 28
        $items = array();
63 28
        foreach ($keys as $key) {
64 28
            $items[$key] = $this->get($key, $default);
65 4
        }
66
67 4
        return $items;
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73 23
    public function has($key)
74
    {
75
        try {
76 23
            $bool = $this->cache_item_pool->hasItem($key);
77 23
        } catch (CacheInvalidArgumentException $e) {
78 14
            self::_rethrow($e);
79
        }
80
81 9
        return $bool;
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87 1
    public function clear()
88
    {
89 1
        return $this->cache_item_pool->clear();
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95 39
    public function deleteMultiple($keys)
96
    {
97 39
        $keys = self::_normalizedKeys($keys);
98
99
        try {
100 26
            $bool = $this->cache_item_pool->deleteItems($keys);
101 26
        } catch (CacheInvalidArgumentException $e) {
102 24
            self::_rethrow($e);
103
        }
104
105 2
        return $bool;
106
    }
107
108
    /**
109
     * {@inheritdoc}
110
     */
111 16
    public function delete($key)
112
    {
113
        try {
114 16
            $bool = $this->cache_item_pool->deleteItem($key);
115 16
        } catch (CacheInvalidArgumentException $e) {
116 14
            self::_rethrow($e);
117
        }
118
119 2
        return $bool;
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125 21 View Code Duplication
    public function set($key, $value, $ttl = null)
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...
126
    {
127
        try {
128 21
            $item = $this->cache_item_pool->getItem($key);
129 7
            $this->setItemProperties($item, $value, $ttl);
0 ignored issues
show
$item of type object<Psr\Cache\CacheItemInterface> is not a sub-type of object<Apix\Cache\PsrCache\Item>. It seems like you assume a concrete implementation of the interface Psr\Cache\CacheItemInterface 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...
130 21
        } catch (CacheInvalidArgumentException $e) {
131 14
            self::_rethrow($e);
132
        }
133
134 7
        return $this->cache_item_pool->save($item);
135
    }
136
137
    /**
138
     * {@inheritdoc}
139
     */
140 45
    public function setMultiple($values, $ttl = null)
141
    {
142 45
        if (!is_array($values) && !$values instanceof \Traversable) {
143 13
            throw new InvalidArgumentException(sprintf(
144 13
                'Expected an array or a \Traversable, got `%s`.',
145 13
                gettype($values)
146 13
            ));
147
        }
148
149 32
        $keys = array_keys((array) $values);
150
151
        try {
152 32
            $items = $this->cache_item_pool->getItems($keys);
153 32
        } catch (CacheInvalidArgumentException $e) {
154 24
            self::_rethrow($e);
155
        }
156
157 8
        $success = true;
158 8
        foreach ($items as $key => $item) {
159
            try {
160 8
                $this->setItemProperties($item, $values[$key], $ttl);
161 8
            } catch (CacheInvalidArgumentException $e) {
162 1
                self::_rethrow($e);
163
            }
164
165
            $success = $success
166 7
                       && $this->cache_item_pool->saveDeferred($item);
167 7
        }
168
169 7
        return $success && $this->cache_item_pool->commit();
170
    }
171
172
    /**
173
     * Sets the properties of an item object.
174
     *
175
     * @param CacheItem              $item
176
     * @param mixed                  $value The item value (unserialized)
177
     * @param integer|\DateInterval|null $ttl
178
     *
179
     * @return static The invoked object.
180
     */
181 13
    protected function setItemProperties(
182
        CacheItem $item, $value, $ttl = null
183
    ) {
184 13
        return $item->set($value)
185 13
                    ->expiresAfter($ttl);
186
    }
187
188 80
    private static function _normalizedKeys($keys)
189
    {
190 80
        if (!is_array($keys)) {
191 52
            if (!$keys instanceof \Traversable) {
192 26
                throw new InvalidArgumentException(sprintf(
193 26
                    'Expected an array or a \Traversable, got `%s`.',
194 26
                    gettype($keys)
195 26
                ));
196
            }
197
198 26
            $keys = iterator_to_array($keys, false);
199 26
        }
200
201 54
        return $keys;
202
    }
203
204 129
    private static function _rethrow(CacheInvalidArgumentException $e)
205
    {
206 129
        throw new InvalidArgumentException(
207 129
            $e->getMessage(), $e->getCode(), $e
208 129
        );
209
    }
210
211
    /**
212
     * Returns the cache adapter for this pool.
213
     *
214
     * @return CacheAdapter
215
     */
216 7
    public function getCacheAdapter()
217
    {
218 7
        return $this->cache_item_pool->getCacheAdapter();
219
    }
220
}
221