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.

AccessControlBlock::getBlockCategory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 8
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQLAPI\GraphQLAPI\Blocks;
6
7
use PoP\AccessControl\Schema\SchemaModes;
8
use PoP\AccessControl\ComponentConfiguration;
9
use GraphQLAPI\GraphQLAPI\Blocks\AbstractControlBlock;
10
use GraphQLAPI\GraphQLAPI\Facades\ModuleRegistryFacade;
11
use GraphQLAPI\GraphQLAPI\Blocks\GraphQLByPoPBlockTrait;
12
use PoP\ComponentModel\Facades\Instances\InstanceManagerFacade;
13
use GraphQLAPI\GraphQLAPI\BlockCategories\AbstractBlockCategory;
14
use GraphQLAPI\GraphQLAPI\BlockCategories\AccessControlBlockCategory;
15
use GraphQLAPI\GraphQLAPI\ModuleResolvers\AccessControlFunctionalityModuleResolver;
16
17
/**
18
 * Access Control block
19
 */
20
class AccessControlBlock extends AbstractControlBlock
21
{
22
    use GraphQLByPoPBlockTrait;
23
24
    public const ATTRIBUTE_NAME_SCHEMA_MODE = 'schemaMode';
25
26
    protected function getBlockName(): string
27
    {
28
        return 'access-control';
29
    }
30
31
    protected function getBlockCategory(): ?AbstractBlockCategory
32
    {
33
        $instanceManager = InstanceManagerFacade::getInstance();
34
        /**
35
         * @var AccessControlBlockCategory
36
         */
37
        $blockCategory = $instanceManager->getInstance(AccessControlBlockCategory::class);
38
        return $blockCategory;
39
    }
40
41
    protected function registerEditorCSS(): bool
42
    {
43
        return true;
44
    }
45
46
    protected function registerCommonStyleCSS(): bool
47
    {
48
        return true;
49
    }
50
51
    protected function getBlockDataTitle(): string
52
    {
53
        return \__('Define access for:', 'graphql-api');
54
    }
55
    protected function getBlockContentTitle(): string
56
    {
57
        if (ComponentConfiguration::enableIndividualControlForPublicPrivateSchemaMode()) {
58
            return \__('Access Control Rules:', 'graphql-api');
59
        }
60
        return \__('Who can access:', 'graphql-api');
61
    }
62
63
    /**
64
     * Pass localized data to the block
65
     *
66
     * @return array<string, mixed>
67
     */
68
    protected function getLocalizedData(): array
69
    {
70
        return array_merge(
71
            parent::getLocalizedData(),
72
            [
73
                'isIndividualControlForSchemaModeEnabled' => ComponentConfiguration::enableIndividualControlForPublicPrivateSchemaMode(),
74
            ]
75
        );
76
    }
77
78
    /**
79
     * Return the nested blocks' content
80
     *
81
     * @param array<string, mixed> $attributes
82
     */
83
    protected function getBlockContent(array $attributes, string $content): string
84
    {
85
        $maybeSchemaModeContent = '';
86
        if (ComponentConfiguration::enableIndividualControlForPublicPrivateSchemaMode()) {
87
            $blockContentPlaceholder = <<<EOT
88
                <p><strong>%s</strong> %s</p>
89
                <h4 class="%s">%s</h4>
90
EOT;
91
            $className = $this->getBlockClassName() . '-front';
92
            $schemaModeLabels = [
93
                SchemaModes::PUBLIC_SCHEMA_MODE => \__('Public', 'graphql-api'),
94
                SchemaModes::PRIVATE_SCHEMA_MODE => \__('Private', 'graphql-api'),
95
            ];
96
            $maybeSchemaModeContent = sprintf(
97
                $blockContentPlaceholder,
98
                \__('Public/Private Schema:', 'graphql-api'),
99
                isset($attributes[self::ATTRIBUTE_NAME_SCHEMA_MODE]) ?
100
                    $schemaModeLabels[$attributes[self::ATTRIBUTE_NAME_SCHEMA_MODE]]
101
                    : \__('Default', 'graphql-api'),
102
                $className . '__title',
103
                \__('Who can access:', 'graphql-api')
104
            );
105
        }
106
        if ($content) {
107
            return $maybeSchemaModeContent . $content;
108
        }
109
        return $maybeSchemaModeContent . sprintf(
110
            '<em>%s</em>',
111
            \__('(not set)', 'graphql-api')
112
        );
113
    }
114
}
115