Passed
Push — v9 ( 467cbb...1836cb )
by Georges
03:07 queued 24s
created

Driver::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 *
5
 * This file is part of Phpfastcache.
6
 *
7
 * @license MIT License (MIT)
8
 *
9
 * For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files.
10
 *
11
 * @author Georges.L (Geolim4)  <[email protected]>
12
 * @author Contributors  https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
13
 */
14
15
declare(strict_types=1);
16
17
namespace Phpfastcache\Drivers\Devrandom;
18
19
use DateInterval;
20
use DateTime;
21
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
22
use Phpfastcache\Core\Pool\TaggableCacheItemPoolTrait;
23
use Phpfastcache\Entities\DriverStatistic;
24
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
25
use Psr\Cache\CacheItemInterface;
26
27
/**
28
 * @method Config getConfig()
29
 */
30
class Driver implements ExtendedCacheItemPoolInterface
31
{
32
    use TaggableCacheItemPoolTrait;
33
34
    /**
35
     * @return bool
36
     */
37
    public function driverCheck(): bool
38
    {
39
        return true;
40
    }
41
42
    /**
43
     * @return DriverStatistic
44
     */
45
    public function getStats(): DriverStatistic
46
    {
47
        $stat = new DriverStatistic();
48
        $stat->setInfo('[Devrandom] A void info string')
49
            ->setSize(0)
50
            ->setData(implode(', ', array_keys($this->itemInstances)))
51
            ->setRawData(false);
52
53
        return $stat;
54
    }
55
56
    /**
57
     * @param CacheItemInterface $item
58
     * @return bool
59
     * @throws PhpfastcacheInvalidArgumentException
60
     */
61
    protected function driverWrite(CacheItemInterface $item): bool
62
    {
63
        $this->assertCacheItemType($item, Item::class);
64
65
        return true;
66
    }
67
68
    /**
69
     * @param CacheItemInterface $item
70
     * @return array
71
     */
72
    protected function driverRead(CacheItemInterface $item): ?array
1 ignored issue
show
Unused Code introduced by
The parameter $item 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

72
    protected function driverRead(/** @scrutinizer ignore-unused */ CacheItemInterface $item): ?array

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...
73
    {
74
        $chanceOfRetrieval = $this->getConfig()->getChanceOfRetrieval();
75
        $ttl = $this->getConfig()->getDefaultTtl();
76
77
        if (\random_int(0, 100) < $chanceOfRetrieval) {
78
            return [
79
                self::DRIVER_DATA_WRAPPER_INDEX => \bin2hex(\random_bytes($this->getConfig()->getDataLength())),
80
                self::DRIVER_TAGS_WRAPPER_INDEX => [],
81
                self::DRIVER_EDATE_WRAPPER_INDEX => (new DateTime())->add(new DateInterval("PT{$ttl}S")),
82
            ];
83
        }
84
85
        return null;
86
    }
87
88
    /**
89
     * @param CacheItemInterface $item
90
     * @return bool
91
     * @throws PhpfastcacheInvalidArgumentException
92
     */
93
    protected function driverDelete(CacheItemInterface $item): bool
94
    {
95
        $this->assertCacheItemType($item, Item::class);
96
97
        return true;
98
    }
99
100
    /**
101
     * @return bool
102
     */
103
    protected function driverClear(): bool
104
    {
105
        return true;
106
    }
107
108
    /**
109
     * @return bool
110
     */
111
    protected function driverConnect(): bool
112
    {
113
        return true;
114
    }
115
}
116