Skip to content

Commit

Permalink
added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
romalytvynenko committed Mar 9, 2024
1 parent 86c6a97 commit c546995
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/Support/InferExtensions/JsonResourceTypeInfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,13 @@ private static function modelType(ClassDefinition $jsonClass, Scope $scope): ?Ty
$modelType = new UnknownType("Cannot resolve [$modelClass] model type.");
$modelClassDefinition = null;
if ($modelClass && is_a($modelClass, Model::class, true)) {
try {
$modelClassDefinition = (new ModelInfo($modelClass))->type();
// @todo Use ModelExtension implementation of model info to type conversion.
// @todo The problem is that model extension type is dynamic and I'm not sure how to use it here.
$modelClassDefinition = (new ModelInfo($modelClass))->type();

$scope->index->registerClassDefinition($modelClassDefinition);
$scope->index->registerClassDefinition($modelClassDefinition);

$modelType = new ObjectType($modelClassDefinition->name);
} catch (\LogicException $e) {
// Here doctrine/dbal is not installed.
$modelType = null;
$modelClassDefinition = null;
}
$modelType = new ObjectType($modelClassDefinition->name);
}

static::$jsonResourcesModelTypesCache[$jsonClass->name] = [$modelType, $modelClassDefinition];
Expand Down
1 change: 1 addition & 0 deletions src/Support/InferExtensions/ModelExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private function getBaseAttributeType(Model $model, string $key, array $value)
return new ObjectType(Carbon::class);
}

// @todo Fix to native types
$attributeType = match ($typeName) {
'int', 'integer', 'bigint' => new IntegerType(),
'float', 'double', 'decimal' => new FloatType(),
Expand Down

0 comments on commit c546995

Please sign in to comment.