| Conditions | 4 |
| Paths | 3 |
| Total Lines | 19 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | public function __construct(array $types, RecursiveTypeMapperInterface $typeMapper) |
||
| 17 | { |
||
| 18 | $name = 'Union'; |
||
| 19 | foreach ($types as $type) { |
||
| 20 | $name .= $type->name; |
||
| 21 | if (!$type instanceof ObjectType) { |
||
| 22 | throw InvalidTypesInUnionException::notObjectType(); |
||
| 23 | } |
||
| 24 | } |
||
| 25 | parent::__construct([ |
||
| 26 | 'name' => $name, |
||
| 27 | 'types' => $types, |
||
| 28 | 'resolveType' => function($value) use ($typeMapper) { |
||
| 29 | if (!is_object($value)) { |
||
| 30 | throw new \InvalidArgumentException('Expected object for resolveType. Got: "'.gettype($value).'"'); |
||
| 31 | } |
||
| 32 | |||
| 33 | $className = get_class($value); |
||
| 34 | return $typeMapper->mapClassToInterfaceOrType($className, null); |
||
| 35 | } |
||
| 39 |