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

Resolver::getAccessor()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2
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