MemcacheDriverCollisionDetectorTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 28
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A checkCollision() 0 24 4
1
<?php
2
3
/**
4
 *
5
 * This file is part of Phpfastcache.
6
 *
7
 * @license MIT License (MIT)
8
 *
9
 * For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files.
10
 *
11
 * @author Georges.L (Geolim4)  <[email protected]>
12
 * @author Contributors  https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
13
 */
14
15
declare(strict_types=1);
16
17
namespace Phpfastcache\Util;
18
19
trait MemcacheDriverCollisionDetectorTrait
20
{
21
    protected static string $driverUsed;
22
23
    public static function checkCollision(string $driverName): bool
24
    {
25
        $constantName = __NAMESPACE__ . '\MEMCACHE_DRIVER_USED';
26
27
        if ($driverName) {
28
            if (!defined($constantName)) {
29
                define($constantName, $driverName);
30
31
                return true;
32
            }
33
34
            if (constant($constantName) !== $driverName) {
35
                trigger_error(
36
                    'Memcache collision detected, you used both Memcache and Memcached driver in your script, this may leads to unexpected behaviours',
37
                    E_USER_WARNING
38
                );
39
40
                return false;
41
            }
42
43
            return true;
44
        }
45
46
        return false;
47
    }
48
}
49