Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Push — annotations ( 87c88c...79459a )
by Jérémiah
24:19 queued 10s
created

AccessResolver   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 21
lcom 1
cbo 3
dl 0
loc 82
ccs 38
cts 38
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B processFilter() 0 24 8
B resolve() 0 23 6
A isMutationRootField() 0 4 2
A checkAccessForStrictMode() 0 9 3
A hasAccess() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Overblog\GraphQLBundle\Resolver;
6
7
use GraphQL\Executor\Promise\Adapter\SyncPromise;
8
use GraphQL\Executor\Promise\Promise;
9
use GraphQL\Executor\Promise\PromiseAdapter;
10
use GraphQL\Type\Definition\ListOfType;
11
use GraphQL\Type\Definition\ResolveInfo;
12
use Overblog\GraphQLBundle\Error\UserError;
13
use Overblog\GraphQLBundle\Error\UserWarning;
14
use Overblog\GraphQLBundle\Relay\Connection\Output\Connection;
15
use Overblog\GraphQLBundle\Relay\Connection\Output\Edge;
16
17
class AccessResolver
18
{
19
    /** @var PromiseAdapter */
20
    private $promiseAdapter;
21
22 98
    public function __construct(PromiseAdapter $promiseAdapter)
23
    {
24 98
        $this->promiseAdapter = $promiseAdapter;
25 98
    }
26
27 11
    public function resolve(callable $accessChecker, callable $resolveCallback, array $resolveArgs = [], $useStrictAccess = false)
28
    {
29
        if ($useStrictAccess || self::isMutationRootField($resolveArgs[3])) {
30 11
            return $this->checkAccessForStrictMode($accessChecker, $resolveCallback, $resolveArgs);
31 3
        }
32 1
33
        $result = \call_user_func_array($resolveCallback, $resolveArgs);
34
35 2
        if ($result instanceof Promise) {
0 ignored issues
show
Bug introduced by
The class GraphQL\Executor\Promise\Promise does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
36
            $result = $result->adoptedPromise;
37 10
        }
38
39
        if ($this->promiseAdapter->isThenable($result) || $result instanceof SyncPromise) {
0 ignored issues
show
Bug introduced by
The class GraphQL\Executor\Promise\Adapter\SyncPromise does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
40 8
            return $this->promiseAdapter->then(
41
                new Promise($result, $this->promiseAdapter),
42
                function ($result) use ($accessChecker, $resolveArgs) {
43 10
                    return $this->processFilter($result, $accessChecker, $resolveArgs);
44
                }
45 10
            );
46 10
        }
47 1
48
        return $this->processFilter($result, $accessChecker, $resolveArgs);
49
    }
50 10
51 1
    private static function isMutationRootField(ResolveInfo $info): bool
52 1
    {
53
        return 'mutation' === $info->operation->operation && $info->parentType === $info->schema->getMutationType();
54 1
    }
55 1
56
    private function checkAccessForStrictMode(callable $accessChecker, callable $resolveCallback, array $resolveArgs = [])
57
    {
58
        if (!$this->hasAccess($accessChecker, $resolveArgs)) {
59 10
            $exceptionClassName = self::isMutationRootField($resolveArgs[3]) ? UserError::class : UserWarning::class;
60
            throw new $exceptionClassName('Access denied to this field.');
61
        }
62 10
63
        return \call_user_func_array($resolveCallback, $resolveArgs);
64
    }
65 10
66
    private function processFilter($result, $accessChecker, $resolveArgs)
67 10
    {
68 3
        /** @var ResolveInfo $resolveInfo */
69 3
        $resolveInfo = $resolveArgs[3];
70
71 7
        if (\is_iterable($result) && $resolveInfo->returnType instanceof ListOfType) {
0 ignored issues
show
Bug introduced by
The class GraphQL\Type\Definition\ListOfType does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
72 1
            foreach ($result as $i => $object) {
73
                $result[$i] = $this->hasAccess($accessChecker, $resolveArgs, $object) ? $object : null;
74 1
            }
75
        } elseif ($result instanceof Connection) {
76 1
            $result->edges = \array_map(
77 1
                function (Edge $edge) use ($accessChecker, $resolveArgs) {
78 1
                    $edge->node = $this->hasAccess($accessChecker, $resolveArgs, $edge->node) ? $edge->node : null;
79
80 7
                    return $edge;
81 3
                },
82
                $result->edges
83
            );
84 7
        } elseif (!$this->hasAccess($accessChecker, $resolveArgs, $result)) {
85
            throw new UserWarning('Access denied to this field.');
86
        }
87 11
88
        return $result;
89 11
    }
90 11
91
    private function hasAccess(callable $accessChecker, array $resolveArgs = [], $object = null): bool
92 11
    {
93
        $resolveArgs[] = $object;
94
        $access = (bool) \call_user_func_array($accessChecker, $resolveArgs);
95
96
        return $access;
97
    }
98
}
99