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 ( 5f2c26...67714c )
by Leonardo
11:03
created

isHidden()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 0
cts 5
cp 0
crap 6
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\Security\UserAuthorization;
10
use GraphQLAPI\GraphQLAPI\ModuleResolvers\ModuleResolverTrait;
11
use GraphQLAPI\GraphQLAPI\ModuleTypeResolvers\ModuleTypeResolver;
12
13
class PluginManagementFunctionalityModuleResolver extends AbstractFunctionalityModuleResolver
14
{
15
    use ModuleResolverTrait;
16
17
    public const SCHEMA_EDITING_ACCESS = Plugin::NAMESPACE . '\schema-editing-access';
18
    public const GENERAL = Plugin::NAMESPACE . '\general';
19
20
    /**
21
     * Setting options
22
     */
23
    public const OPTION_EDITING_ACCESS_SCHEME = 'editing-access-scheme';
24
    public const OPTION_ADD_RELEASE_NOTES_ADMIN_NOTICE = 'add-release-notes-admin-notice';
25
26
    /**
27
     * @return string[]
28
     */
29
    public static function getModulesToResolve(): array
30
    {
31
        return [
32
            self::GENERAL,
33
            self::SCHEMA_EDITING_ACCESS,
34
        ];
35
    }
36
37
    /**
38
     * Enable to customize a specific UI for the module
39
     */
40
    public function getModuleType(string $module): string
41
    {
42
        return ModuleTypeResolver::PLUGIN_MANAGEMENT;
43
    }
44
45
    public function canBeDisabled(string $module): bool
46
    {
47
        switch ($module) {
48
            case self::GENERAL:
49
                return false;
50
        }
51
        return parent::canBeDisabled($module);
52
    }
53
54
    public function isHidden(string $module): bool
55
    {
56
        switch ($module) {
57
            case self::GENERAL:
58
                return true;
59
        }
60
        return parent::isHidden($module);
61
    }
62
63
    public function getName(string $module): string
64
    {
65
        $names = [
66
            self::SCHEMA_EDITING_ACCESS => \__('Schema Editing Access', 'graphql-api'),
67
            self::GENERAL => \__('General', 'graphql-api'),
68
        ];
69
        return $names[$module] ?? $module;
70
    }
71
72
    public function getDescription(string $module): string
73
    {
74
        switch ($module) {
75
            case self::SCHEMA_EDITING_ACCESS:
76
                return \__('Grant access to users other than admins to edit the GraphQL schema', 'graphql-api');
77
            case self::GENERAL:
78
                return \__('General options for the plugin', 'graphql-api');
79
        }
80
        return parent::getDescription($module);
81
    }
82
83
    /**
84
     * Default value for an option set by the module
85
     *
86
     * @param string $module
87
     * @param string $option
88
     * @return mixed Anything the setting might be: an array|string|bool|int|null
89
     */
90
    public function getSettingsDefaultValue(string $module, string $option)
91
    {
92
        $defaultValues = [
93
            self::SCHEMA_EDITING_ACCESS => [
94
                self::OPTION_EDITING_ACCESS_SCHEME => UserAuthorization::ACCESS_SCHEME_ADMIN_ONLY,
95
            ],
96
            self::GENERAL => [
97
                self::OPTION_ADD_RELEASE_NOTES_ADMIN_NOTICE => true,
98
            ],
99
        ];
100
        return $defaultValues[$module][$option];
101
    }
102
103
    /**
104
     * Array with the inputs to show as settings for the module
105
     *
106
     * @return array<array> List of settings for the module, each entry is an array with property => value
107
     */
108
    public function getSettings(string $module): array
109
    {
110
        $moduleSettings = parent::getSettings($module);
111
        // Do the if one by one, so that the SELECT do not get evaluated unless needed
112
        if ($module == self::SCHEMA_EDITING_ACCESS) {
113
            /**
114
             * Write Access Scheme
115
             * If `"admin"`, only the admin can compose a GraphQL query and endpoint
116
             * If `"post"`, the workflow from creating posts is employed (i.e. Author role can create
117
             * but not publish the query, Editor role can publish it, etc)
118
             */
119
            $option = self::OPTION_EDITING_ACCESS_SCHEME;
120
            $moduleSettings[] = [
121
                Properties::INPUT => $option,
122
                Properties::NAME => $this->getSettingOptionName(
123
                    $module,
124
                    $option
125
                ),
126
                Properties::TITLE => \__('Editing Access Scheme', 'graphql-api'),
127
                Properties::DESCRIPTION => \__('Scheme to decide which users can edit the schema (Persisted Queries, Custom Endpoints and related post types) and with what permissions', 'graphql-api'),
128
                Properties::TYPE => Properties::TYPE_STRING,
129
                Properties::POSSIBLE_VALUES => [
130
                    UserAuthorization::ACCESS_SCHEME_ADMIN_ONLY => \__('Admin user(s) only', 'graphql-api'),
131
                    UserAuthorization::ACCESS_SCHEME_POST => \__('Use same access workflow as for editing posts', 'graphql-api'),
132
                ],
133
            ];
134
        } elseif ($module == self::GENERAL) {
135
            $option = self::OPTION_ADD_RELEASE_NOTES_ADMIN_NOTICE;
136
            $moduleSettings[] = [
137
                Properties::INPUT => $option,
138
                Properties::NAME => $this->getSettingOptionName(
139
                    $module,
140
                    $option
141
                ),
142
                Properties::TITLE => \__('Display admin notice with release notes?', 'graphql-api'),
143
                Properties::DESCRIPTION => \__('Immediately after upgrading the plugin, show an admin notice with a link to the latest release notes?', 'graphql-api'),
144
                Properties::TYPE => Properties::TYPE_BOOL,
145
            ];
146
        }
147
        return $moduleSettings;
148
    }
149
}
150