From c5469951ca5be7f2f601ccb69f2e88e54676bd99 Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Sat, 9 Mar 2024 15:51:45 +0200 Subject: [PATCH] added comments --- .../InferExtensions/JsonResourceTypeInfer.php | 14 +++++--------- src/Support/InferExtensions/ModelExtension.php | 1 + 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/Support/InferExtensions/JsonResourceTypeInfer.php b/src/Support/InferExtensions/JsonResourceTypeInfer.php index 1ff39fdf..7c2958a9 100644 --- a/src/Support/InferExtensions/JsonResourceTypeInfer.php +++ b/src/Support/InferExtensions/JsonResourceTypeInfer.php @@ -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]; diff --git a/src/Support/InferExtensions/ModelExtension.php b/src/Support/InferExtensions/ModelExtension.php index 3aa43fa4..8353c1d5 100644 --- a/src/Support/InferExtensions/ModelExtension.php +++ b/src/Support/InferExtensions/ModelExtension.php @@ -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(),