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 ( d5a27a...1e0f3a )
by Leonardo
13:55
created

Component::doInitialize()   B

Complexity

Conditions 8
Paths 68

Size

Total Lines 61
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
cc 8
eloc 34
nc 68
nop 3
dl 0
loc 61
rs 8.1315
c 0
b 0
f 0
ccs 0
cts 26
cp 0
crap 72

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQLAPI\GraphQLAPI;
6
7
use GraphQLAPI\GraphQLAPI\Config\ServiceConfiguration;
8
use GraphQLAPI\GraphQLAPI\Container\CompilerPasses\RegisterAccessControlRuleBlockCompilerPass;
9
use GraphQLAPI\GraphQLAPI\Facades\ModuleRegistryFacade;
10
use GraphQLAPI\GraphQLAPI\Facades\UserSettingsManagerFacade;
11
use GraphQLAPI\GraphQLAPI\ModuleResolvers\CacheFunctionalityModuleResolver;
12
use GraphQLAPI\GraphQLAPI\ModuleResolvers\ClientFunctionalityModuleResolver;
13
use GraphQLAPI\GraphQLAPI\ModuleResolvers\PerformanceFunctionalityModuleResolver;
14
use GraphQLAPI\GraphQLAPI\SchemaConfiguratorExecuters\EditingPersistedQuerySchemaConfiguratorExecuter;
15
use GraphQLAPI\GraphQLAPI\SchemaConfiguratorExecuters\EndpointSchemaConfiguratorExecuter;
16
use GraphQLAPI\GraphQLAPI\SchemaConfiguratorExecuters\PersistedQuerySchemaConfiguratorExecuter;
17
use PoP\CacheControl\DirectiveResolvers\CacheControlDirectiveResolver;
18
use PoP\ComponentModel\ComponentConfiguration as ComponentModelComponentConfiguration;
19
use PoP\ComponentModel\ComponentConfiguration\ComponentConfigurationHelpers;
20
use PoP\ComponentModel\Environment as ComponentModelEnvironment;
21
use PoP\ComponentModel\Facades\Engine\DataloadingEngineFacade;
22
use PoP\Root\Component\AbstractComponent;
23
24
/**
25
 * Initialize component
26
 */
