Skip to content

Commit

Permalink
added immutable date cast support (#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
romalytvynenko authored Oct 14, 2024
1 parent 068bd75 commit c87c99a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Support/InferExtensions/ModelExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function getMethodReturnType(MethodCallEvent $event): ?Type
$propertyType = $event->getInstance()->getPropertyType($name);

(new TypeWalker)->replace($propertyType, function (Type $t) {
return $t->isInstanceOf(Carbon::class)
return ($t->isInstanceOf(Carbon::class) || $t->isInstanceOf(CarbonImmutable::class))
? tap(new StringType, fn ($t) => $t->setAttribute('format', 'date-time'))
: null;
});
Expand Down
5 changes: 3 additions & 2 deletions src/Support/TypeToSchemaExtensions/FlattensMergeValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Dedoc\Scramble\Support\TypeToSchemaExtensions;

use Carbon\Carbon;
use Carbon\CarbonImmutable;
use Dedoc\Scramble\Support\Type\ArrayItemType_;
use Dedoc\Scramble\Support\Type\Generic;
use Dedoc\Scramble\Support\Type\KeyedArrayType;
Expand Down Expand Up @@ -32,10 +33,10 @@ protected function flattenMergeValues(array $items)

if (
$item->value instanceof Union
&& (new TypeWalker)->first($item->value, fn (Type $t) => $t->isInstanceOf(Carbon::class))
&& (new TypeWalker)->first($item->value, fn (Type $t) => $t->isInstanceOf(Carbon::class) || $t->isInstanceOf(CarbonImmutable::class))
) {
(new TypeWalker)->replace($item->value, function (Type $t) {
return $t->isInstanceOf(Carbon::class)
return ($t->isInstanceOf(Carbon::class) || $t->isInstanceOf(CarbonImmutable::class))
? tap(new StringType, fn ($t) => $t->setAttribute('format', 'date-time'))
: null;
});
Expand Down

0 comments on commit c87c99a

Please sign in to comment.