Issues (36)

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/PsrCache/Pool.php (2 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\Cache\PsrCache;
14
15
use Apix\Cache\Adapter as CacheAdapter;
16
use Psr\Cache\CacheItemInterface as ItemInterface;
17
use Psr\Cache\CacheItemPoolInterface as ItemPoolInterface;
18
19
class Pool implements ItemPoolInterface
20
{
21
22
    /**
23
     *
24
     * @var CacheAdapter
25
     */
26
    protected $cache_adapter;
27
28
    /**
29
     * Deferred cache items to be saved later.
30
     *
31
     * @var array   Collection of \Apix\PsrCache\Item.
32
     */
33
    protected $deferred = array();
34
35
    /**
36
     * Constructor.
37
     */
38 374 View Code Duplication
    public function __construct(CacheAdapter $cache_adapter)
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...
39
    {
40 374
        $this->cache_adapter = $cache_adapter;
41
42
        $options = array(
43
            'tag_enable' => false // wether to enable tagging
44 374
        );
45 374
        $this->cache_adapter->setOptions($options);
46 374
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 170
    public function getItem($key)
52
    {
53 170
        $key = Item::normalizedKey($key);
54
55 170
        if (isset($this->deferred[$key])) {
56 170
            return $this->deferred[$key];
57 170
        }
58 170
59
        $value = $this->cache_adapter->loadKey($key);
60 170
61
        return new Item(
62
            $this->cache_adapter->removePrefixKey($key),
63
            $value,
64
            $this->cache_adapter->getTtl($key) ?: null,
65
            (bool) $value // indicates wether it is loaded from cache or not.
66 68
        );
67
    }
68 68
69 68
    /**
70 68
     * {@inheritdoc}
71 68
     */
72
    public function getItems(array $keys = array())
73 68
    {
74
        $items = array();
75
        foreach ($keys as $key) {
76
            $items[$key] = $this->getItem($key);
77
        }
78
79 68
        return $items;
80
    }
81 68
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function hasItem($key)
86
    {
87 34
        return $this->getItem($key)->isHit();
88
    }
89 34
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function clear()
94
    {
95 68
        $this->deferred = array();
96
        return $this->cache_adapter->flush(true);
97 68
    }
98 68
99 68
    /**
100
     * {@inheritdoc}
101 68
     */
102
    public function deleteItems(array $keys)
103
    {
104
        $checks = array();
105
        foreach ($keys as $key) {
106
            // Only delete from cache if it actually exists
107 34
            if($this->getItem($key)->isHit()) {
108
                $checks[] = $this->cache_adapter->delete($key);
109 34
            }
110
            unset($this->deferred[$key]);
111
        }
112
        return (bool) !in_array(false, $checks, true);
113
    }
114
115 170
    /**
116
     * {@inheritdoc}
117 170
     */
118
    public function deleteItem($key)
119 170
    {
120 170
        return $this->deleteItems(array($key));
121 170
    }
122 170
123 170
    /**
124 170
     * {@inheritdoc}
125 170
     */
126 170
    public function save(ItemInterface $item)
127
    {
128 170
        $ttl = $item->getTtlInSecond();
129
130
        $item->setHit(true);
131
        $success = $this->cache_adapter->save(
132
                        $item->get(),             // value to store
133
                        $item->getKey(),          // its key
134 34
                        null,                     // disable tags support
135
                        is_null($ttl) ? 0 : $ttl  // ttl in sec or null forever
136 34
                    );
137
        $item->setHit($success);
138 34
139
        return $success;
140
    }
141
142
    /**
143
     * {@inheritdoc}
144 34
     */
145
    public function saveDeferred(ItemInterface $item)
146 34
    {
147 34
        $this->deferred[$item->getKey()] = $item;
148 34
149 34
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this; (Apix\Cache\PsrCache\Pool) is incompatible with the return type declared by the interface Psr\Cache\CacheItemPoolInterface::saveDeferred of type boolean.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

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

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
150 34
    }
151 34
152
    /**
153 34
     * {@inheritdoc}
154
     */
155
    public function commit()
156
    {
157
        foreach ($this->deferred as $key => $item) {
158
            $this->save($item);
159
            if ( $item->isHit() ) {
160
                unset($this->deferred[$key]);
161 289
            }
162
        }
163 289
164
        return empty($this->deferred);
165
    }
166
167 17
    /**
168
     * Returns the cache adapter for this pool.
169
     *
170
     * @return CacheAdapter
171
     */
172
    public function getCacheAdapter()
173
    {
174
        return $this->cache_adapter;
175
    }
176
177
    /**
178
     * Commit the deferred items ~ acts as the last resort garbage collector.
179
     */
180
    public function __destruct()
181
    {
182
        $this->commit();
183
    }
184
185
}
186