From 73f73e73db66eeeda7162ff50393a3c6ca4c7711 Mon Sep 17 00:00:00 2001 From: Roman Lytvynenko Date: Sat, 9 Mar 2024 17:22:59 +0200 Subject: [PATCH] fixed dates, fixed possibly missing type --- src/Support/InferExtensions/ModelExtension.php | 9 ++++++--- .../RulesExtractor/ValidateCallExtractor.php | 4 ++++ src/Support/ResponseExtractor/ModelInfo.php | 2 ++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Support/InferExtensions/ModelExtension.php b/src/Support/InferExtensions/ModelExtension.php index 8353c1d5..ff5db67a 100644 --- a/src/Support/InferExtensions/ModelExtension.php +++ b/src/Support/InferExtensions/ModelExtension.php @@ -71,7 +71,10 @@ private function getBaseAttributeType(Model $model, string $key, array $value) $type = explode(' ', $value['type']); $typeName = explode('(', $type[0])[0]; - if (in_array($key, $model->getDates())) { + if ( + ($model->getCasts()[$key] ?? null) === 'datetime' + || in_array($key, $model->getDates()) + ) { return new ObjectType(Carbon::class); } @@ -79,8 +82,8 @@ private function getBaseAttributeType(Model $model, string $key, array $value) $attributeType = match ($typeName) { 'int', 'integer', 'bigint' => new IntegerType(), 'float', 'double', 'decimal' => new FloatType(), - 'string', 'varchar', 'text', 'datetime' => new StringType(), - 'bool', 'boolean' => new BooleanType(), + 'varchar', 'string', 'text', 'datetime' => new StringType(), // string, text - needed? + 'tinyint', 'bool', 'boolean' => new BooleanType(), // bool, boolean - needed? 'json', 'array' => new ArrayType(), default => new UnknownType("unimplemented DB column type [$type[0]]"), }; diff --git a/src/Support/OperationExtensions/RulesExtractor/ValidateCallExtractor.php b/src/Support/OperationExtensions/RulesExtractor/ValidateCallExtractor.php index 3bec2be8..5d19d86c 100644 --- a/src/Support/OperationExtensions/RulesExtractor/ValidateCallExtractor.php +++ b/src/Support/OperationExtensions/RulesExtractor/ValidateCallExtractor.php @@ -121,6 +121,10 @@ private function getPossibleParamType(Node\Stmt\ClassMethod $methodNode, Node\Ex { $paramsMap = collect($methodNode->getParams()) ->mapWithKeys(function (Node\Param $param) { + if (!$param->type) { + return []; + } + try { return [ $param->var->name => $param->type->name, diff --git a/src/Support/ResponseExtractor/ModelInfo.php b/src/Support/ResponseExtractor/ModelInfo.php index 5d48c3e4..86661f1f 100644 --- a/src/Support/ResponseExtractor/ModelInfo.php +++ b/src/Support/ResponseExtractor/ModelInfo.php @@ -95,8 +95,10 @@ public function type() 'double' => new FloatType(), 'decimal' => new FloatType(), 'string' => new StringType(), + 'varchar' => new StringType(), 'text' => new StringType(), 'datetime' => new StringType(), + 'tinyint' => new BooleanType(), 'bool' => new BooleanType(), 'boolean' => new BooleanType(), 'json' => new ArrayType(),