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.
Completed
Push — master ( f8338c...2c06e9 )
by Leonardo
13:39
created

Component   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Test Coverage

Coverage 5.13%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 54
dl 0
loc 124
ccs 2
cts 39
cp 0.0513
rs 10
c 5
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A doInitialize() 0 20 3
A beforeBoot() 0 7 1
A boot() 0 20 3
A getDependedComponentClasses() 0 25 1
A initComponentConfiguration() 0 15 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQLAPI\GraphQLAPI;
6
7
use PoP\Root\Component\AbstractComponent;
8
use PoP\Root\Component\YAMLServicesTrait;
9
use GraphQLAPI\GraphQLAPI\Config\ServiceConfiguration;
10
use GraphQLAPI\GraphQLAPI\Facades\ModuleRegistryFacade;
11
use PoP\ComponentModel\Container\ContainerBuilderUtils;
12
use PoP\ComponentModel\Facades\Engine\DataloadingEngineFacade;
13
use PoP\ComponentModel\Environment as ComponentModelEnvironment;
14
use PoP\CacheControl\DirectiveResolvers\CacheControlDirectiveResolver;
15
use GraphQLAPI\GraphQLAPI\ModuleResolvers\CacheFunctionalityModuleResolver;
16
use PoP\ComponentModel\ComponentConfiguration\ComponentConfigurationHelpers;
17
use GraphQLAPI\GraphQLAPI\ModuleResolvers\PerformanceFunctionalityModuleResolver;
18
use PoP\ComponentModel\ComponentConfiguration as ComponentModelComponentConfiguration;
19
use GraphQLAPI\GraphQLAPI\SchemaConfiguratorExecuters\EndpointSchemaConfiguratorExecuter;
20
use GraphQLAPI\GraphQLAPI\SchemaConfiguratorExecuters\PersistedQuerySchemaConfiguratorExecuter;
21
use GraphQLAPI\GraphQLAPI\SchemaConfiguratorExecuters\EditingPersistedQuerySchemaConfiguratorExecuter;
22
23
/**
24
 * Initialize component
25
 */
26
class Component extends AbstractComponent
27
{
28
    use YAMLServicesTrait;
29
30
    // const VERSION = '0.1.0';
31
32
    /**
33
     * Classes from PoP components that must be initialized before this component
34
     *
35
     * @return string[]
36
     */
37 1
    public static function getDependedComponentClasses(): array
38
    {
39
        return [
40 1
            \PoPSchema\GenericCustomPosts\Component::class,
41
            \PoPSchema\CommentMetaWP\Component::class,
42
            \GraphQLByPoP\GraphQLServer\Component::class,
43
            \PoPSchema\MediaWP\Component::class,
44
            \PoPSchema\PostsWP\Component::class,
45
            \PoPSchema\PagesWP\Component::class,
46
            \PoPSchema\CustomPostMediaWP\Component::class,
47
            \PoPSchema\CustomPostMetaWP\Component::class,
48
            \PoPSchema\TaxonomyQueryWP\Component::class,
49
            \PoPSchema\PostTagsWP\Component::class,
50
            \PoPSchema\UserRolesAccessControl\Component::class,
51
            \PoPSchema\UserRolesWP\Component::class,
52
            \PoPSchema\UserStateWP\Component::class,
53
            \PoPSchema\UserMetaWP\Component::class,
54
            \PoPSchema\CustomPostMutationsWP\Component::class,
55
            \PoPSchema\PostMutations\Component::class,
56
            \PoPSchema\CustomPostMediaMutationsWP\Component::class,
57
            \PoPSchema\CommentMutationsWP\Component::class,
58
            \PoPSchema\UserStateMutationsWP\Component::class,
59
            \PoPSchema\BasicDirectives\Component::class,
60
            \GraphQLByPoP\GraphQLClientsForWP\Component::class,
61
            \GraphQLByPoP\GraphQLEndpointForWP\Component::class,
62
        ];
63
    }
64
65
    /**
66
     * Initialize services
67
     *
68
     * @param array<string, mixed> $configuration
69
     * @param string[] $skipSchemaComponentClasses
70
     */
71
    protected static function doInitialize(
72
        array $configuration = [],
73
        bool $skipSchema = false,
74
        array $skipSchemaComponentClasses = []
75
    ): void {
76
        parent::doInitialize($configuration, $skipSchema, $skipSchemaComponentClasses);
77
        self::initYAMLServices(dirname(__DIR__));
78
        /**
79
         * FieldResolvers used to configure the services can also be accessed in the admin area
80
         */
81
        if (\is_admin()) {
82
            self::maybeInitYAMLSchemaServices(dirname(__DIR__), $skipSchema, '', 'admin-schema-services.yaml');
83
        }
84
        // Register the Cache services, if the module is not disabled
85
        $moduleRegistry = ModuleRegistryFacade::getInstance();
86
        if ($moduleRegistry->isModuleEnabled(CacheFunctionalityModuleResolver::CONFIGURATION_CACHE)) {
87
            self::initYAMLServices(dirname(__DIR__), '', 'cache-services.yaml');
88
        }
89
        self::initComponentConfiguration();
90
        ServiceConfiguration::initialize();
91
    }
92
93
    protected static function initComponentConfiguration(): void
94
    {
95
        /**
96
         * Enable the schema entity registries, as to retrieve the type/directive resolver classes
97
         * from the type/directive names, saved in the DB in the ACL/CCL Custom Post Types
98
         */
99
        $hookName = ComponentConfigurationHelpers::getHookName(
100
            ComponentModelComponentConfiguration::class,
101
            ComponentModelEnvironment::ENABLE_SCHEMA_ENTITY_REGISTRIES
102
        );
103
        \add_filter(
104
            $hookName,
105
            fn () => true,
106
            PHP_INT_MAX,
107
            1
108
        );
109
    }
110
111
    /**
112
     * Boot component
113
     *
114
     * @return void
115
     */
116
    public static function beforeBoot(): void
117
    {
118
        parent::beforeBoot();
119
120
        // Initialize classes
121
        ContainerBuilderUtils::instantiateNamespaceServices(__NAMESPACE__ . '\\Hooks');
122
        ContainerBuilderUtils::attachFieldResolversFromNamespace(__NAMESPACE__ . '\\Admin\\FieldResolvers', false);
123
    }
124
125
    /**
126
     * Boot component
127
     *
128
     * @return void
129
     */
130
    public static function boot(): void
131
    {
132
        parent::boot();
133
134
        // Enable the CacheControl, if the module is not disabled
135
        $moduleRegistry = ModuleRegistryFacade::getInstance();
136
        if ($moduleRegistry->isModuleEnabled(PerformanceFunctionalityModuleResolver::CACHE_CONTROL)) {
137
            // Unless previewing the query
138
            if (!\is_preview()) {
139
                $dataloadingEngine = DataloadingEngineFacade::getInstance();
140
                $dataloadingEngine->addMandatoryDirectives([
141
                    CacheControlDirectiveResolver::getDirectiveName(),
142
                ]);
143
            }
144
        }
145
146
        // Configure the GraphQL query with Access/Cache Control Lists
147
        (new PersistedQuerySchemaConfiguratorExecuter())->init();
148
        (new EndpointSchemaConfiguratorExecuter())->init();
149
        (new EditingPersistedQuerySchemaConfiguratorExecuter())->init();
150
    }
151
}
152