Passed
Pull Request — master (#838)
by Georges
01:55
created

DriverPoolAbstractTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A assertCacheItemType() 0 5 2
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\Core\Pool;
17
18
use Phpfastcache\Core\Item\ExtendedCacheItemInterface;
19
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
20
21
trait DriverPoolAbstractTrait
22
{
23
    /**
24
     * @return bool
25
     */
26
    abstract protected function driverCheck(): bool;
27
28
    /**
29
     * @return bool
30
     */
31
    abstract protected function driverConnect(): bool;
32
33
    /**
34
     * @param ExtendedCacheItemInterface $item
35
     * @return ?array
36
     */
37
    abstract protected function driverRead(ExtendedCacheItemInterface $item): ?array;
38
39
    /**
40
     * @param ExtendedCacheItemInterface $item
41
     * @return bool
42
     */
43
    abstract protected function driverWrite(ExtendedCacheItemInterface $item): bool;
44
45
    /**
46
     * @param ExtendedCacheItemInterface $item
47
     * @return bool
48
     */
49
    abstract protected function driverDelete(ExtendedCacheItemInterface $item): bool;
50
51
    /**
52
     * @return bool
53
     */
54
    abstract protected function driverClear(): bool;
55
56
    /**
57
     * @param ExtendedCacheItemInterface $item
58
     * @param string $expectedClassType
59
     * @throws PhpfastcacheInvalidArgumentException
60
     */
61
    protected function assertCacheItemType(ExtendedCacheItemInterface $item, string $expectedClassType): void
62
    {
63
        if (!($item instanceof $expectedClassType)) {
64
            throw new PhpfastcacheInvalidArgumentException(
65
                \sprintf('Cross-driver type confusion detected: Expected "%s" object, got "%s"', $expectedClassType, $item::class)
66
            );
67
        }
68
    }
69
}
70