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.
Completed
Push — master ( d245d8...82e8c7 )
by Leonardo
10:28
created

EditorHelpers::getEditingPostID()   B

Complexity

Conditions 8
Paths 6

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
cc 8
eloc 12
c 0
b 0
f 0
nc 6
nop 0
dl 0
loc 18
ccs 0
cts 12
cp 0
crap 72
rs 8.4444
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQLAPI\GraphQLAPI\General;
6
7
class EditorHelpers
8
{
9
    /**
10
     * Get the post type currently being created/edited in the editor
11
     *
12
     * @return string
13
     */
14
    public static function getEditingPostType(): ?string
15
    {
16
        // When in the editor, there is no direct way to obtain the post type in hook "init",
17
        // since $typenow has not been initialized yet
18
        // Hence, recreate the logic to get post type from URL if we are on post-new.php, or
19
        // from edited post in post.php
20
        if (!\is_admin()) {
21
            return null;
22
        }
23
        global $pagenow;
24
        if (!in_array($pagenow, ['post-new.php', 'post.php'])) {
25
            return null;
26
        }
27
        $typenow = null;
28
        if ('post-new.php' === $pagenow) {
29
            if (isset($_REQUEST['post_type']) && \post_type_exists($_REQUEST['post_type'])) {
30
                $typenow = $_REQUEST['post_type'];
31
            };
32
        } elseif ('post.php' === $pagenow) {
33
            $post_id = null;
34
            if (isset($_GET['post']) && isset($_POST['post_ID']) && (int) $_GET['post'] !== (int) $_POST['post_ID']) {
35
                // Do nothing
36
            } elseif (isset($_GET['post'])) {
37
                $post_id = (int) $_GET['post'];
38
            } elseif (isset($_POST['post_ID'])) {
39
                $post_id = (int) $_POST['post_ID'];
40
            }
41
            if (!is_null($post_id)) {
42
                $post = \get_post($post_id);
43
                if (!is_null($post)) {
44
                    $typenow = $post->post_type;
45
                }
46
            }
47
        }
48
        return $typenow;
49
    }
50
51
    /**
52
     * Get the post ID currently being edited in the editor
53
     */
54
    public static function getEditingPostID(): ?int
55
    {
56
        if (!\is_admin()) {
57
            return null;
58
        }
59
        global $pagenow;
60
        if ($pagenow != 'post.php') {
61
            return null;
62
        }
63
        $post_id = null;
64
        if (isset($_GET['post']) && isset($_POST['post_ID']) && (int) $_GET['post'] !== (int) $_POST['post_ID']) {
65
            // Do nothing
66
        } elseif (isset($_GET['post'])) {
67
            $post_id = (int) $_GET['post'];
68
        } elseif (isset($_POST['post_ID'])) {
69
            $post_id = (int) $_POST['post_ID'];
70
        }
71
        return $post_id;
72
    }
73
}
74