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 ( aac044...cc3c72 )
by Leonardo
14:28
created

ModuleDocumentationMenuPage   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 72
rs 10
c 0
b 0
f 0
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A isCurrentScreen() 0 3 2
A getContentToPrint() 0 35 5
A __construct() 0 3 1
A openInModalWindow() 0 3 1
A getMenuPageSlug() 0 8 1
A useTabpanelForContent() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQLAPI\GraphQLAPI\ConditionalOnEnvironment\Admin\Services\MenuPages;
6
7
use GraphQLAPI\GraphQLAPI\ConditionalOnEnvironment\Admin\Services\Helpers\MenuPageHelper;
8
use GraphQLAPI\GraphQLAPI\Facades\ModuleRegistryFacade;
9
use GraphQLAPI\GraphQLAPI\General\RequestParams;
10
use InvalidArgumentException;
11
use PoP\ComponentModel\Facades\Instances\InstanceManagerFacade;
12
13
/**
14
 * Module Documentation menu page
15
 */
16
class ModuleDocumentationMenuPage extends AbstractDocsMenuPage
17
{
18
    protected MenuPageHelper $menuPageHelper;
19
20
    function __construct(MenuPageHelper $menuPageHelper)
21
    {
22
        $this->menuPageHelper = $menuPageHelper;
23
    }
24
25
    public function getMenuPageSlug(): string
26
    {
27
        $instanceManager = InstanceManagerFacade::getInstance();
28
        /**
29
         * @var ModulesMenuPage
30
         */
31
        $modulesMenuPage = $instanceManager->getInstance(ModulesMenuPage::class);
32
        return $modulesMenuPage->getMenuPageSlug();
33
    }
34
35
    /**
36
     * Validate the param also
37
     */
38
    protected function isCurrentScreen(): bool
39
    {
40
        return $this->menuPageHelper->isDocumentationScreen() && parent::isCurrentScreen();
41
    }
42
43
    protected function openInModalWindow(): bool
44
    {
45
        return true;
46
    }
47
48
    protected function useTabpanelForContent(): bool
49
    {
50
        return true;
51
    }
52
53
    protected function getContentToPrint(): string
54
    {
55
        // This is crazy: passing ?module=Foo\Bar\module,
56
        // and then doing $_GET['module'], returns "Foo\\Bar\\module"
57
        // So parse the URL to extract the "module" param
58
        $vars = [];
59
        parse_str($_SERVER['REQUEST_URI'], $vars);
60
        $module = urldecode($vars[RequestParams::MODULE]);
61
        $moduleRegistry = ModuleRegistryFacade::getInstance();
62
        try {
63
            $moduleResolver = $moduleRegistry->getModuleResolver($module);
64
        } catch (InvalidArgumentException $e) {
65
            return sprintf(
66
                '<p>%s</p>',
67
                sprintf(
68
                    \__('Oops, module \'%s\' does not exist', 'graphql-api'),
69
                    $module
70
                )
71
            );
72
        }
73
        $hasDocumentation = $moduleResolver->hasDocumentation($module);
74
        $documentation = '';
75
        if ($hasDocumentation) {
76
            $documentation = $moduleResolver->getDocumentation($module);
77
        }
78
        if (!$hasDocumentation || $documentation === null) {
79
            return sprintf(
80
                '<p>%s</p>',
81
                sprintf(
82
                    \__('Oops, module \'%s\' has no documentation', 'graphql-api'),
83
                    $moduleResolver->getName($module)
84
                )
85
            );
86
        }
87
        return $documentation;
88
    }
89
}
90