[12.x] Improve types in \Illuminate\Support\Str helper#58356
[12.x] Improve types in \Illuminate\Support\Str helper#58356taylorotwell merged 1 commit intolaravel:12.xfrom
\Illuminate\Support\Str helper#58356Conversation
|
Test failure doesn't seem to be related to changes |
|
I really wish there was just |
|
Fair point 🤔 I used what was already used elsewhere. Let's see what Taylor has to say |
|
I don't really know if phpstan even has a custom return tag, but others psalm etc. do for the same reason as mentioned. I find it kind of a weird phpstan choice to use custom syntax on an already established tag. Currently have problems with other functions that have this and no explicit return type as it just ends up being mixed in IDE. |
It does:
I didn't know that 😲 That really isn't ideal 😕 Maybe, we should prefix all conditional returns in Laravel 🤔 |
|
I must be bad at searching then 😅 tried to skim through with search and found nothing. As the framework already is embracing phpstan as default it's probably not in interest to yet again get a flood of changes so it is what it is. Saw that PHPStorm tries to support it best it can at the type level but ain't always on point, especially on the nested conditions where it just drops half of the condition types so maybe it will get better and won't matter in the long run. At least from the JetBrains side 😬 |
Good to know that I'm not the only one who gets a little lost in the PHPStan docs 😅 |
wwright216
left a comment
There was a problem hiding this comment.
I know this has already been merged (and now released) but....
| * @param array|string $subject | ||
| * @param string|string[] $pattern | ||
| * @param (\Closure(array): string)|string[]|string $replace | ||
| * @param array|string[] $subject |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks for the suggestions, there's already a PR for this: #58364
| * @param array|string[] $subject | ||
| * @param int $limit | ||
| * @return string|string[]|null | ||
| * @return ($subject is array ? string|null : string[]|null) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Add explicit array|string parameter type hint and string return type to the toCssClasses method, following the pattern established in recent type improvement PRs like laravel#58356. This improves type safety and IDE support without changing functionality.
Add explicit array|string parameter type hint and string return type to the toCssStyles method, following the pattern established in recent type improvement PRs like laravel#58356. This improves type safety and IDE support without changing functionality.
Add explicit mixed parameter type hint and bool return type to the accessible method, following the pattern established in recent type improvement PRs like laravel#58356. This improves type safety and IDE support without changing functionality.
Add explicit mixed parameter type hint and bool return type to the arrayable method, following the pattern established in recent type improvement PRs like laravel#58356. This improves type safety and IDE support without changing functionality.
Benefits
✅ Improved static analysis
✅ Improved type inference
✅ Increased type coverage
Highlights
non-empty-stringassertions