Skip to content

Commit 2ce210c

Browse files
committed
support bool
1 parent 647b117 commit 2ce210c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/ModelTransformer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public function transform(ReflectionClass $class, string $name): TransformedType
5858

5959
preg_match($regex, $comment, $matches);
6060

61+
// dump($comment, $append, $regex, $matches);
62+
6163
if (count($matches) > 1) {
6264
$type = $this->mapCastToType($matches[1]);
6365
}
@@ -91,7 +93,7 @@ private function mapTypeNameToJsonType(string $columnType): string
9193
private function mapCastToType(string $cast): string
9294
{
9395
return match ($cast) {
94-
'boolean' => 'boolean',
96+
'boolean', 'bool' => 'boolean',
9597
'int', 'float' => 'number',
9698
'string', 'datetime', 'timestamp', 'date', 'uuid' => 'string',
9799
'array', 'object' => 'any',

tests/Feature/TransformEloquentModelsTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
/**
144144
* @property string $appended_attribute_str
145145
* @property int $appended_attribute_int
146+
* @property bool $appended_attribute_bool
146147
*/
147148
$model = new class extends \Illuminate\Database\Eloquent\Model {
148149
protected $table = 'test_table';
@@ -151,6 +152,7 @@
151152
'appended_attribute_str',
152153
'appended_attribute_array',
153154
'appended_attribute_int',
155+
'appended_attribute_bool',
154156
];
155157

156158
public function appendedAttribute()
@@ -172,6 +174,10 @@ public function appendedAttributeInt()
172174
{
173175
new Attribute(get: fn() => 1);
174176
}
177+
public function appendedAttributeBool()
178+
{
179+
new Attribute(get: fn() => true);
180+
}
175181
};
176182

177183
$transformer = new ModelTransformer;
@@ -184,6 +190,7 @@ public function appendedAttributeInt()
184190
"appended_attribute_str: string\n" .
185191
"appended_attribute_array: any\n" .
186192
"appended_attribute_int: number\n" .
193+
"appended_attribute_bool: boolean\n" .
187194
'}';
188195

189196
expect($transformedType?->transformed)->toEqual($type_definition);

0 commit comments

Comments
 (0)