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.
Passed
Push — master ( c30996...045419 )
by Leonardo
03:04
created

PerformanceFunctionalityModuleResolver   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 53
dl 0
loc 115
ccs 0
cts 83
cp 0
rs 10
c 0
b 0
f 0
wmc 13

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getModulesToResolve() 0 6 1
A getDescription() 0 11 4
A getName() 0 8 1
A getDependedModuleLists() 0 26 4
A getSettings() 0 19 2
A getSettingsDefaultValue() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQLAPI\GraphQLAPI\ModuleResolvers;
6
7
use GraphQLAPI\GraphQLAPI\Plugin;
8
use GraphQLAPI\GraphQLAPI\Facades\ModuleRegistryFacade;
9
use GraphQLAPI\GraphQLAPI\ModuleResolvers\ModuleResolverTrait;
10
use GraphQLAPI\GraphQLAPI\ModuleResolvers\AccessControlFunctionalityModuleResolver;
11
use GraphQLAPI\GraphQLAPI\ModuleSettings\Properties;
12
13
/**
14
 * The cache modules have different behavior depending on the environment:
15
 * - "development": visible, disabled by default
16
 * - "production": hidden, enabled by default
17
 *
18
 * @author Leonardo Losoviz <[email protected]>
19
 */
20
class PerformanceFunctionalityModuleResolver extends AbstractCacheFunctionalityModuleResolver
21
{
22
    use ModuleResolverTrait;
23
24
    public const CACHE_CONTROL = Plugin::NAMESPACE . '\cache-control';
25
    public const CONFIGURATION_CACHE = Plugin::NAMESPACE . '\configuration-cache';
26
    public const SCHEMA_CACHE = Plugin::NAMESPACE . '\schema-cache';
27
28
    /**
29
     * Setting options
30
     */
31
    public const OPTION_MAX_AGE = 'max-age';
32
33
    public static function getModulesToResolve(): array
34
    {
35
        return [
36
            self::CACHE_CONTROL,
37
            self::CONFIGURATION_CACHE,
38
            self::SCHEMA_CACHE,
39
        ];
40
    }
41
42
    public function getDependedModuleLists(string $module): array
43
    {
44
        switch ($module) {
45
            case self::CACHE_CONTROL:
46
                return [
47
                    [
48
                        FunctionalityModuleResolver::SCHEMA_CONFIGURATION,
49
                    ],
50
                    [
51
                        FunctionalityModuleResolver::PERSISTED_QUERIES,
52
                    ],
53
                ];
54
            case self::CONFIGURATION_CACHE:
55
                return [];
56
            case self::SCHEMA_CACHE:
57
                $moduleRegistry = ModuleRegistryFacade::getInstance();
58
                return [
59
                    [
60
                        self::CONFIGURATION_CACHE,
61
                    ],
62
                    [
63
                        $moduleRegistry->getInverseDependency(AccessControlFunctionalityModuleResolver::PUBLIC_PRIVATE_SCHEMA),
64
                    ],
65
                ];
66
        }
67
        return parent::getDependedModuleLists($module);
68
    }
69
70
    public function getName(string $module): string
71
    {
72
        $names = [
73
            self::CACHE_CONTROL => \__('Cache Control', 'graphql-api'),
74
            self::CONFIGURATION_CACHE => \__('Configuration Cache', 'graphql-api'),
75
            self::SCHEMA_CACHE => \__('Schema Cache', 'graphql-api'),
76
        ];
77
        return $names[$module] ?? $module;
78
    }
79
80
    public function getDescription(string $module): string
81
    {
82
        switch ($module) {
83
            case self::CACHE_CONTROL:
84
                return \__('Provide HTTP Caching for Persisted Queries, sending the Cache-Control header with a max-age value calculated from all fields in the query', 'graphql-api');
85
            case self::CONFIGURATION_CACHE:
86
                return \__('Cache the generated application configuration to disk', 'graphql-api');
87
            case self::SCHEMA_CACHE:
88
                return \__('Cache the generated schema to disk', 'graphql-api');
89
        }
90
        return parent::getDescription($module);
91
    }
92
93
    /**
94
     * Default value for an option set by the module
95
     *
96
     * @param string $module
97
     * @param string $option
98
     * @return mixed Anything the setting might be: an array|string|bool|int|null
99
     */
100
    public function getSettingsDefaultValue(string $module, string $option)
101
    {
102
        $defaultValues = [
103
            self::CACHE_CONTROL => [
104
                self::OPTION_MAX_AGE => 86400, // 1 day
105
            ],
106
        ];
107
        return $defaultValues[$module][$option];
108
    }
109
110
    /**
111
     * Array with the inputs to show as settings for the module
112
     *
113
     * @param string $module
114
     * @return array
115
     */
116
    public function getSettings(string $module): array
117
    {
118
        $moduleSettings = parent::getSettings($module);
119
        // Do the if one by one, so that the SELECT do not get evaluated unless needed
120
        if ($module == self::CACHE_CONTROL) {
121
            $option = self::OPTION_MAX_AGE;
122
            $moduleSettings[] = [
123
                Properties::INPUT => $option,
124
                Properties::NAME => $this->getSettingOptionName(
125
                    $module,
126
                    $option
127
                ),
128
                Properties::TITLE => \__('Default max-age', 'graphql-api'),
129
                Properties::DESCRIPTION => \__('Default max-age value (in seconds) for the Cache-Control header, for all fields and directives in the schema', 'graphql-api'),
130
                Properties::TYPE => Properties::TYPE_INT,
131
                Properties::MIN_NUMBER => 0,
132
            ];
133
        }
134
        return $moduleSettings;
135
    }
136
}
137