Skip to content

[9.x] Allow for int value parameters to whereMonth() and whereDay()#43668

Merged
taylorotwell merged 1 commit into
laravel:9.xfrom
lupinitylabs:feature/where-month-day-int-values
Aug 15, 2022
Merged

[9.x] Allow for int value parameters to whereMonth() and whereDay()#43668
taylorotwell merged 1 commit into
laravel:9.xfrom
lupinitylabs:feature/where-month-day-int-values

Conversation

@lupinitylabs

@lupinitylabs lupinitylabs commented Aug 11, 2022

Copy link
Copy Markdown
Contributor

When trying to pass an integer value to whereMonth() or whereDay(), e.g.

User::whereMonth('updated_at', '=', 4)->get();

PHPstan will report Parameter #3 $value of method Illuminate\Database\Eloquent\Builder<App\Models\User>::whereMonth() expects DateTimeInterface|string|null, int given.

At the same time,

User::whereYear('updated_at', '=', 2022)->get();

will accept integer values.

This PR suggests to make the type definitions for whereYear(), whereMonth() and whereDay() more consistent by adding the int type to the @param docblock for $value.

I am swapping out the usage of str_pad() with sprintf() because the latter will accept mixed arguments, whereas for str_pad(), we would have to convert int values to strings first (and it's more compact, too).

@lupinitylabs lupinitylabs changed the title Allow for int value parameters for whereMonth() and whereDay() [9.x] Allow for int value parameters for whereMonth() and whereDay() Aug 11, 2022
@lupinitylabs

lupinitylabs commented Aug 11, 2022

Copy link
Copy Markdown
Contributor Author

Looks like the failing test is unrelated...?

@lupinitylabs lupinitylabs changed the title [9.x] Allow for int value parameters for whereMonth() and whereDay() [9.x] Allow for int value parameters to whereMonth() and whereDay() Aug 11, 2022
@taylorotwell taylorotwell merged commit c951ba7 into laravel:9.x Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants