Completed
Pull Request — final (#320)
by Georges
02:40
created

CustomMemcachedCacheClass   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
1
<?php
2
3
/**
4
 * @author Khoa Bui (khoaofgod)  <[email protected]> http://www.phpfastcache.com
5
 * @author Georges.L (Geolim4)  <[email protected]>
6
 */
7
8
use phpFastCache\Core\Item\ExtendedCacheItemInterface;
9
use phpFastCache\Drivers\Memcached\Driver as MemcachedDriver;
10
use phpFastCache\Proxy\phpFastCacheAbstractProxy;
11
12
13
chdir(__DIR__);
14
require_once __DIR__ . '/../vendor/autoload.php';
15
16
$status = 0;
17
echo "Testing phpFastCacheAbstractProxy class\n";
18
19
/**
20
 * Dynamic driver-based example
21
 * Class myCustomCacheClass
22
 * @package MyCustom\Project
23
 */
24
class CustomMemcachedCacheClass extends phpFastCacheAbstractProxy
25
{
26
    public function __construct($driver = '', array $config = [])
27
    {
28
        $driver = 'Memcached';
29
        parent::__construct($driver, $config);
30
        /**
31
         * That's all !! Your cache class is ready to use
32
         */
33
    }
34
}
35
36
37
/**
38
 * Testing memcached as it is declared in .travis.yml
39
 */
40
$driverInstance = new CustomMemcachedCacheClass();
41
42 View Code Duplication
if (!is_object($driverInstance->getItem('test'))) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
43
    echo '[FAIL] $driverInstance->getItem() returned an invalid var type:' . gettype($driverInstance) . "\n";
44
    $status = 1;
45
}else if(!($driverInstance->getItem('test') instanceof ExtendedCacheItemInterface)){
0 ignored issues
show
Bug introduced by
The class phpFastCache\Core\Item\ExtendedCacheItemInterface 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...
46
    echo '[FAIL] $driverInstance->getItem() returned an invalid class that does not implements ExtendedCacheItemInterface: ' . get_class($driverInstance) . "\n";
47
    $status = 1;
48
}else{
49
    echo '[PASS] $driverInstance->getItem() returned a valid class that implements ExtendedCacheItemInterface: ' . get_class($driverInstance) . "\n";
50
}
51
52
exit($status);