Completed
Branch final (ad8b8d)
by Georges
03:08 queued 28s
created

Item   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

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 Khoa Bui (khoaofgod)  <[email protected]> http://www.phpfastcache.com
11
 * @author Georges.L (Geolim4)  <[email protected]>
12
 *
13
 */
14
15
namespace phpFastCache\Drivers\Couchbase;
16
17
use phpFastCache\Cache\ExtendedCacheItemInterface;
18
use phpFastCache\Cache\ExtendedCacheItemPoolInterface;
19
use phpFastCache\Cache\ItemBaseTrait;
20
use phpFastCache\Drivers\Couchbase\Driver as CouchbaseDriver;
21
22
/**
23
 * Class Item
24
 * @package phpFastCache\Drivers\Apc
25
 */
26 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...
27
{
28
    use ItemBaseTrait;
29
30
    /**
31
     * Item constructor.
32
     * @param \phpFastCache\Drivers\Couchbase\Driver $driver
33
     * @param $key
34
     * @throws \InvalidArgumentException
35
     */
36
    public function __construct(CouchbaseDriver $driver, $key)
37
    {
38
        if (is_string($key)) {
39
            $this->key = $key;
40
            $this->driver = $driver;
41
            $this->driver->setItem($this);
42
            $this->expirationDate = new \DateTime();
43
        } else {
44
            throw new \InvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.', gettype($key)));
45
        }
46
    }
47
48
    /**
49
     * @param ExtendedCacheItemPoolInterface $driver
50
     * @throws \InvalidArgumentException
51
     * @return static
52
     */
53
    public function setDriver(ExtendedCacheItemPoolInterface $driver)
54
    {
55
        if ($driver instanceof CouchbaseDriver) {
56
            $this->driver = $driver;
57
58
            return $this;
59
        } else {
60
            throw new \InvalidArgumentException('Invalid driver instance');
61
        }
62
    }
63
}