Passed
Pull Request — master (#838)
by Georges
03:44 queued 01:36
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
declare(strict_types=1);
15
16
namespace Phpfastcache\Drivers\Devrandom;
17
18
use DateInterval;
19
use DateTime;
20
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
21
use Phpfastcache\Core\Pool\TaggableCacheItemPoolTrait;
22
use Phpfastcache\Entities\DriverStatistic;
23
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
24
use Psr\Cache\CacheItemInterface;
25
26
/**
27
 * @property Config $config Return the config object
28
 */
29
class Driver implements ExtendedCacheItemPoolInterface
30
{
31
    use TaggableCacheItemPoolTrait;
32
33
    /**
34
     * @return bool
35
     */
36
    public function driverCheck(): bool
37
    {
38
        return true;
39
    }
40
41
    /**
42
     * @return DriverStatistic
43
     */
44
    public function getStats(): DriverStatistic
45
    {
46
        $stat = new DriverStatistic();
47
        $stat->setInfo('[Devrandom] A void info string')
48
            ->setSize(0)
49
            ->setData(implode(', ', array_keys($this->itemInstances)))
50
            ->setRawData(false);
51
52
        return $stat;
53
    }
54
55
    /**
56
     * @param CacheItemInterface $item
57
     * @return bool
58
     * @throws PhpfastcacheInvalidArgumentException
59
     */
60
    protected function driverWrite(CacheItemInterface $item): bool
61
    {
62
        $this->assertCacheItemType($item, Item::class);
63
64
        return true;
65
    }
66
67
    /**
68
     * @param CacheItemInterface $item
69
     * @return array
70
     */
71
    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

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