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 (#197)
by Renato
09:16 queued 02:55
created

Resolver   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 59
Duplicated Lines 16.95 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 92.59%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 14
lcom 1
cbo 2
dl 10
loc 59
ccs 25
cts 27
cp 0.9259
rs 10
c 1
b 0
f 0

6 Methods

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