We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Total Complexity | 10 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
9 | class FieldResolver |
||
10 | { |
||
11 | 42 | public function __invoke($parentValue, $args, $context, ResolveInfo $info) |
|
12 | { |
||
13 | 42 | $fieldName = $info->fieldName; |
|
14 | 42 | $value = self::valueFromObjectOrArray($parentValue, $fieldName); |
|
15 | |||
16 | 42 | return $value instanceof \Closure ? $value($parentValue, $args, $context, $info) : $value; |
|
17 | } |
||
18 | |||
19 | 43 | public static function valueFromObjectOrArray($objectOrArray, $fieldName) |
|
20 | { |
||
21 | 43 | $value = null; |
|
22 | 43 | if (\is_array($objectOrArray) && isset($objectOrArray[$fieldName])) { |
|
23 | 36 | $value = $objectOrArray[$fieldName]; |
|
24 | 21 | } elseif (\is_object($objectOrArray)) { |
|
25 | 19 | if (null !== $getter = self::guessObjectMethod($objectOrArray, $fieldName, 'get')) { |
|
26 | 17 | $value = $objectOrArray->$getter(); |
|
27 | 2 | } elseif (isset($objectOrArray->$fieldName)) { |
|
28 | 1 | $value = $objectOrArray->$fieldName; |
|
29 | } |
||
30 | } |
||
31 | |||
32 | 43 | return $value; |
|
33 | } |
||
34 | |||
35 | 19 | private static function guessObjectMethod($object, string $fieldName, string $prefix): ?string |
|
42 | } |
||
43 | } |
||
44 |