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
Pull Request — master (#277)
by Jérémiah
22:38 queued 19:05
created

Resolver   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 57
Duplicated Lines 17.54 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 2
dl 10
loc 57
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0

6 Methods

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

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 Symfony\Component\PropertyAccess\PropertyAccess;
7
use Symfony\Component\PropertyAccess\PropertyAccessor;
8
9
class Resolver
10
{
11
    /** @var PropertyAccessor */
12
    private static $accessor;
13
14 52
    public static function defaultResolveFn($objectOrArray, $args, $context, ResolveInfo $info)
15
    {
16 52
        $fieldName = $info->fieldName;
17 52
        $value = static::valueFromObjectOrArray($objectOrArray, $fieldName);
18
19 52
        return $value instanceof \Closure ? $value($objectOrArray, $args, $context, $info) : $value;
20
    }
21
22 53
    public static function valueFromObjectOrArray($objectOrArray, $fieldName)
23
    {
24 53
        $value = null;
25 53
        $index = sprintf('[%s]', $fieldName);
26
27 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...
28 35
            $value = self::getAccessor()->getValue($objectOrArray, $index);
29 31
        } elseif (is_object($objectOrArray) && self::isReadable($objectOrArray, $fieldName)) {
30 29
            $value = self::getAccessor()->getValue($objectOrArray, $fieldName);
31
        }
32
33 53
        return $value;
34
    }
35
36 6
    public static function setObjectOrArrayValue(&$objectOrArray, $fieldName, $value)
37
    {
38 6
        $index = sprintf('[%s]', $fieldName);
39
40 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...
41 6
            self::getAccessor()->setValue($objectOrArray, $index, $value);
42 1
        } elseif (is_object($objectOrArray) && self::isWritable($objectOrArray, $fieldName)) {
43 1
            self::getAccessor()->setValue($objectOrArray, $fieldName, $value);
44
        }
45 6
    }
46
47 53
    private static function isReadable($objectOrArray, $indexOrProperty)
48
    {
49 53
        return self::getAccessor()->isReadable($objectOrArray, $indexOrProperty);
50
    }
51
52 6
    private static function isWritable($objectOrArray, $indexOrProperty)
53
    {
54 6
        return self::getAccessor()->isWritable($objectOrArray, $indexOrProperty);
55
    }
56
57 54
    private static function getAccessor()
58
    {
59 54
        if (null === self::$accessor) {
60 1
            self::$accessor = PropertyAccess::createPropertyAccessor();
61
        }
62
63 54
        return self::$accessor;
64
    }
65
}
66