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.

executeSchemaConfiguration()   B
last analyzed

Complexity

Conditions 10
Paths 13

Size

Total Lines 55
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 110

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 10
eloc 30
nc 13
nop 1
dl 0
loc 55
ccs 0
cts 19
cp 0
crap 110
rs 7.6666
c 2
b 0
f 0

How to fix   Long Method    Complexity   

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\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