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.

Types   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 0
dl 0
loc 91
ccs 36
cts 36
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
B types() 0 28 7
A has() 0 6 1
A get() 0 10 2
A reset() 0 5 1
A ensureTypes() 0 9 4
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Tools\ResourceTestUtilities;
4
5
use Exception;
6
use Generator;
7
use RecursiveDirectoryIterator;
8
use RecursiveIteratorIterator;
9
use ReflectionClass;
10
11
final class Types
12
{
13
    protected static $types = [];
14
15
    /**
16
     * @var bool
17
     */
18
    protected static $doneScanning = false;
19
20
    /**
21
     * @return Generator<Type>
0 ignored issues
show
Documentation introduced by
The doc-type Generator<Type> could not be parsed: Expected "|" or "end of type", but got "<" at position 9. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
22
     */
23 4
    public static function types(): Generator
24
    {
25 4
        if (self::$doneScanning && count(self::$types) > 0) {
26 2
            yield from self::$types;
27
28 2
            return;
29
        }
30
31 2
        $path = __DIR__ . DIRECTORY_SEPARATOR . 'Type' . DIRECTORY_SEPARATOR;
32 2
        $directory = new RecursiveDirectoryIterator($path);
33 2
        $directory = new RecursiveIteratorIterator($directory);
34 2
        foreach ($directory as $node) {
35 2
            $nodePath = $node->getPath() . DIRECTORY_SEPARATOR . $node->getFilename();
36 2
            if (!is_file($nodePath)) {
37 2
                continue;
38
            }
39
40 2
            $fileName = str_replace('/', '\\', $nodePath);
41 2
            $class = __NAMESPACE__ . '\\Type\\' . substr(substr($fileName, strlen($path)), 0, -4);
42 2
            if (class_exists($class) && (new ReflectionClass($class))->implementsInterface(Type::class)) {
43 2
                $type = new $class();
44 2
                self::$types[$type->scalar()] = $type;
45 2
                yield $type;
46
            }
47
        }
48
49 2
        self::$doneScanning = true;
50 2
    }
51
52
    /**
53
     * @param  string $type
54
     * @return bool
55
     */
56 2
    public static function has(string $type): bool
57
    {
58 2
        self::ensureTypes();
59
60 2
        return isset(self::$types[$type]);
61
    }
62
63
    /**
64
     * @param  string    $type
65
     * @throws Exception
66
     * @return Type
67
     */
68 2
    public static function get(string $type): Type
69
    {
70 2
        self::ensureTypes();
71
72 2
        if (isset(self::$types[$type])) {
73 1
            return self::$types[$type];
74
        }
75
76 1
        throw new Exception('Type "' . $type . '" not found, use has to check"');
77
    }
78
79
    /**
80
     * Reset state.
81
     */
82 1
    public static function reset()
83
    {
84 1
        self::$types = [];
85 1
        self::$doneScanning = false;
86 1
    }
87
88
    /**
89
     * A wee bit hacky, but this ensures that when ever `has` or `get` is called before `types`
90
     * all types are detected and available for `has` and `get`.
91
     */
92 4
    protected static function ensureTypes()
93
    {
94 4
        if (self::$doneScanning && count(self::$types) > 0) {
95 3
            return;
96
        }
97
98 1
        foreach (self::types() as $t) {
99
        }
100 1
    }
101
}
102