Passed
Push — master ( 9aa048...898b5e )
by Mattia
04:05
created

UserNotFoundCache   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 3 1
A has() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Minepic\Cache;
6
7
use Cache;
8
use Log;
9
10
class UserNotFoundCache
11
{
12
    private const PREFIX = 'not_found_';
13
    private const TTL = 86400;
14
15
    /**
16
     * @param string $usernameOrUuid
17
     *
18
     * @return bool
19
     */
20
    public static function has(string $usernameOrUuid): bool
21
    {
22
        if (Cache::has(self::PREFIX.\md5($usernameOrUuid))) {
23
            Log::debug('User not found cache hit: '.$usernameOrUuid);
24
25
            return true;
26
        }
27
28
        return false;
29
    }
30
31
    /**
32
     * @param $usernameOrUuid
33
     *
34
     * @return bool
35
     */
36
    public static function add($usernameOrUuid): bool
37
    {
38
        return Cache::add(self::PREFIX.\md5($usernameOrUuid), 1, self::TTL);
39
    }
40
}
41