GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

functions.php ➔ once()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 4
nop 1
dl 0
loc 28
rs 9.472
c 0
b 0
f 0
1
<?php
2
3
use Spatie\Once\Backtrace;
4
use Spatie\Once\Cache;
5
6
function once($callback)
7
{
8
    $trace = debug_backtrace(
9
        DEBUG_BACKTRACE_PROVIDE_OBJECT, 2
10
    );
11
12
    $backtrace = new Backtrace($trace);
13
14
    if ($backtrace->getFunctionName() === 'eval') {
15
        return call_user_func($callback);
16
    }
17
18
    $object = $backtrace->getObject();
19
20
    $hash = $backtrace->getHash();
21
22
    if (! Cache::isEnabled()) {
23
        return call_user_func($callback, $backtrace->getArguments());
24
    }
25
26
    if (! Cache::has($object, $hash)) {
27
        $result = call_user_func($callback, $backtrace->getArguments());
28
29
        Cache::set($object, $hash, $result);
30
    }
31
32
    return Cache::get($object, $hash);
33
}
34