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
Pull Request — master (#73)
by Jérémiah
06:18
created

AccessResolver   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 4
dl 0
loc 67
ccs 36
cts 36
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resolve() 0 15 3
C filterResultUsingAccess() 0 40 7
A hasAccess() 0 7 1
1
<?php
2
3
/*
4
 * This file is part of the OverblogGraphQLBundle package.
5
 *
6
 * (c) Overblog <http://github.com/overblog/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Overblog\GraphQLBundle\Resolver;
13
14
use Overblog\GraphQLBundle\Error\UserError;
15
use Overblog\GraphQLBundle\Error\UserWarning;
16
use Overblog\GraphQLBundle\Promise\PromiseInterface;
17
use Overblog\GraphQLBundle\Relay\Connection\Output\Connection;
18
use Overblog\GraphQLBundle\Relay\Connection\Output\Edge;
19
20
class AccessResolver
21 9
{
22
    public function resolve(callable $accessChecker, callable $resolveCallback, array $resolveArgs = [], $isMutation = false)
23
    {
24 9
        // operation is mutation and is mutation field
25 3
        if ($isMutation) {
26 1
            if (!$this->hasAccess($accessChecker, null, $resolveArgs)) {
27
                throw new UserError('Access denied to this field.');
28
            }
29 2
30 2
            $result = call_user_func_array($resolveCallback, $resolveArgs);
31 8
        } else {
32
            $result = $this->filterResultUsingAccess($accessChecker, $resolveCallback, $resolveArgs);
33
        }
34 7
35
        return $result;
36
    }
37 8
38
    private function filterResultUsingAccess(callable $accessChecker, callable $resolveCallback, array $resolveArgs = [])
39 8
    {
40
        $result = call_user_func_array($resolveCallback, $resolveArgs);
41 8
42 8
        $onFulFilled = function ($result) use ($accessChecker, $resolveArgs) {
43 3
            switch (true) {
44
                case is_array($result):
45 3
                    $result = array_map(
46 3
                        function ($object) use ($accessChecker, $resolveArgs) {
47
                            return $this->hasAccess($accessChecker, $object, $resolveArgs) ? $object : null;
48 3
                        },
49 3
                        $result
50 5
                    );
51 1
                    break;
52 1
                case $result instanceof Connection:
53 1
                    $result->edges = array_map(
54
                        function (Edge $edge) use ($accessChecker, $resolveArgs) {
55 1
                            $edge->node = $this->hasAccess($accessChecker, $edge->node, $resolveArgs) ? $edge->node : null;
56 1
57 1
                            return $edge;
58 1
                        },
59 1
                        $result->edges
60 5
                    );
61 5
                    break;
62 2
                default:
63
                    if (!$this->hasAccess($accessChecker, $result, $resolveArgs)) {
64 3
                        throw new UserWarning('Access denied to this field.');
65 5
                    }
66
                    break;
67 6
            }
68
69
            return $result;
70 9
        };
71
72 9
        if ($result instanceof  PromiseInterface) {
0 ignored issues
show
Bug introduced by
The class Overblog\GraphQLBundle\Promise\PromiseInterface 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...
73 9
            return $result->then($onFulFilled);
74
        }
75 9
76
        return $onFulFilled($result);
77
    }
78
79
    private function hasAccess(callable $accessChecker, $object, array $resolveArgs = [])
80
    {
81
        $resolveArgs[] = $object;
82
        $access = (bool) call_user_func_array($accessChecker, $resolveArgs);
83
84
        return $access;
85
    }
86
}
87