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.

EndpointOptionsBlock   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 62
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getBlockContent() 0 22 3
A getBlockCategory() 0 8 1
A getLocalizedData() 0 8 1
A getBlockName() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQLAPI\GraphQLAPI\Blocks;
6
7
use GraphQLAPI\GraphQLAPI\Facades\ModuleRegistryFacade;
8
use GraphQLAPI\GraphQLAPI\Blocks\GraphQLByPoPBlockTrait;
9
use PoP\ComponentModel\Facades\Instances\InstanceManagerFacade;
10
use GraphQLAPI\GraphQLAPI\BlockCategories\AbstractBlockCategory;
11
use GraphQLAPI\GraphQLAPI\BlockCategories\EndpointBlockCategory;
12
use GraphQLAPI\GraphQLAPI\Blocks\AbstractQueryExecutionOptionsBlock;
13
use GraphQLAPI\GraphQLAPI\ModuleResolvers\ClientFunctionalityModuleResolver;
14
15
/**
16
 * Endpoint Options block
17
 */
18
class EndpointOptionsBlock extends AbstractQueryExecutionOptionsBlock
19
{
20
    use GraphQLByPoPBlockTrait;
21
22
    public const ATTRIBUTE_NAME_IS_GRAPHIQL_ENABLED = 'isGraphiQLEnabled';
23
    public const ATTRIBUTE_NAME_IS_VOYAGER_ENABLED = 'isVoyagerEnabled';
24
25
    protected function getBlockName(): string
26
    {
27
        return 'endpoint-options';
28
    }
29
30
    protected function getBlockCategory(): ?AbstractBlockCategory
31
    {
32
        $instanceManager = InstanceManagerFacade::getInstance();
33
        /**
34
         * @var EndpointBlockCategory
35
         */
36
        $blockCategory = $instanceManager->getInstance(EndpointBlockCategory::class);
37
        return $blockCategory;
38
    }
39
40
    /**
41
     * @param array<string, mixed> $attributes
42
     */
43
    protected function getBlockContent(array $attributes, string $content): string
44
    {
45
        $blockContent = parent::getBlockContent($attributes, $content);
46
        $moduleRegistry = ModuleRegistryFacade::getInstance();
47
48
        $blockContentPlaceholder = '<p><strong>%s</strong> %s</p>';
49
        if ($moduleRegistry->isModuleEnabled(ClientFunctionalityModuleResolver::GRAPHIQL_FOR_CUSTOM_ENDPOINTS)) {
50
            $blockContent .= sprintf(
51
                $blockContentPlaceholder,
52
                \__('Expose GraphiQL client?', 'graphql-api'),
53
                $this->getBooleanLabel($attributes[self::ATTRIBUTE_NAME_IS_GRAPHIQL_ENABLED] ?? true)
54
            );
55
        }
56
        if ($moduleRegistry->isModuleEnabled(ClientFunctionalityModuleResolver::INTERACTIVE_SCHEMA_FOR_CUSTOM_ENDPOINTS)) {
57
            $blockContent .= sprintf(
58
                $blockContentPlaceholder,
59
                \__('Expose the Interactive Schema client?', 'graphql-api'),
60
                $this->getBooleanLabel($attributes[self::ATTRIBUTE_NAME_IS_VOYAGER_ENABLED] ?? true)
61
            );
62
        }
63
64
        return $blockContent;
65
    }
66
67
    /**
68
     * Pass localized data to the block
69
     *
70
     * @return array<string, mixed>
71
     */
72
    protected function getLocalizedData(): array
73
    {
74
        $moduleRegistry = ModuleRegistryFacade::getInstance();
75
        return array_merge(
76
            parent::getLocalizedData(),
77
            [
78
                'isGraphiQLEnabled' => $moduleRegistry->isModuleEnabled(ClientFunctionalityModuleResolver::GRAPHIQL_FOR_CUSTOM_ENDPOINTS),
79
                'isVoyagerEnabled' => $moduleRegistry->isModuleEnabled(ClientFunctionalityModuleResolver::INTERACTIVE_SCHEMA_FOR_CUSTOM_ENDPOINTS),
80
            ]
81
        );
82
    }
83
}
84