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 % |
Changes | 0 |
1 | <?php |
||
9 | class FieldResolver |
||
10 | { |
||
11 | public function __invoke($parentValue, $args, $context, ResolveInfo $info) |
||
12 | { |
||
13 | $fieldName = $info->fieldName; |
||
14 | $value = self::valueFromObjectOrArray($parentValue, $fieldName); |
||
15 | |||
16 | return $value instanceof \Closure ? $value($parentValue, $args, $context, $info) : $value; |
||
17 | } |
||
18 | |||
19 | public static function valueFromObjectOrArray($objectOrArray, $fieldName) |
||
20 | { |
||
21 | $value = null; |
||
22 | if (\is_array($objectOrArray) && isset($objectOrArray[$fieldName])) { |
||
23 | $value = $objectOrArray[$fieldName]; |
||
24 | } elseif (\is_object($objectOrArray)) { |
||
25 | if (null !== $getter = self::guessObjectMethod($objectOrArray, $fieldName, 'get')) { |
||
26 | $value = $objectOrArray->$getter(); |
||
27 | } elseif (isset($objectOrArray->$fieldName)) { |
||
28 | $value = $objectOrArray->$fieldName; |
||
29 | } |
||
30 | } |
||
31 | |||
32 | return $value; |
||
33 | } |
||
34 | |||
35 | private static function guessObjectMethod($object, string $fieldName, string $prefix): ?string |
||
42 | } |
||
43 | } |
||
44 |