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
11:23
created

Resolver::propertyValueFromObject()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 2
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 Overblog\GraphQLBundle\Promise\PromiseInterface;
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
        if ($objectOrArray instanceof PromiseInterface) {
30
            $objectOrArray = $objectOrArray->wait();
31
        }
32 33
        $value = static::valueFromObjectOrArray($objectOrArray, $fieldName);
33
34 33
        return $value instanceof \Closure ? $value($objectOrArray, $args, $context, $info) : $value;
35
    }
36
37 34
    public static function valueFromObjectOrArray($objectOrArray, $fieldName)
38
    {
39 34
        $value = null;
40 34
        $index = sprintf('[%s]', $fieldName);
41
42 34
        if (self::getAccessor()->isReadable($objectOrArray, $index)) {
43 28
            $value = self::getAccessor()->getValue($objectOrArray, $index);
44 34
        } elseif (is_object($objectOrArray)) {
45 16
            $value = self::propertyValueFromObject($objectOrArray, $fieldName);
46 16
        }
47
48 34
        return $value;
49
    }
50
51 4
    public static function setObjectOrArrayValue(&$objectOrArray, $fieldName, $value)
52
    {
53 4
        $index = sprintf('[%s]', $fieldName);
54
55 4
        if (self::getAccessor()->isWritable($objectOrArray, $index)) {
56 4
            self::getAccessor()->setValue($objectOrArray, $index, $value);
57 4
        } elseif (is_object($objectOrArray)) {
58
            self::getAccessor()->setValue($objectOrArray, $fieldName, $value);
59
        }
60 4
    }
61
62 16
    private static function propertyValueFromObject($object, $fieldName)
63
    {
64 16
        $value = null;
65
66 16
        if (self::getAccessor()->isReadable($object, $fieldName)) {
67 15
            $value = self::getAccessor()->getValue($object, $fieldName);
68 15
        }
69
70 16
        return $value;
71
    }
72
73 34
    private static function getAccessor()
74
    {
75 34
        if (null === self::$accessor) {
76 1
            self::$accessor = PropertyAccess::createPropertyAccessor();
77 1
        }
78
79 34
        return self::$accessor;
80
    }
81
}
82