/** * @param $value * @param AbstractType $abstractType * @return Type * @throws \Exception */ public static function getTypeOf($value, AbstractType $abstractType) { $possibleTypes = $abstractType->getPossibleTypes(); for ($i = 0; $i < count($possibleTypes); $i++) { /** @var ObjectType $type */ $type = $possibleTypes[$i]; $isTypeOf = $type->isTypeOf($value); if ($isTypeOf === null) { // TODO: move this to a JS impl specific type system validation step // so the error can be found before execution. throw new \Exception('Non-Object Type ' . $abstractType->name . ' does not implement ' . 'resolveType and Object Type ' . $type->name . ' does not implement ' . 'isTypeOf. There is no way to determine if a value is of this type.'); } if ($isTypeOf) { return $type; } } return null; }