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.

CallbackEnumTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 26
ccs 10
cts 10
cp 1
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 7 2
A resolve() 0 8 3
1
<?php
2
declare(strict_types=1);
3
namespace Thunder\Platenum\Enum;
4
5
use Thunder\Platenum\Exception\PlatenumException;
6
7
/**
8
 * @template TMember
9
 * @template TValue
10
 *
11
 * @author Tomasz Kowalczyk <[email protected]>
12 1
 */
13
trait CallbackEnumTrait
14
{
15
    /** @use EnumTrait<TMember,TValue> */
16
    use EnumTrait;
17
18 2
    /** @var non-empty-array<class-string,callable():array<string,int|string>> */
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-array<class-st...ray<string,int|string>> at position 0 could not be parsed: Unknown type name 'non-empty-array' at position 0 in non-empty-array<class-string,callable():array<string,int|string>>.
Loading history...
19
    protected static $callbacks = [];
20 2
21 1
    /** @param callable():array<string,int|string> $callback */
22
    final public static function initialize(callable $callback): void
23
    {
24 2
        if(array_key_exists(static::class, static::$callbacks)) {
25 2
            throw PlatenumException::fromAlreadyInitializedCallback(static::class);
26
        }
27 3
28
        static::$callbacks[static::class] = $callback;
29 3
    }
30 3
31 2
    private static function resolve(): array
32
    {
33
        $class = static::class;
34 1
        if(false === (array_key_exists($class, static::$callbacks) && is_callable(static::$callbacks[$class]))) {
35
            throw PlatenumException::fromInvalidCallback($class);
36
        }
37
38
        return (static::$callbacks[$class])();
39
    }
40
}
41