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 ( db9dfd...2681d8 )
by Leonardo
06:34
created

QueryHooks::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
ccs 0
cts 2
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\Hooks;
6
7
use PoP\Hooks\AbstractHookSet;
8
use GraphQLAPI\GraphQLAPI\Admin\FieldResolvers\CPTFieldResolver;
9
use GraphQLAPI\GraphQLAPI\PostTypes\GraphQLCacheControlListPostType;
10
use GraphQLAPI\GraphQLAPI\PostTypes\GraphQLAccessControlListPostType;
11
use GraphQLAPI\GraphQLAPI\PostTypes\GraphQLSchemaConfigurationPostType;
12
use GraphQLAPI\GraphQLAPI\PostTypes\GraphQLFieldDeprecationListPostType;
13
use PoPSchema\SchemaCommons\DataLoading\ReturnTypes;
14
15
class QueryHooks extends AbstractHookSet
16
{
17
    public const NON_EXISTING_ID = "non-existing";
18
19
    protected function init()
20
    {
21
        $this->hooksAPI->addAction(
22
            'CMSAPI:customposts:query',
23
            [$this, 'convertCustomPostsQuery'],
24
            10,
25
            2
26
        );
27
    }
28
29
    /**
30
     * Remove querying private CPTs
31
     *
32
     * @param array<string, mixed> $query
33
     * @param array<string, mixed> $options
34
     * @return array<string, mixed>
35
     */
36
    public function convertCustomPostsQuery(array $query, array $options): array
37
    {
38
        // Hooks must be active only when resolving the query into IDs,
39
        // and not when resolving IDs into object, since there we don't have `$options`
40
        if (isset($query['post_type'])
41
            && (!isset($options[CPTFieldResolver::QUERY_OPTION_ALLOW_QUERYING_PRIVATE_CPTS]) || !$options[CPTFieldResolver::QUERY_OPTION_ALLOW_QUERYING_PRIVATE_CPTS])
42
            && isset($options['return-type']) && $options['return-type'] == ReturnTypes::IDS
43
        ) {
44
            // These CPTs must not be queried from outside, since they contain private configuration data
45
            $query['post_type'] = array_diff(
46
                $query['post_type'],
47
                [
48
                    GraphQLAccessControlListPostType::POST_TYPE,
49
                    GraphQLCacheControlListPostType::POST_TYPE,
50
                    GraphQLFieldDeprecationListPostType::POST_TYPE,
51
                    GraphQLSchemaConfigurationPostType::POST_TYPE,
52
                ]
53
            );
54
            // If there are no valid postTypes, then return no results
55
            // By not adding the post type, WordPress will fetch a "post"
56
            // Then, include a non-existing ID
57
            if (!$query['post_type']) {
58
                $query['include'] = self::NON_EXISTING_ID;
59
            }
60
        }
61
        return $query;
62
    }
63
}
64