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.

CacheControlBlock   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 89
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0
wmc 12

9 Methods

Rating   Name   Duplication   Size   Complexity  
A registerCommonStyleCSS() 0 3 1
A getBlockCategory() 0 8 1
A getDefaultLanguage() 0 4 1
A registerEditorCSS() 0 3 1
A getBlockDataTitle() 0 3 1
A getBlockContent() 0 28 4
A addLocalLanguage() 0 3 1
A getBlockName() 0 3 1
A getBlockContentTitle() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQLAPI\GraphQLAPI\Blocks;
6
7
use GraphQLAPI\GraphQLAPI\Blocks\AbstractControlBlock;
8
use GraphQLAPI\GraphQLAPI\Blocks\GraphQLByPoPBlockTrait;
9
use PoP\ComponentModel\Facades\Instances\InstanceManagerFacade;
10
use GraphQLAPI\GraphQLAPI\BlockCategories\AbstractBlockCategory;
11
use GraphQLAPI\GraphQLAPI\BlockCategories\CacheControlBlockCategory;
12
13
/**
14
 * Cache Control block
15
 */
16
class CacheControlBlock extends AbstractControlBlock
17
{
18
    use GraphQLByPoPBlockTrait;
19
20
    public const ATTRIBUTE_NAME_CACHE_CONTROL_MAX_AGE = 'cacheControlMaxAge';
21
22
    protected function getBlockName(): string
23
    {
24
        return 'cache-control';
25
    }
26
27
    protected function getBlockCategory(): ?AbstractBlockCategory
28
    {
29
        $instanceManager = InstanceManagerFacade::getInstance();
30
        /**
31
         * @var CacheControlBlockCategory
32
         */
33
        $blockCategory = $instanceManager->getInstance(CacheControlBlockCategory::class);
34
        return $blockCategory;
35
    }
36
37
    protected function registerCommonStyleCSS(): bool
38
    {
39
        return true;
40
    }
41
42
    protected function registerEditorCSS(): bool
43
    {
44
        return true;
45
    }
46
47
    /**
48
     * Add the locale language to the localized data?
49
     *
50
     * @return bool
51
     */
52
    protected function addLocalLanguage(): bool
53
    {
54
        return true;
55
    }
56
57
    /**
58
     * Default language for the script/component's documentation
59
     */
60
    protected function getDefaultLanguage(): ?string
61
    {
62
        // English
63
        return 'en';
64
    }
65
66
    protected function getBlockDataTitle(): string
67
    {
68
        return \__('Cache-control header for:', 'graphql-api');
69
    }
70
    protected function getBlockContentTitle(): string
71
    {
72
        return \__('Max-age:', 'graphql-api');
73
    }
74
    /**
75
     * @param array<string, mixed> $attributes
76
     */
77
    protected function getBlockContent(array $attributes, string $content): string
78
    {
79
        $blockContentPlaceholder = <<<EOF
80
        <div class="%s">
81
            %s
82
        </div>
83
EOF;
84
        $cacheControlMaxAge = $attributes[self::ATTRIBUTE_NAME_CACHE_CONTROL_MAX_AGE] ?? null;
85
        if (is_null($cacheControlMaxAge) || $cacheControlMaxAge < 0) {
86
            $cacheControlMaxAgeText = sprintf(
87
                '<em>%s</em>',
88
                \__('(not set)', 'graphql-api')
89
            );
90
        } elseif ($cacheControlMaxAge === 0) {
91
            $cacheControlMaxAgeText = sprintf(
92
                \__('%s seconds (<code>no-store</code>)', 'graphql-api'),
93
                $cacheControlMaxAge
94
            );
95
        } else {
96
            $cacheControlMaxAgeText = sprintf(
97
                \__('%s seconds', 'graphql-api'),
98
                $cacheControlMaxAge
99
            );
100
        }
101
        return sprintf(
102
            $blockContentPlaceholder,
103
            $this->getBlockClassName() . '__content',
104
            $cacheControlMaxAgeText
105
        );
106
    }
107
}
108