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.
Passed
Push — master ( 668646...cf7f24 )
by Leonardo
03:23
created

enableIndividualControlForPublicPrivateSchemaMode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 6
ccs 0
cts 6
cp 0
crap 6
rs 10
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
        return $instanceManager->getInstance(AccessControlBlockCategory::class);
35
    }
36
37
    protected function registerEditorCSS(): bool
38
    {
39
        return true;
40
    }
41
42
    protected function registerCommonStyleCSS(): bool
43
    {
44
        return true;
45
    }
46
    protected function enableIndividualControlForPublicPrivateSchemaMode(): bool
47
    {
48
        $moduleRegistry = ModuleRegistryFacade::getInstance();
49
        return
50
            $moduleRegistry->isModuleEnabled(AccessControlFunctionalityModuleResolver::PUBLIC_PRIVATE_SCHEMA)
51
            && ComponentConfiguration::enableIndividualControlForPublicPrivateSchemaMode();
52
    }
53
54
    protected function getBlockDataTitle(): string
55
    {
56
        return \__('Define access for:', 'graphql-api');
57
    }
58
    protected function getBlockContentTitle(): string
59
    {
60
        if ($this->enableIndividualControlForPublicPrivateSchemaMode()) {
61
            return \__('Access Control Rules:', 'graphql-api');
62
        }
63
        return \__('Who can access:', 'graphql-api');
64
    }
65
66
    /**
67
     * Pass localized data to the block
68
     *
69
     * @return array
70
     */
71
    protected function getLocalizedData(): array
72
    {
73
        return array_merge(
74
            parent::getLocalizedData(),
75
            [
76
                'isIndividualControlForSchemaModeEnabled' => $this->enableIndividualControlForPublicPrivateSchemaMode(),
77
            ]
78
        );
79
    }
80
81
    /**
82
     * Return the nested blocks' content
83
     *
84
     * @param array $attributes
85
     * @param string $content
86
     * @return string
87
     */
88
    protected function getBlockContent(array $attributes, string $content): string
89
    {
90
        $maybeSchemaModeContent = '';
91
        if ($this->enableIndividualControlForPublicPrivateSchemaMode()) {
92
            $blockContentPlaceholder = <<<EOT
93
                <p><strong>%s</strong> %s</p>
94
                <h4 class="%s">%s</h4>
95
EOT;
96
            $className = $this->getBlockClassName() . '-front';
97
            $schemaModeLabels = [
98
                SchemaModes::PUBLIC_SCHEMA_MODE => \__('Public', 'graphql-api'),
99
                SchemaModes::PRIVATE_SCHEMA_MODE => \__('Private', 'graphql-api'),
100
            ];
101
            $maybeSchemaModeContent = sprintf(
102
                $blockContentPlaceholder,
103
                \__('Public/Private Schema:', 'graphql-api'),
104
                $attributes[self::ATTRIBUTE_NAME_SCHEMA_MODE] ?
105
                    $schemaModeLabels[$attributes[self::ATTRIBUTE_NAME_SCHEMA_MODE]]
106
                    : \__('Default', 'graphql-api'),
107
                $className . '__title',
108
                \__('Who can access:', 'graphql-api')
109
            );
110
        }
111
        if ($content) {
112
            return $maybeSchemaModeContent . $content;
113
        }
114
        return $maybeSchemaModeContent . sprintf(
115
            '<em>%s</em>',
116
            \__('(not set)', 'graphql-api')
117
        );
118
    }
119
}
120