Cache::read()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 6
rs 10
1
<?php
2
3
/**
4
 * Bluz Framework Component
5
 *
6
 * @copyright Bluz PHP Team
7
 * @link      https://github.com/bluzphp/framework
8
 */
9
10
declare(strict_types=1);
11
12
namespace Bluz\Session\Adapter;
13
14
use Bluz\Common\Exception\ConfigurationException;
15
use Bluz\Proxy;
16
17
/**
18
 * Cache session handler
19
 *
20
 * @package Bluz\Session\Adapter
21
 */
22
class Cache extends AbstractAdapter implements \SessionHandlerInterface
23
{
24
    /**
25
     * Check and setup Redis server
26
     *
27
     * @param  array $settings
28
     *
29
     * @throws ConfigurationException
30
     */
31
    public function __construct(array $settings = [])
0 ignored issues
show
Unused Code introduced by
The parameter $settings is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

31
    public function __construct(/** @scrutinizer ignore-unused */ array $settings = [])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
32
    {
33
        if (!Proxy\Cache::getInstance()) {
34
            throw new ConfigurationException(
35
                'Cache configuration is missed or disabled. Please check `cache` configuration section'
36
            );
37
        }
38
    }
39
40
    /**
41
     * Read session data
42
     *
43
     * @param  string $id
44
     *
45
     * @return string
46
     * @throws \Psr\Cache\InvalidArgumentException
47
     */
48
    public function read($id): string
49
    {
50
        return Proxy\Cache::get($this->prepareId($id)) ?: '';
51
    }
52
53
    /**
54
     * Write session data
55
     *
56
     * @param  string $id
57
     * @param  string $data
58
     *
59
     * @return bool
60
     * @throws \Psr\Cache\InvalidArgumentException
61
     */
62
    public function write($id, $data): bool
63
    {
64
        return Proxy\Cache::set($this->prepareId($id), $data, $this->ttl);
65
    }
66
67
    /**
68
     * Destroy a session
69
     *
70
     * @param  integer $id
71
     *
72
     * @return bool
73
     */
74
    public function destroy($id): bool
75
    {
76
        return Proxy\Cache::delete($this->prepareId($id));
77
    }
78
}
79