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.

CacheControlGraphQLQueryConfigurator   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 31
dl 0
loc 63
ccs 0
cts 19
cp 0
rs 10
c 2
b 0
f 0
wmc 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B executeSchemaConfiguration() 0 55 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQLAPI\GraphQLAPI\SchemaConfigurators;
6
7
use PoP\ComponentModel\Misc\GeneralUtils;
8
use GraphQLAPI\GraphQLAPI\General\BlockHelpers;
9
use GraphQLAPI\GraphQLAPI\Blocks\CacheControlBlock;
10
use GraphQLAPI\GraphQLAPI\Blocks\AbstractControlBlock;
11
use GraphQLAPI\GraphQLAPI\Facades\ModuleRegistryFacade;
12
use PoP\CacheControl\Facades\CacheControlManagerFacade;
13
use PoP\ComponentModel\Facades\Instances\InstanceManagerFacade;
14
use GraphQLAPI\GraphQLAPI\SchemaConfigurators\AbstractGraphQLQueryConfigurator;
15
use GraphQLAPI\GraphQLAPI\ModuleResolvers\PerformanceFunctionalityModuleResolver;
16
17
class CacheControlGraphQLQueryConfigurator extends AbstractGraphQLQueryConfigurator
18
{
19
    /**
20
     * Extract the configuration items defined in the CPT,
21
     * and inject them into the service as to take effect in the current GraphQL query
22
     *
23
     * @return void
24
     */
25
    public function executeSchemaConfiguration(int $cclPostID): void
26
    {
27
        // Only execute for GET operations
28
        if ($_SERVER['REQUEST_METHOD'] != 'GET') {
29
            return;
30
        }
31
32
        // Only if the module is not disabled
33
        $moduleRegistry = ModuleRegistryFacade::getInstance();
34
        if (!$moduleRegistry->isModuleEnabled(PerformanceFunctionalityModuleResolver::CACHE_CONTROL)) {
35
            return;
36
        }
37
38
        $instanceManager = InstanceManagerFacade::getInstance();
39
        /**
40
         * @var CacheControlBlock
41
         */
42
        $block = $instanceManager->getInstance(CacheControlBlock::class);
43
        $cclBlockItems = BlockHelpers::getBlocksOfTypeFromCustomPost(
44
            $cclPostID,
45
            $block
46
        );
47
        $cacheControlManager = CacheControlManagerFacade::getInstance();
48
        // The "Cache Control" type contains the fields/directives and the max-age
49
        foreach ($cclBlockItems as $cclBlockItem) {
50
            $maxAge = $cclBlockItem['attrs'][CacheControlBlock::ATTRIBUTE_NAME_CACHE_CONTROL_MAX_AGE] ?? null;
51
            if (!is_null($maxAge) && $maxAge >= 0) {
52
                // Extract the saved fields
53
                if ($typeFields = $cclBlockItem['attrs'][AbstractControlBlock::ATTRIBUTE_NAME_TYPE_FIELDS] ?? null) {
54
                    if (
55
                        $entriesForFields = GeneralUtils::arrayFlatten(
56
                            array_map(
57
                                fn ($selectedField) => $this->getEntriesFromField($selectedField, $maxAge),
58
                                $typeFields
59
                            )
60
                        )
61
                    ) {
62
                        $cacheControlManager->addEntriesForFields(
63
                            $entriesForFields
64
                        );
65
                    }
66
                }
67
68
                // Extract the saved directives
69
                if ($directives = $cclBlockItem['attrs'][AbstractControlBlock::ATTRIBUTE_NAME_DIRECTIVES] ?? null) {
70
                    if (
71
                        $entriesForDirectives = GeneralUtils::arrayFlatten(array_filter(
72
                            array_map(
73
                                fn ($selectedDirective) => $this->getEntriesFromDirective($selectedDirective, $maxAge),
74
                                $directives
75
                            )
76
                        ))
77
                    ) {
78
                        $cacheControlManager->addEntriesForDirectives(
79
                            $entriesForDirectives
80
                        );
81
                    }
82
                }
83
            }
84
        }
85
    }
86
}
87