Skip to content

Commit

Permalink
fixed dates, fixed possibly missing type
Browse files Browse the repository at this point in the history
  • Loading branch information
romalytvynenko committed Mar 9, 2024
1 parent c546995 commit 73f73e7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Support/InferExtensions/ModelExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,19 @@ 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);
}

// @todo Fix to native types
$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]]"),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/Support/ResponseExtractor/ModelInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 73f73e7

Please sign in to comment.