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 ( 9cc5a9...dc3333 )
by Leonardo
15:02
created

GraphiQLMenuPage::useGraphiQLExplorer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQLAPI\GraphQLAPI\ConditionalOnEnvironment\Admin\ConditionalOnEnvironment\GraphiQLExplorerInAdminClient\Overrides\Services\MenuPages;
6
7
use GraphQLAPI\GraphQLAPI\ConditionalOnEnvironment\Admin\Services\Clients\AdminGraphiQLWithExplorerClient;
8
use GraphQLAPI\GraphQLAPI\ConditionalOnEnvironment\Admin\Services\MenuPages\GraphiQLMenuPage as UpstreamGraphiQLMenuPage;
9
use PoP\ComponentModel\Facades\Instances\InstanceManagerFacade;
10
11
/**
12
 * GraphiQL with Explorer page
13
 */
14
class GraphiQLMenuPage extends UpstreamGraphiQLMenuPage
15
{
16
    protected function getGraphiQLWithExplorerClientHTML(): string
17
    {
18
        $instanceManager = InstanceManagerFacade::getInstance();
19
        /**
20
         * @var AdminGraphiQLWithExplorerClient
21
         */
22
        $client = $instanceManager->getInstance(AdminGraphiQLWithExplorerClient::class);
23
        return $client->getClientHTML();
24
    }
25
26
    public function print(): void
27
    {
28
        $htmlContent = $this->getGraphiQLWithExplorerClientHTML();
29
        // Extract the HTML inside <body>
30
        $matches = [];
31
        preg_match('/<body([^>]+)?>(.*?)<\/body>/s', $htmlContent, $matches);
32
        $bodyHTMLContent = $matches[2];
33
        // Remove all JS/CSS assets, since they are enqueued
34
        $bodyHTMLContent = preg_replace(
35
            [
36
                '/<link[^>]*>(.*)<\/link>"/s',
37
                '/<script[^>]*>(.*)<\/script>/s',
38
            ],
39
            '',
40
            $bodyHTMLContent
41
        );
42
        echo $bodyHTMLContent;
43
    }
44
45
    /**
46
     * Enqueue the required assets and initialize the localized scripts
47
     *
48
     * @return void
49
     */
50
    protected function enqueueGraphiQLCustomAssets(): void
51
    {
52
        // Common settings to both clients (with/out Explorer)
53
        $scriptSettings = array(
54
            'nonce' => \wp_create_nonce('wp_rest'),
55
            'response' => $this->getResponse(),
56
        );
57
58
        // Print the HTML from the Client
59
        $htmlContent = $this->getGraphiQLWithExplorerClientHTML();
60
        // Extract the JS/CSS assets, from either the <head> or the <head>
61
        $matches = [];
62
        preg_match_all('/<link[^>]+href="([^">]+)"/s', $htmlContent, $matches);
63
        $cssFileURLs = $matches[1];
64
        foreach ($cssFileURLs as $index => $cssFileURL) {
65
            \wp_enqueue_style(
66
                'graphql-api-graphiql-with-explorer-' . $index,
67
                $cssFileURL,
68
                array(),
69
                \GRAPHQL_API_VERSION
70
            );
71
        }
72
        preg_match_all('/<script[^>]+src="([^">]+)"/s', $htmlContent, $matches);
73
        $jsFileURLs = $matches[1];
74
        foreach ($jsFileURLs as $index => $jsFileURL) {
75
            \wp_enqueue_script(
76
                'graphql-api-graphiql-with-explorer-' . $index,
77
                $jsFileURL,
78
                array(),
79
                \GRAPHQL_API_VERSION,
80
                true
81
            );
82
        }
83
84
        // Override styles for the admin, so load last
85
        \wp_enqueue_style(
86
            'graphql-api-graphiql-with-explorer-client',
87
            \GRAPHQL_API_URL . 'assets/css/graphiql-with-explorer-client.css',
88
            array(),
89
            \GRAPHQL_API_VERSION
90
        );
91
92
        // Load data into the script. Because no script is enqueued since it is
93
        // in the body, then localize it to React
94
        \wp_localize_script(
95
            'graphql-api-graphiql-with-explorer-0',
96
            'graphiQLWithExplorerClientForWP',
97
            $scriptSettings
98
        );
99
    }
100
}
101