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 ( 0322d9...a68f9e )
by Leonardo
03:48
created

AbstractEditorScript::getScriptPublicPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
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\EditorScripts;
6
7
use GraphQLAPI\GraphQLAPI\General\EditorHelpers;
8
use GraphQLAPI\GraphQLAPI\Scripts\AbstractScript;
9
10
/**
11
 * Base class for a Gutenberg script.
12
 * The JS/CSS assets for each block is contained in folder {pluginDir}/editor-scripts/{scriptName}, and follows
13
 * the architecture from @wordpress/create-block package
14
 *
15
 * @see https://developer.wordpress.org/block-editor/packages/packages-create-block/
16
 */
17
abstract class AbstractEditorScript extends AbstractScript
18
{
19
    use HasDocumentationScriptTrait;
20
21
    /**
22
     * Pass localized data to the block
23
     *
24
     * @return array
25
     */
26
    protected function getLocalizedData(): array
27
    {
28
        return array_merge(
29
            parent::getLocalizedData(),
30
            $this->getDocsLocalizedData()
31
        );
32
    }
33
34
    /**
35
     * URL to the script
36
     *
37
     * @return string
38
     */
39
    protected function getScriptDirURL(): string
40
    {
41
        return $this->getPluginURL() . '/editor-scripts/' . $this->getScriptName() . '/';
42
    }
43
44
    /**
45
     * Docs are bundled as chunks by webpack, and loaded lazily
46
     * The `publicPath` property for `config.output` must be provided
47
     * pointing to the generated chunks folder, otherwise it is
48
     * by default resolved as /wp-admin/..., producing a 404.
49
     *
50
     * The public path will be set under global variable `__webpack_public_path__` in JS
51
     *
52
     * @see https://v4.webpack.js.org/guides/public-path/#on-the-fly
53
     */
54
    protected function getScriptPublicPath(): string
55
    {
56
        return $this->getScriptDirURL() . 'build/';
57
    }
58
59
    /**
60
     * Where is the script stored
61
     *
62
     * @return string
63
     */
64
    protected function getScriptDir(): string
65
    {
66
        return $this->getPluginDir() . '/editor-scripts/' . $this->getScriptName();
67
    }
68
69
    /**
70
     * Post types for which to register the script
71
     *
72
     * @return array
73
     */
74
    protected function getAllowedPostTypes(): array
75
    {
76
        return [];
77
    }
78
79
    /**
80
     * Registers all script assets
81
     */
82
    public function initScript(): void
83
    {
84
        /**
85
         * Maybe only load the script when creating/editing for some CPT only
86
         */
87
        if (\is_admin()) {
88
            if ($postTypes = $this->getAllowedPostTypes()) {
89
                if (!in_array(EditorHelpers::getEditingPostType(), $postTypes)) {
90
                    return;
91
                }
92
            }
93
        }
94
95
        parent::initScript();
96
97
        /**
98
         * Register the documentation (from under folder "docs/"), for the locale and the default language
99
         * IMPORTANT: Uncomment for webpack v5, to not duplicate the content of the docs inside build/index.js
100
         */
101
        // $this->initDocumentationScripts();
102
    }
103
104
    /**
105
     * Register the documentation (from under folder "docs/"), for the locale and the default language
106
     */
107
    protected function initDocumentationScripts(): void
108
    {
109
        $dir = $this->getScriptDir();
110
        $scriptName = $this->getScriptName();
111
        $script_asset_path = "$dir/build/index.asset.php";
112
        $url = $this->getScriptDirURL();
113
        $script_asset = require($script_asset_path);
114
115
        $this->registerDocumentationScripts($scriptName, $url, $script_asset['dependencies'], $script_asset['version']);
116
    }
117
}
118