GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ItemPool::save()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the O2System Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Cache\Adapters\Wincache;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Cache\Item;
19
use Psr\Cache\CacheItemInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Cache\CacheItemInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Psr\Cache\CacheItemPoolInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Cache\CacheItemPoolInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use O2System\Spl\Exceptions\Logic\InvalidArgumentException;
22
23
/**
24
 * Class ItemPool
25
 *
26
 * @package O2System\Cache\Adapters\File
27
 */
28
class ItemPool extends Adapter implements CacheItemPoolInterface
29
{
30
    /**
31
     * ItemPool::getItems
32
     *
33
     * Returns a traversable set of cache items.
34
     *
35
     * @param string[] $keys
36
     *   An indexed array of keys of items to retrieve.
37
     *
38
     * @throws InvalidArgumentException
39
     *   If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException
40
     *   MUST be thrown.
41
     *
42
     * @return array|\Traversable
43
     *   A traversable collection of Cache Items keyed by the cache keys of
44
     *   each item. A Cache item will be returned for each key, even if that
45
     *   key is not found. However, if no keys are specified then an empty
46
     *   traversable MUST be returned instead.
47
     */
48
    public function getItems(array $keys = [])
49
    {
50
        if ( ! is_array($keys)) {
0 ignored issues
show
introduced by
The condition is_array($keys) is always true.
Loading history...
51
            throw new InvalidArgumentException('E_INVALID_ARGUMENT_ARRAY_CACHE_EXCEPTION');
52
        }
53
54
        $items = [];
55
56
        if (empty($keys)) {
57
            $ucacheInfo = wincache_ucache_info(false);
58
59
            foreach ($ucacheInfo[ 'ucache_entries' ] as $item) {
60
                $items[] = $this->getItem(str_replace($this->prefixKey, '', $item[ 'key_name' ]));
61
            }
62
        } elseif (count($keys)) {
63
            foreach ($keys as $key) {
64
                $items[] = $this->getItem($key);
65
            }
66
        }
67
68
        return $items;
69
    }
70
71
    // ------------------------------------------------------------------------
72
73
    /**
74
     * ItemPool::getKey
75
     *
76
     * Returns a Cache Item representing the specified key.
77
     *
78
     * This method must always return a CacheItemInterface object, even in case of
79
     * a cache miss. It MUST NOT return null.
80
     *
81
     * @param string $key
82
     *   The key for which to return the corresponding Cache Item.
83
     *
84
     * @throws InvalidArgumentException
85
     *   If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
86
     *   MUST be thrown.
87
     *
88
     * @return CacheItemInterface
89
     *   The corresponding Cache Item.
90
     */
91
    public function getItem($key)
92
    {
93
        if ( ! is_string($key)) {
0 ignored issues
show
introduced by
The condition is_string($key) is always true.
Loading history...
94
            throw new InvalidArgumentException('E_INVALID_ARGUMENT_STRING_CACHE_EXCEPTION');
95
        }
96
97
        $success = false;
98
99
        $metadata = wincache_ucache_get($this->prefixKey . $key, $success);
100
101
        return new Item($key, $metadata);
102
    }
103
104
    // ------------------------------------------------------------------------
105
106
    /**
107
     * ItemPool::hasItem
108
     *
109
     * Confirms if the cache contains specified cache item.
110
     *
111
     * Note: This method MAY avoid retrieving the cached value for performance reasons.
112
     * This could result in a race condition with CacheItemInterface::get(). To avoid
113
     * such situation use CacheItemInterface::isHit() instead.
114
     *
115
     * @param string $key
116
     *   The key for which to check existence.
117
     *
118
     * @throws InvalidArgumentException
119
     *   If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
120
     *   MUST be thrown.
121
     *
122
     * @return bool
123
     *   True if item exists in the cache, false otherwise.
124
     */
125
    public function hasItem($key)
126
    {
127
        if ( ! is_string($key)) {
0 ignored issues
show
introduced by
The condition is_string($key) is always true.
Loading history...
128
            throw new InvalidArgumentException('E_INVALID_ARGUMENT_STRING_CACHE_EXCEPTION');
129
        }
130
131
        return (bool)wincache_ucache_exists($this->prefixKey . $key);
132
    }
133
134
    // ------------------------------------------------------------------------
135
136
    /**
137
     * ItemPool::clear
138
     *
139
     * Deletes all items in the pool.
140
     *
141
     * @return bool
142
     *   True if the pool was successfully cleared. False if there was an error.
143
     */
144
    public function clear()
145
    {
146
        return (bool)wincache_ucache_clear();
147
    }
148
149
    // ------------------------------------------------------------------------
150
151
    /**
152
     * ItemPool::deleteItem
153
     *
154
     * Removes the item from the pool.
155
     *
156
     * @param string $key
157
     *   The key to delete.
158
     *
159
     * @throws InvalidArgumentException
160
     *   If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
161
     *   MUST be thrown.
162
     *
163
     * @return bool
164
     *   True if the item was successfully removed. False if there was an error.
165
     */
166
    public function deleteItem($key)
167
    {
168
        if ( ! is_string($key)) {
0 ignored issues
show
introduced by
The condition is_string($key) is always true.
Loading history...
169
            throw new InvalidArgumentException('E_INVALID_ARGUMENT_STRING_CACHE_EXCEPTION');
170
        }
171
172
        return (bool)wincache_ucache_delete($this->prefixKey . $key);
173
    }
174
175
    // ------------------------------------------------------------------------
176
177
    /**
178
     * ItemPool::save
179
     *
180
     * Persists a cache item immediately.
181
     *
182
     * @param CacheItemInterface $item
183
     *   The cache item to save.
184
     *
185
     * @return bool
186
     *   True if the item was successfully persisted. False if there was an error.
187
     */
188
    public function save(CacheItemInterface $item)
189
    {
190
        $metadata = $item->getMetadata();
191
        $metadata[ 'data' ] = $item->get();
192
193
        return wincache_ucache_set($this->prefixKey . $item->getKey(), $metadata, $metadata[ 'ttl' ]);
194
    }
195
}