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 — master ( 4d43f2...4b77ed )
by Jérémiah
14:49
created

AclConfigProcessor   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 75
Duplicated Lines 21.33 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 5
dl 16
loc 75
ccs 34
cts 34
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B acl() 0 23 7
A process() 16 16 3
A findFieldResolver() 0 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Overblog\GraphQLBundle\Definition\ConfigProcessor;
4
5
use GraphQL\Type\Definition\ResolveInfo;
6
use Overblog\GraphQLBundle\Definition\LazyConfig;
7
use Overblog\GraphQLBundle\Error\UserWarning;
8
use Overblog\GraphQLBundle\Resolver\AccessResolver;
9
10
final class AclConfigProcessor implements ConfigProcessorInterface
11
{
12
    /** @var AccessResolver */
13
    private $accessResolver;
14
15
    /** @var callable */
16
    private $defaultResolver;
17
18 88
    public function __construct(AccessResolver $accessResolver, callable $defaultResolver)
19
    {
20 88
        $this->accessResolver = $accessResolver;
21 88
        $this->defaultResolver = $defaultResolver;
22 88
    }
23
24
    public static function acl(array $fields, AccessResolver $accessResolver, callable $defaultResolver)
25
    {
26 78
        $deniedAccess = static function () {
27 1
            throw new UserWarning('Access denied to this field.');
28 78
        };
29 78
        foreach ($fields as &$field) {
30 78
            if (isset($field['access']) && true !== $field['access']) {
31 11
                $accessChecker = $field['access'];
32 11
                if (false === $accessChecker) {
33 10
                    $field['resolve'] = $deniedAccess;
34 11
                } elseif (is_callable($accessChecker)) {
35 78
                    $field['resolve'] = function ($value, $args, $context, ResolveInfo $info) use ($field, $accessChecker, $accessResolver, $defaultResolver) {
36 10
                        $resolverCallback = self::findFieldResolver($field, $info, $defaultResolver);
37 10
                        $isMutation = 'mutation' === $info->operation->operation && $info->parentType === $info->schema->getMutationType();
38
39 10
                        return $accessResolver->resolve($accessChecker, $resolverCallback, [$value, $args, $context, $info], $isMutation);
40 78
                    };
41
                }
42
            }
43
        }
44
45 78
        return $fields;
46
    }
47
48 View Code Duplication
    public function process(LazyConfig $lazyConfig)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
    {
50 88
        $lazyConfig->addPostLoader(function ($config) {
51 88
            if (isset($config['fields']) && is_callable($config['fields'])) {
52 78
                $config['fields'] = function () use ($config) {
53 78
                    $fields = $config['fields']();
54
55 78
                    return static::acl($fields, $this->accessResolver, $this->defaultResolver);
56
                };
57
            }
58
59 88
            return $config;
60 88
        });
61
62 88
        return $lazyConfig;
63
    }
64
65
    /**
66
     * @param array       $field
67
     * @param ResolveInfo $info
68
     * @param callable    $defaultResolver
69
     *
70
     * @return callable
71
     */
72 10
    private static function findFieldResolver(array $field, ResolveInfo $info, callable $defaultResolver)
73
    {
74 10
        if (isset($field['resolve'])) {
75 7
            $resolver = $field['resolve'];
76 6
        } elseif (isset($info->parentType->config['resolveField'])) {
77 1
            $resolver = $info->parentType->config['resolveField'];
78
        } else {
79 5
            $resolver = $defaultResolver;
80
        }
81
82 10
        return $resolver;
83
    }
84
}
85