Completed
Push — v5.1 ( ad5c2c...2ab2d0 )
by Georges
03:22
created

Item::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 8
c 1
b 0
f 1
nc 2
nop 2
dl 11
loc 11
rs 9.4285
1
<?php
2
/**
3
 *
4
 * This file is part of phpFastCache.
5
 *
6
 * @license MIT License (MIT)
7
 *
8
 * For full copyright and license information, please see the docs/CREDITS.txt file.
9
 *
10
 * @author Lucas Brucksch <[email protected]>
11
 *
12
 */
13
14
namespace phpFastCache\Drivers\Zenddisk;
15
16
use phpFastCache\Cache\ExtendedCacheItemInterface;
17
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
18
use phpFastCache\Cache\ItemBaseTrait;
19
use phpFastCache\Drivers\Zenddisk\Driver as ZendDiskDriver;
20
21
/**
22
 * Class Item
23
 * @package phpFastCache\Drivers\Zenddisk
24
 */
25 View Code Duplication
class Item implements ExtendedCacheItemInterface
1 ignored issue
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
{
27
    use ItemBaseTrait;
28
29
    /**
30
     * Item constructor.
31
     * @param \phpFastCache\Drivers\Zenddisk\Driver $driver
32
     * @param $key
33
     * @throws \InvalidArgumentException
34
     */
35
    public function __construct(ZendDiskDriver $driver, $key)
36
    {
37
        if (is_string($key)) {
38
            $this->key = $key;
39
            $this->driver = $driver;
40
            $this->driver->setItem($this);
41
            $this->expirationDate = new \DateTime();
42
        } else {
43
            throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
44
        }
45
    }
46
47
    /**
48
     * @param ExtendedCacheItemPoolInterface $driver
49
     * @throws \InvalidArgumentException
50
     * @return static
51
     */
52
    public function setDriver(ExtendedCacheItemPoolInterface $driver)
53
    {
54
        if ($driver instanceof ZendDiskDriver) {
55
            $this->driver = $driver;
56
57
            return $this;
58
        } else {
59
            throw new \InvalidArgumentException('Invalid driver instance');
60
        }
61
    }
62
}