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 (#283)
by Jérémiah
14:17
created

Resolver   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 69
Duplicated Lines 14.49 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 3
dl 10
loc 69
ccs 33
cts 33
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A defaultResolveFn() 0 7 2
A valueFromObjectOrArray() 5 13 4
A setObjectOrArrayValue() 5 10 4
A wrapArgs() 0 11 2
A isReadable() 0 4 1
A isWritable() 0 4 1
A getAccessor() 0 8 2

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\Resolver;
4
5
use GraphQL\Type\Definition\ResolveInfo;
6
use Overblog\GraphQLBundle\Definition\Argument;
7
use Symfony\Component\PropertyAccess\PropertyAccess;
8
use Symfony\Component\PropertyAccess\PropertyAccessor;
9
10
class Resolver
11
{
12
    /** @var PropertyAccessor */
13
    private static $accessor;
14
15 52
    public static function defaultResolveFn($objectOrArray, $args, $context, ResolveInfo $info)
16
    {
17 52
        $fieldName = $info->fieldName;
18 52
        $value = static::valueFromObjectOrArray($objectOrArray, $fieldName);
19
20 52
        return $value instanceof \Closure ? $value($objectOrArray, $args, $context, $info) : $value;
21
    }
22
23 53
    public static function valueFromObjectOrArray($objectOrArray, $fieldName)
24
    {
25 53
        $value = null;
26 53
        $index = sprintf('[%s]', $fieldName);
27
28 53 View Code Duplication
        if (self::isReadable($objectOrArray, $index)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
29 35
            $value = self::getAccessor()->getValue($objectOrArray, $index);
30 31
        } elseif (is_object($objectOrArray) && self::isReadable($objectOrArray, $fieldName)) {
31 29
            $value = self::getAccessor()->getValue($objectOrArray, $fieldName);
32
        }
33
34 53
        return $value;
35
    }
36
37 6
    public static function setObjectOrArrayValue(&$objectOrArray, $fieldName, $value)
38
    {
39 6
        $index = sprintf('[%s]', $fieldName);
40
41 6 View Code Duplication
        if (self::isWritable($objectOrArray, $index)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
42 6
            self::getAccessor()->setValue($objectOrArray, $index, $value);
43 1
        } elseif (is_object($objectOrArray) && self::isWritable($objectOrArray, $fieldName)) {
44 1
            self::getAccessor()->setValue($objectOrArray, $fieldName, $value);
45
        }
46 6
    }
47
48
    public static function wrapArgs(callable $resolver)
49
    {
50 74
        return static function () use ($resolver) {
51 48
            $args = func_get_args();
52 48
            if (count($args) > 1) {
53 47
                $args[1] = new Argument($args[1]);
54
            }
55
56 48
            return $resolver(...$args);
57 74
        };
58
    }
59
60 53
    private static function isReadable($objectOrArray, $indexOrProperty)
61
    {
62 53
        return self::getAccessor()->isReadable($objectOrArray, $indexOrProperty);
63
    }
64
65 6
    private static function isWritable($objectOrArray, $indexOrProperty)
66
    {
67 6
        return self::getAccessor()->isWritable($objectOrArray, $indexOrProperty);
68
    }
69
70 54
    private static function getAccessor()
71
    {
72 54
        if (null === self::$accessor) {
73 1
            self::$accessor = PropertyAccess::createPropertyAccessor();
74
        }
75
76 54
        return self::$accessor;
77
    }
78
}
79