Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detailed return types for str_pad() and str_repeat() #6094

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions stubs/CoreGenericFunctions.phpstub
Original file line number Diff line number Diff line change
Expand Up @@ -762,13 +762,26 @@ function str_ireplace($search, $replace, $subject, &$count = null) {}
/**
* @psalm-pure
*
* @return ($input is non-empty-string ? non-empty-string : ($pad_length is positive-int ? non-empty-string: string))
*
* @psalm-flow ($input, $pad_string) -> return
*/
function str_pad(string $input, int $pad_length, $pad_string = '', int $pad_type = STR_PAD_RIGHT): string {}

/**
* @psalm-pure
*
* @todo update $multiplier to be `0|positive-int`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you left this on purpose?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. str_repeat() throws warnings when given negative int, but Psalm was emitting too many false positive coercion issues (int -> positive int) even on its own codebase.

* @return (
* $input is non-empty-string
* ? (
* $multiplier is positive-int
* ? non-empty-string
* : ($multiplier is 0 ? '' : string)
* )
* : ($multiplier is 0 ? '' : string)
* )
*
* @psalm-flow ($input) -> return
*/
function str_repeat(string $input, int $multiplier): string {}
Expand Down