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 ( 4c3b7e...cb6ff1 )
by Leonardo
03:37
created

ClientFunctionalityModuleResolver::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 10
ccs 0
cts 10
cp 0
crap 2
rs 10
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 PoP\GraphQLClientsForWP\ComponentConfiguration as GraphQLClientsForWPComponentConfiguration;
12
13
/**
14
 * Modules exposing clients to interact with the API
15
 *
16
 * @author Leonardo Losoviz <[email protected]>
17
 */
18
class ClientFunctionalityModuleResolver extends AbstractFunctionalityModuleResolver
19
{
20
    use ModuleResolverTrait;
21
22
    public const GRAPHIQL_FOR_SINGLE_ENDPOINT = Plugin::NAMESPACE . '\graphiql-for-single-endpoint';
23
    public const GRAPHIQL_FOR_CUSTOM_ENDPOINTS = Plugin::NAMESPACE . '\graphiql-for-custom-endpoints';
24
    public const INTERACTIVE_SCHEMA_FOR_SINGLE_ENDPOINT = Plugin::NAMESPACE . '\interactive-schema-for-single-endpoint';
25
    public const INTERACTIVE_SCHEMA_FOR_CUSTOM_ENDPOINTS = Plugin::NAMESPACE . '\interactive-schema-for-custom-endpoints';
26
    public const GRAPHIQL_EXPLORER = Plugin::NAMESPACE . '\graphiql-explorer';
27
28
    public static function getModulesToResolve(): array
29
    {
30
        return [
31
            self::GRAPHIQL_FOR_SINGLE_ENDPOINT,
32
            self::INTERACTIVE_SCHEMA_FOR_SINGLE_ENDPOINT,
33
            self::GRAPHIQL_FOR_CUSTOM_ENDPOINTS,
34
            self::INTERACTIVE_SCHEMA_FOR_CUSTOM_ENDPOINTS,
35
            self::GRAPHIQL_EXPLORER,
36
        ];
37
    }
38
39
    public function getDependedModuleLists(string $module): array
40
    {
41
        switch ($module) {
42
            case self::GRAPHIQL_FOR_SINGLE_ENDPOINT:
43
            case self::INTERACTIVE_SCHEMA_FOR_SINGLE_ENDPOINT:
44
                return [
45
                    [
46
                        FunctionalityModuleResolver::SINGLE_ENDPOINT,
47
                    ],
48
                ];
49
            case self::GRAPHIQL_FOR_CUSTOM_ENDPOINTS:
50
            case self::INTERACTIVE_SCHEMA_FOR_CUSTOM_ENDPOINTS:
51
                return [
52
                    [
53
                        FunctionalityModuleResolver::CUSTOM_ENDPOINTS,
54
                    ],
55
                ];
56
            case self::GRAPHIQL_EXPLORER:
57
                return [
58
                    [
59
                        FunctionalityModuleResolver::PERSISTED_QUERIES,
60
                    ],
61
                ];
62
        }
63
        return parent::getDependedModuleLists($module);
64
    }
65
66
    public function areRequirementsSatisfied(string $module): bool
67
    {
68
        switch ($module) {
69
            case self::GRAPHIQL_FOR_SINGLE_ENDPOINT:
70
            case self::INTERACTIVE_SCHEMA_FOR_SINGLE_ENDPOINT:
71
                /**
72
                 * Permalink structure must be enabled
73
                 */
74
                return !empty(\get_option('permalink_structure'));
75
        }
76
        return parent::areRequirementsSatisfied($module);
77
    }
78
79
    public function getName(string $module): string
80
    {
81
        $names = [
82
            self::GRAPHIQL_FOR_SINGLE_ENDPOINT => \__('GraphiQL for Single Endpoint', 'graphql-api'),
83
            self::GRAPHIQL_FOR_CUSTOM_ENDPOINTS => \__('GraphiQL for Custom Endpoints', 'graphql-api'),
84
            self::INTERACTIVE_SCHEMA_FOR_SINGLE_ENDPOINT => \__('Interactive Schema for Single Endpoint', 'graphql-api'),
85
            self::INTERACTIVE_SCHEMA_FOR_CUSTOM_ENDPOINTS => \__('Interactive Schema for Custom Endpoints', 'graphql-api'),
86
            self::GRAPHIQL_EXPLORER => \__('GraphiQL Explorer', 'graphql-api'),
87
        ];
88
        return $names[$module] ?? $module;
89
    }
90
91
    public function getDescription(string $module): string
92
    {
93
        switch ($module) {
94
            case self::GRAPHIQL_FOR_SINGLE_ENDPOINT:
95
                return \sprintf(
96
                    \__('Make a public GraphiQL client available under <code>%s</code>, to execute queries against the single endpoint. It requires pretty permalinks enabled', 'graphql-api'),
97
                    GraphQLClientsForWPComponentConfiguration::getGraphiQLClientEndpoint()
98
                );
99
            case self::GRAPHIQL_FOR_CUSTOM_ENDPOINTS:
100
                return \__('Enable custom endpoints to be attached their own GraphiQL client, to execute queries against them', 'graphql-api');
101
            case self::INTERACTIVE_SCHEMA_FOR_SINGLE_ENDPOINT:
102
                return \sprintf(
103
                    \__('Make a public Interactive Schema client available under <code>%s</code>, to visualize the schema accessible through the single endpoint. It requires pretty permalinks enabled', 'graphql-api'),
104
                    GraphQLClientsForWPComponentConfiguration::getVoyagerClientEndpoint()
105
                );
106
            case self::INTERACTIVE_SCHEMA_FOR_CUSTOM_ENDPOINTS:
107
                return \__('Enable custom endpoints to be attached their own Interactive schema client, to visualize the custom schema subset', 'graphql-api');
108
            case self::GRAPHIQL_EXPLORER:
109
                return \__('Add the Explorer widget to the GraphiQL client when creating Persisted Queries, to simplify coding the query (by point-and-clicking on the fields)', 'graphql-api');
110
        }
111
        return parent::getDescription($module);
112
    }
113
114
    /**
115
     * Default value for an option set by the module
116
     *
117
     * @param string $module
118
     * @param string $option
119
     * @return mixed Anything the setting might be: an array|string|bool|int|null
120
     */
121
    public function getSettingsDefaultValue(string $module, string $option)
122
    {
123
        $defaultValues = [
124
            self::GRAPHIQL_FOR_SINGLE_ENDPOINT => [
125
                FunctionalityModuleResolver::OPTION_PATH => '/graphiql/',
126
            ],
127
            self::INTERACTIVE_SCHEMA_FOR_SINGLE_ENDPOINT => [
128
                FunctionalityModuleResolver::OPTION_PATH => '/schema/',
129
            ],
130
        ];
131
        return $defaultValues[$module][$option];
132
    }
133
134
    /**
135
     * Array with the inputs to show as settings for the module
136
     *
137
     * @param string $module
138
     * @return array
139
     */
140
    public function getSettings(string $module): array
141
    {
142
        $moduleSettings = parent::getSettings($module);
143
        $moduleRegistry = ModuleRegistryFacade::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $moduleRegistry is dead and can be removed.
Loading history...
144
        // Do the if one by one, so that the SELECT do not get evaluated unless needed
145
        if ($module == self::GRAPHIQL_FOR_SINGLE_ENDPOINT) {
146
            $option = FunctionalityModuleResolver::OPTION_PATH;
147
            $moduleSettings[] = [
148
                Properties::INPUT => $option,
149
                Properties::NAME => $this->getSettingOptionName(
150
                    $module,
151
                    $option
152
                ),
153
                Properties::TITLE => \__('Client path', 'graphql-api'),
154
                Properties::DESCRIPTION => \__('URL path to access the public GraphiQL client', 'graphql-api'),
155
                Properties::TYPE => Properties::TYPE_STRING,
156
            ];
157
        } elseif ($module == self::INTERACTIVE_SCHEMA_FOR_SINGLE_ENDPOINT) {
158
            $option = FunctionalityModuleResolver::OPTION_PATH;
159
            $moduleSettings[] = [
160
                Properties::INPUT => $option,
161
                Properties::NAME => $this->getSettingOptionName(
162
                    $module,
163
                    $option
164
                ),
165
                Properties::TITLE => \__('Client path', 'graphql-api'),
166
                Properties::DESCRIPTION => \__('URL path to access the public Interactive Schema client', 'graphql-api'),
167
                Properties::TYPE => Properties::TYPE_STRING,
168
            ];
169
        }
170
        return $moduleSettings;
171
    }
172
}
173