Completed
Push — V6 ( 3487d5...56e1e4 )
by Georges
02:48
created

Driver   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 112
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 112
loc 112
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 3

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 2
A driverCheck() 4 4 1
A driverWrite() 11 11 2
A driverRead() 8 8 1
A driverDelete() 11 11 2
A driverClear() 4 4 1
A driverConnect() 4 4 1
A getStats() 10 10 1

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\Devfalse;
16
17
use phpFastCache\Core\Pool\DriverBaseTrait;
18
use phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface;
19
use phpFastCache\Entities\driverStatistic;
20
use phpFastCache\Exceptions\phpFastCacheDriverCheckException;
21
use phpFastCache\Exceptions\phpFastCacheDriverException;
22
use Psr\Cache\CacheItemInterface;
23
24
/**
25
 * Class Driver
26
 * @package phpFastCache\Drivers
27
 */
28 View Code Duplication
class Driver implements ExtendedCacheItemPoolInterface
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...
29
{
30
    use DriverBaseTrait;
31
32
    /**
33
     * Driver constructor.
34
     * @param array $config
35
     * @throws phpFastCacheDriverException
36
     */
37
    public function __construct(array $config = [])
38
    {
39
        $this->setup($config);
40
41
        if (!$this->driverCheck()) {
42
            throw new phpFastCacheDriverCheckException(sprintf(self::DRIVER_CHECK_FAILURE, $this->getDriverName()));
43
        }
44
    }
45
46
    /**
47
     * @return bool
48
     */
49
    public function driverCheck()
50
    {
51
        return true;
52
    }
53
54
    /**
55
     * @param \Psr\Cache\CacheItemInterface $item
56
     * @return mixed
57
     * @throws \InvalidArgumentException
58
     */
59
    protected function driverWrite(CacheItemInterface $item)
60
    {
61
        /**
62
         * Check for Cross-Driver type confusion
63
         */
64
        if ($item instanceof Item) {
0 ignored issues
show
Bug introduced by
The class phpFastCache\Drivers\Devfalse\Item does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
65
            return true;
66
        } else {
67
            throw new \InvalidArgumentException('Cross-Driver type confusion detected');
68
        }
69
    }
70
71
    /**
72
     * @param \Psr\Cache\CacheItemInterface $item
73
     * @return array [
74
     *      'd' => 'THE ITEM DATA'
75
     *      't' => 'THE ITEM DATE EXPIRATION'
76
     *      'g' => 'THE ITEM TAGS'
77
     * ]
78
     */
79
    protected function driverRead(CacheItemInterface $item)
1 ignored issue
show
Unused Code introduced by
The parameter $item is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
80
    {
81
        return [
82
          self::DRIVER_DATA_WRAPPER_INDEX => false,
83
          self::DRIVER_TAGS_WRAPPER_INDEX => [],
84
          self::DRIVER_TIME_WRAPPER_INDEX => new \DateTime(),
85
        ];
86
    }
87
    /**
88
     * @param \Psr\Cache\CacheItemInterface $item
89
     * @return bool
90
     * @throws \InvalidArgumentException
91
     */
92
    protected function driverDelete(CacheItemInterface $item)
93
    {
94
        /**
95
         * Check for Cross-Driver type confusion
96
         */
97
        if ($item instanceof Item) {
0 ignored issues
show
Bug introduced by
The class phpFastCache\Drivers\Devfalse\Item does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
98
            return true;
99
        } else {
100
            throw new \InvalidArgumentException('Cross-Driver type confusion detected');
101
        }
102
    }
103
104
    /**
105
     * @return bool
106
     */
107
    protected function driverClear()
108
    {
109
        return true;
110
    }
111
112
    /**
113
     * @return bool
114
     */
115
    protected function driverConnect()
116
    {
117
        return true;
118
    }
119
120
    /********************
121
     *
122
     * PSR-6 Extended Methods
123
     *
124
     *******************/
125
126
    /**
127
     * @return driverStatistic
128
     */
129
    public function getStats()
130
    {
131
        $stat = new driverStatistic();
132
        $stat->setInfo('[Devfalse] A void info string')
133
          ->setSize(0)
134
          ->setData(implode(', ', array_keys($this->itemInstances)))
135
          ->setRawData(false);
136
137
        return $stat;
138
    }
139
}