Conditions | 6 |
Paths | 5 |
Total Lines | 22 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
12 | public function resolve(ExecutionEnvironment $environment) |
||
13 | { |
||
14 | $value = $environment->getValue(); |
||
15 | $fieldName = $environment->getInfo()->getFieldName(); |
||
16 | |||
17 | if (\is_array($value) || $value instanceof \ArrayAccess) { |
||
18 | return $value[$fieldName] ?? null; |
||
19 | } |
||
20 | |||
21 | if (\is_object($value)) { |
||
22 | $getter = 'get' . ucfirst($fieldName); |
||
23 | |||
24 | if (method_exists($value, $getter)) { |
||
25 | return $value->{$getter}(); |
||
26 | } |
||
27 | |||
28 | if (property_exists($value, $fieldName)) { |
||
29 | return $value->{$fieldName}; |
||
30 | } |
||
31 | } |
||
32 | |||
33 | throw new \Exception(sprintf('Could not resolve value for field "%s".', $fieldName)); |
||
34 | } |
||
36 |