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

Completed
Push — annotations ( c2b719...16d0c2 )
by Jérémiah
22:59 queued 20:22
created

AccessResolver::processFilter()   B

Complexity

Conditions 8
Paths 4

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 8

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 14
cts 14
cp 1
rs 8.4444
c 0
b 0
f 0
cc 8
nc 4
nop 3
crap 8
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 91
    public function __construct(PromiseAdapter $promiseAdapter)
23
    {
24 91
        $this->promiseAdapter = $promiseAdapter;
25 91
    }
26
27 11
    public function resolve(callable $accessChecker, callable $resolveCallback, array $resolveArgs = [], $isMutation = false)
28
    {
29
        // operation is mutation and is mutation field
30 11
        if ($isMutation) {
31 3
            if (!$this->hasAccess($accessChecker, null, $resolveArgs)) {
32 1
                throw new UserError('Access denied to this field.');
33
            }
34
35 2
            $result = \call_user_func_array($resolveCallback, $resolveArgs);
36
        } else {
37 10
            $result = $this->filterResultUsingAccess($accessChecker, $resolveCallback, $resolveArgs);
38
        }
39
40 8
        return $result;
41
    }
42
43 10
    private function filterResultUsingAccess(callable $accessChecker, callable $resolveCallback, array $resolveArgs = [])
44
    {
45 10
        $result = \call_user_func_array($resolveCallback, $resolveArgs);
46 10
        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...
47 1
            $result = $result->adoptedPromise;
48
        }
49
50 10
        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...
51 1
            return $this->promiseAdapter->then(
52 1
                new Promise($result, $this->promiseAdapter),
53
                function ($result) use ($accessChecker, $resolveArgs) {
54 1
                    return $this->processFilter($result, $accessChecker, $resolveArgs);
55 1
                }
56
            );
57
        }
58
59 10
        return $this->processFilter($result, $accessChecker, $resolveArgs);
60
    }
61
62 10
    private function processFilter($result, $accessChecker, $resolveArgs)
63
    {
64
        /** @var ResolveInfo $resolveInfo */
65 10
        $resolveInfo = $resolveArgs[3];
66
67 10
        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...
68 3
            foreach ($result as $i => $object) {
69 3
                $result[$i] = $this->hasAccess($accessChecker, $object, $resolveArgs) ? $object : null;
70
            }
71 7
        } elseif ($result instanceof Connection) {
72 1
            $result->edges = \array_map(
73
                function (Edge $edge) use ($accessChecker, $resolveArgs) {
74 1
                    $edge->node = $this->hasAccess($accessChecker, $edge->node, $resolveArgs) ? $edge->node : null;
75
76 1
                    return $edge;
77 1
                },
78 1
                $result->edges
79
            );
80 7
        } elseif (!$this->hasAccess($accessChecker, $result, $resolveArgs)) {
81 3
            throw new UserWarning('Access denied to this field.');
82
        }
83
84 7
        return $result;
85
    }
86
87 11
    private function hasAccess(callable $accessChecker, $object, array $resolveArgs = [])
88
    {
89 11
        $resolveArgs[] = $object;
90 11
        $access = (bool) \call_user_func_array($accessChecker, $resolveArgs);
91
92 11
        return $access;
93
    }
94
}
95