Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Pull Request — master (#801)
by Timur
22:04
created

ClassesTypesMap   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 71
rs 10
wmc 14

7 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 3 1
A searchClassesMapBy() 0 14 4
A resolveType() 0 11 5
A addClassType() 0 3 1
A resolveClass() 0 3 1
A getType() 0 3 1
A hasType() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Config\Parser\MetadataParser;
6
7
class ClassesTypesMap
8
{
9
    /**
10
     * @var array<string, array{class: string, type: string}>
11
     */
12
    protected array $classesMap = [];
13
14
    public function hasType(string $gqlType): bool
15
    {
16
        return isset($this->classesMap[$gqlType]);
17
    }
18
19
    public function getType(string $gqlType): ?array
20
    {
21
        return $this->classesMap[$gqlType] ?? null;
22
    }
23
24
    /**
25
     * Add a class & a type to the map
26
     */
27
    public function addClassType(string $typeName, string $className, string $graphQLType): void
28
    {
29
        $this->classesMap[$typeName] = ['class' => $className, 'type' => $graphQLType];
30
    }
31
32
    /**
33
     * Resolve the type associated with given class name
34
     */
35
    public function resolveType(string $className, array $filteredTypes = []): ?string
36
    {
37
        foreach ($this->classesMap as $gqlType => $config) {
38
            if ($config['class'] === $className) {
39
                if (empty($filteredTypes) || in_array($config['type'], $filteredTypes)) {
40
                    return $gqlType;
41
                }
42
            }
43
        }
44
45
        return null;
46
    }
47
48
    /**
49
     * Resolve the class name associated with given type
50
     */
51
    public function resolveClass(string $typeName): ?string
52
    {
53
        return $this->classesMap[$typeName]['class'] ?? null;
54
    }
55
56
    /**
57
     * Search the classes map for class by predicate.
58
     */
59
    public function searchClassesMapBy(callable $predicate, string $type): array
60
    {
61
        $classNames = [];
62
        foreach ($this->classesMap as $gqlType => $config) {
63
            if ($config['type'] !== $type) {
64
                continue;
65
            }
66
67
            if ($predicate($gqlType, $config)) {
68
                $classNames[$gqlType] = $config;
69
            }
70
        }
71
72
        return $classNames;
73
    }
74
75
    public function toArray(): array
76
    {
77
        return $this->classesMap;
78
    }
79
}
80