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 ( 4e8bcc...f06828 )
by Leonardo
06:33 queued 03:37
created

getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
ccs 0
cts 6
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQLAPI\GraphQLAPI\ModuleResolvers;
6
7
use GraphQLAPI\GraphQLAPI\Plugin;
8
use GraphQLAPI\GraphQLAPI\ModuleSettings\Properties;
9
use GraphQLAPI\GraphQLAPI\Facades\ModuleRegistryFacade;
10
use GraphQLAPI\GraphQLAPI\ModuleResolvers\ModuleResolverTrait;
11
use GraphQLAPI\GraphQLAPI\PostTypes\GraphQLSchemaConfigurationPostType;
12
13
class SchemaConfigurationFunctionalityModuleResolver extends AbstractFunctionalityModuleResolver
14
{
15
    use ModuleResolverTrait;
16
17
    public const SCHEMA_CONFIGURATION = Plugin::NAMESPACE . '\schema-configuration';
18
19
    /**
20
     * Setting options
21
     */
22
    public const OPTION_SCHEMA_CONFIGURATION_ID = 'schema-configuration-id';
23
24
    /**
25
     * Setting option values
26
     */
27
    public const OPTION_VALUE_NO_VALUE_ID = 0;
28
29
    public static function getModulesToResolve(): array
30
    {
31
        return [
32
            self::SCHEMA_CONFIGURATION,
33
        ];
34
    }
35
36
    public function getDependedModuleLists(string $module): array
37
    {
38
        switch ($module) {
39
            case self::SCHEMA_CONFIGURATION:
40
                return [
41
                    [
42
                        EndpointFunctionalityModuleResolver::PERSISTED_QUERIES,
43
                        EndpointFunctionalityModuleResolver::CUSTOM_ENDPOINTS,
44
                    ],
45
                ];
46
        }
47
        return parent::getDependedModuleLists($module);
48
    }
49
50
    public function getName(string $module): string
51
    {
52
        $names = [
53
            self::SCHEMA_CONFIGURATION => \__('Schema Configuration', 'graphql-api'),
54
        ];
55
        return $names[$module] ?? $module;
56
    }
57
58
    public function getDescription(string $module): string
59
    {
60
        switch ($module) {
61
            case self::SCHEMA_CONFIGURATION:
62
                return \__('Customize the schema accessible to different Custom Endpoints and Persisted Queries, by applying a custom configuration (involving namespacing, access control, cache control, and others) to the grand schema', 'graphql-api');
63
        }
64
        return parent::getDescription($module);
65
    }
66
67
    /**
68
     * Default value for an option set by the module
69
     *
70
     * @param string $module
71
     * @param string $option
72
     * @return mixed Anything the setting might be: an array|string|bool|int|null
73
     */
74
    public function getSettingsDefaultValue(string $module, string $option)
75
    {
76
        $defaultValues = [
77
            self::SCHEMA_CONFIGURATION => [
78
                self::OPTION_SCHEMA_CONFIGURATION_ID => self::OPTION_VALUE_NO_VALUE_ID,
79
            ],
80
        ];
81
        return $defaultValues[$module][$option];
82
    }
83
84
    /**
85
     * Array with the inputs to show as settings for the module
86
     *
87
     * @param string $module
88
     * @return array
89
     */
90
    public function getSettings(string $module): array
91
    {
92
        $moduleSettings = parent::getSettings($module);
93
        $moduleRegistry = ModuleRegistryFacade::getInstance();
94
        // Do the if one by one, so that the SELECT do not get evaluated unless needed
95
        if ($module == self::SCHEMA_CONFIGURATION) {
96
            $whereModules = [];
97
            $maybeWhereModules = [
98
                EndpointFunctionalityModuleResolver::CUSTOM_ENDPOINTS,
99
                EndpointFunctionalityModuleResolver::PERSISTED_QUERIES,
100
            ];
101
            foreach ($maybeWhereModules as $maybeWhereModule) {
102
                if ($moduleRegistry->isModuleEnabled($maybeWhereModule)) {
103
                    $whereModules[] = '▹ ' . $this->getName($maybeWhereModule);
104
                }
105
            }
106
            // Build all the possible values by fetching all the Schema Configuration posts
107
            $possibleValues = [
108
                self::OPTION_VALUE_NO_VALUE_ID => \__('None', 'graphql-api'),
109
            ];
110
            if ($customPosts = \get_posts([
111
                    'posts_per_page' => -1,
112
                    'post_type' => GraphQLSchemaConfigurationPostType::POST_TYPE,
113
                    'post_status' => 'publish',
114
                ])
115
            ) {
116
                foreach ($customPosts as $customPost) {
117
                    $possibleValues[$customPost->ID] = $customPost->post_title;
118
                }
119
            }
120
            $option = self::OPTION_SCHEMA_CONFIGURATION_ID;
121
            $moduleSettings[] = [
122
                Properties::INPUT => $option,
123
                Properties::NAME => $this->getSettingOptionName(
124
                    $module,
125
                    $option
126
                ),
127
                Properties::TITLE => \__('Default Schema Configuration', 'graphql-api'),
128
                Properties::DESCRIPTION => sprintf(
129
                    \__('Schema Configuration to use when option <code>"Default"</code> is selected (in %s)', 'graphql-api'),
130
                    implode(
131
                        \__(', ', 'graphql-api'),
132
                        $whereModules
133
                    )
134
                ),
135
                Properties::TYPE => Properties::TYPE_INT,
136
                // Fetch all Schema Configurations from the DB
137
                Properties::POSSIBLE_VALUES => $possibleValues,
138
            ];
139
        }
140
        return $moduleSettings;
141
    }
142
}
143