27
class Component extends AbstractComponent
28
{
29
    /**
30
     * Classes from PoP components that must be initialized before this component
31
     *
32
     * @return string[]
33
     */
34
    public static function getDependedComponentClasses(): array
35
    {
36
        return [
37 1
            \PoPSchema\GenericCustomPosts\Component::class,
38
            \PoPSchema\CommentMetaWP\Component::class,
39
            \GraphQLByPoP\GraphQLServer\Component::class,
40 1
            \PoPSchema\MediaWP\Component::class,
41
            \PoPSchema\PostsWP\Component::class,
42
            \PoPSchema\PagesWP\Component::class,
43
            \PoPSchema\CustomPostMediaWP\Component::class,
44
            \PoPSchema\CustomPostMetaWP\Component::class,
45
            \PoPSchema\TaxonomyQueryWP\Component::class,
46
            \PoPSchema\PostTagsWP\Component::class,
47
            \PoPSchema\UserRolesAccessControl\Component::class,
48
            \PoPSchema\UserRolesWP\Component::class,
49
            \PoPSchema\UserStateWP\Component::class,
50
            \PoPSchema\UserMetaWP\Component::class,
51
            \PoPSchema\CustomPostMutationsWP\Component::class,
52
            \PoPSchema\PostMutations\Component::class,
53
            \PoPSchema\CustomPostMediaMutationsWP\Component::class,
54
            \PoPSchema\CommentMutationsWP\Component::class,
55
            \PoPSchema\UserStateMutationsWP\Component::class,
56
            \PoPSchema\BasicDirectives\Component::class,
57
            \GraphQLByPoP\GraphQLClientsForWP\Component::class,
58
            \GraphQLByPoP\GraphQLEndpointForWP\Component::class,
59
            \GraphQLAPI\MarkdownConvertor\Component::class,
60
        ];
61
    }
62
63
    /**
64
     * Initialize services
65
     *
66
     * @param array<string, mixed> $configuration
67
     * @param string[] $skipSchemaComponentClasses
68
     */
69
    protected static function doInitialize(
70
        array $configuration = [],
71
        bool $skipSchema = false,
72
        array $skipSchemaComponentClasses = []
73
    ): void {
74
        parent::doInitialize($configuration, $skipSchema, $skipSchemaComponentClasses);
75
        self::initYAMLServices(dirname(__DIR__));
76
        self::initComponentConfiguration();
77
        self::initPHPServices(dirname(__DIR__));
78
        // Override DI services
79
        self::initPHPServices(dirname(__DIR__), '/Overrides');
80
        // Conditional DI settings
81
        /**
82
         * FieldResolvers used to configure the services can also be accessed in the admin area
83
         */
84
        if (\is_admin()) {
85
            self::initPHPServices(dirname(__DIR__), '/ConditionalOnEnvironment/Admin');
86
            self::initPHPServices(dirname(__DIR__), '/ConditionalOnEnvironment/Admin', 'schema-services.php');
87
        }
88
        // Register the Cache services, if the module is not disabled
89
        $moduleRegistry = ModuleRegistryFacade::getInstance();
90
        if ($moduleRegistry->isModuleEnabled(CacheFunctionalityModuleResolver::CONFIGURATION_CACHE)) {
91
            self::initPHPServices(dirname(__DIR__), '/ConditionalOnEnvironment/ConfigurationCache/Overrides');
92
        }
93
        // Maybe use GraphiQL with Explorer
94
        $userSettingsManager = UserSettingsManagerFacade::getInstance();
95
        if ($moduleRegistry->isModuleEnabled(ClientFunctionalityModuleResolver::GRAPHIQL_EXPLORER)) {
96
            if (
97
                $userSettingsManager->getSetting(
98
                    ClientFunctionalityModuleResolver::GRAPHIQL_EXPLORER,
99
                    ClientFunctionalityModuleResolver::OPTION_USE_IN_ADMIN_CLIENT
100
                )
101
            ) {
102
                self::initPHPServices(dirname(__DIR__), '/ConditionalOnEnvironment/GraphiQLExplorerInAdminClient/Overrides');
103
            }
104
            if (
105
                $userSettingsManager->getSetting(
106
                    ClientFunctionalityModuleResolver::GRAPHIQL_EXPLORER,
107
                    ClientFunctionalityModuleResolver::OPTION_USE_IN_ADMIN_PERSISTED_QUERIES
108
                )
109
            ) {
110
                self::initPHPServices(dirname(__DIR__), '/ConditionalOnEnvironment/GraphiQLExplorerInAdminPersistedQueries/Overrides');
111
            }
112
            if (
113
                $userSettingsManager->getSetting(
114
                    ClientFunctionalityModuleResolver::GRAPHIQL_EXPLORER,
115
                    ClientFunctionalityModuleResolver::OPTION_USE_IN_PUBLIC_CLIENT_FOR_SINGLE_ENDPOINT
116
                )
117
            ) {
118
                self::initPHPServices(dirname(__DIR__), '/ConditionalOnEnvironment/GraphiQLExplorerInSingleEndpointPublicClient/Overrides');
119
            }
120
            if (
121
                $userSettingsManager->getSetting(
122
                    ClientFunctionalityModuleResolver::GRAPHIQL_EXPLORER,
123
                    ClientFunctionalityModuleResolver::OPTION_USE_IN_PUBLIC_CLIENT_FOR_CUSTOM_ENDPOINTS
124
                )
125
            ) {
126
                self::initPHPServices(dirname(__DIR__), '/ConditionalOnEnvironment/GraphiQLExplorerInCustomEndpointPublicClient/Overrides');
127
            }
128
        }
129
        ServiceConfiguration::initialize();
130
    }
131
132
    protected static function initComponentConfiguration(): void
133
    {
134
        /**
135
         * Enable the schema entity registries, as to retrieve the type/directive resolver classes
136
         * from the type/directive names, saved in the DB in the ACL/CCL Custom Post Types
137
         */
138
        $hookName = ComponentConfigurationHelpers::getHookName(
139
            ComponentModelComponentConfiguration::class,
140
            ComponentModelEnvironment::ENABLE_SCHEMA_ENTITY_REGISTRIES
141
        );
142
        \add_filter(
143
            $hookName,
144
            fn () => true,
145
            PHP_INT_MAX,
146
            1
147
        );
148
    }
149
150
    /**
151
     * Boot component
152
     *
153
     * @return void
154
     */
155
    public static function boot(): void
156
    {
157
        parent::boot();
158
159
        // Enable the CacheControl, if the module is not disabled
160
        $moduleRegistry = ModuleRegistryFacade::getInstance();
161
        if ($moduleRegistry->isModuleEnabled(PerformanceFunctionalityModuleResolver::CACHE_CONTROL)) {
162
            // Unless previewing the query
163
            if (!\is_preview()) {
164
                $dataloadingEngine = DataloadingEngineFacade::getInstance();
165
                $dataloadingEngine->addMandatoryDirectives([
166
                    CacheControlDirectiveResolver::getDirectiveName(),
167
                ]);
168
            }
169
        }
170
171
        // Configure the GraphQL query with Access/Cache Control Lists
172
        (new PersistedQuerySchemaConfiguratorExecuter())->init();
173
        (new EndpointSchemaConfiguratorExecuter())->init();
174
        (new EditingPersistedQuerySchemaConfiguratorExecuter())->init();
175
    }
176
177
    /**
178
     * Get all the compiler pass classes required to register on the container
179
     *
180
     * @return string[]
181
     */
182
    public static function getContainerCompilerPassClasses(): array
183
    {
184
        return [
185
            RegisterAccessControlRuleBlockCompilerPass::class,
186
        ];
187
    }
188
}
189