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

Item   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 38
loc 38
rs 10
wmc 4
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 11 11 2
A setDriver() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Zendshm;
15
16
use phpFastCache\Cache\ExtendedCacheItemInterface;
17
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
18
use phpFastCache\Cache\ItemBaseTrait;
19
use phpFastCache\Drivers\Zendshm\Driver as ZendSHMDriver;
20
21
/**
22
 * Class Item
23
 * @package phpFastCache\Drivers\Zendshm
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\Zendshm\Driver $driver
32
     * @param $key
33
     * @throws \InvalidArgumentException
34
     */
35
    public function __construct(ZendSHMDriver $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 ZendSHMDriver) {
55
            $this->driver = $driver;
56
57
            return $this;
58
        } else {
59
            throw new \InvalidArgumentException('Invalid driver instance');
60
        }
61
    }
62
}