Completed
Push — final ( 284938...ad8b8d )
by Georges
03:03
created

MemcacheDriverCollisionDetectorTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B checkCollision() 0 21 5
1
<?php
2
namespace phpFastCache\Core;
3
4
/**
5
 * Trait MemcacheDriverCollisionDetectorTrait
6
 * @package phpFastCache\Core
7
 */
8
trait MemcacheDriverCollisionDetectorTrait
9
{
10
    /**
11
     * @var string
12
     */
13
    protected static $driverUsed;
14
15
    /**
16
     * @param $driverName
17
     * @return bool
18
     */
19
    public static function checkCollision($driverName)
20
    {
21
        $CONSTANT_NAME = __NAMESPACE__ . '\MEMCACHE_DRIVER_USED';
22
23
        if ($driverName && is_string($driverName)) {
24
            if (!defined($CONSTANT_NAME)) {
25
                define($CONSTANT_NAME, $driverName);
26
27
                return true;
28
            } else if (constant($CONSTANT_NAME) !== $driverName) {
29
                trigger_error('Memcache collision detected, you used both Memcache and Memcached driver in your script, this may leads to unexpected behaviours',
30
                  E_USER_WARNING);
31
32
                return false;
33
            }
34
35
            return true;
36
        }
37
38
        return false;
39
    }
40
}