Add additional types allowed for date properties #1056
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Date properties added by
laravel-ide-helper
currently do not allow additional types supported by Laravel. The $model->asDateTime($value) method (\Illuminate\Database\Eloquent\Concerns\HasAttributes::asDateTime) is used when setting a date attribute/property. This method checks for\Carbon\CarbonInterface
,\DateTimeInterface
, "numeric" value, or a datestring
.This PR fixes this, and creates a PHPDoc type union containing the custom date class and the above mentioned types (
\Carbon\CarbonInterface
,\DateTimeInterface
,integer
, andstring
).Note: based on what the
asDateTime
method expects, it no longer makes sense to type hint against a custom date class because any date value must be "numeric", astring
, or implement either\Carbon\CarbonInterface
or\DateTimeInterface
(\Carbon\CarbonInterface
implements this interface).\Illuminate\Support\Carbon
extends\Carbon\Carbon
which in turn implements\Carbon\CarbonInterface
. Something to consider.Type of change
Checklist
composer fix-style
I have created this PR in response to @mfn's comments on #989.