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:29
created

Resolver   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 67
Duplicated Lines 14.93 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 82.35%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 16
c 4
b 0
f 0
lcom 1
cbo 3
dl 10
loc 67
ccs 28
cts 34
cp 0.8235
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A defaultResolveFn() 0 7 2
A valueFromObjectOrArray() 5 13 4
A setObjectOrArrayValue() 5 10 4
A isReadable() 0 8 2
A isWritable() 0 8 2
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
/*
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 GraphQL\Type\Definition\ResolveInfo;
15
use Symfony\Component\PropertyAccess\Exception\OutOfBoundsException;
16
use Symfony\Component\PropertyAccess\PropertyAccess;
17
use Symfony\Component\PropertyAccess\PropertyAccessor;
18
19
class Resolver
20
{
21
    /**
22
     * @var PropertyAccessor
23
     */
24
    private static $accessor;
25
26 33
    public static function defaultResolveFn($objectOrArray, $args, $context, ResolveInfo $info)
27
    {
28 33
        $fieldName = $info->fieldName;
29 33
        $value = static::valueFromObjectOrArray($objectOrArray, $fieldName);
30
31 33
        return $value instanceof \Closure ? $value($objectOrArray, $args, $context, $info) : $value;
32
    }
33
34 34
    public static function valueFromObjectOrArray($objectOrArray, $fieldName)
35
    {
36 34
        $value = null;
37 34
        $index = sprintf('[%s]', $fieldName);
38
39 34 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...
40 28
            $value = self::getAccessor()->getValue($objectOrArray, $index);
41 34
        } elseif (is_object($objectOrArray) && self::isReadable($objectOrArray, $fieldName)) {
42 15
            $value = self::getAccessor()->getValue($objectOrArray, $fieldName);
43 15
        }
44
45 34
        return $value;
46
    }
47
48 4
    public static function setObjectOrArrayValue(&$objectOrArray, $fieldName, $value)
49
    {
50 4
        $index = sprintf('[%s]', $fieldName);
51
52 4 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...
53 4
            self::getAccessor()->setValue($objectOrArray, $index, $value);
54 4
        } elseif (is_object($objectOrArray) && self::isWritable($objectOrArray, $fieldName)) {
55
            self::getAccessor()->setValue($objectOrArray, $fieldName, $value);
56
        }
57 4
    }
58
59 34
    private static function isReadable($objectOrArray, $indexOrProperty)
60
    {
61
        try {
62 34
            return self::getAccessor()->isReadable($objectOrArray, $indexOrProperty);
63
        } catch (OutOfBoundsException $e) {
64
            return false;
65
        }
66
    }
67
68 4
    private static function isWritable($objectOrArray, $indexOrProperty)
69
    {
70
        try {
71 4
            return self::getAccessor()->isWritable($objectOrArray, $indexOrProperty);
72
        } catch (OutOfBoundsException $e) {
73
            return false;
74
        }
75
    }
76
77 34
    private static function getAccessor()
78
    {
79 34
        if (null === self::$accessor) {
80 1
            self::$accessor = PropertyAccess::createPropertyAccessor();
81 1
        }
82
83 34
        return self::$accessor;
84
    }
85
}
86