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

Add type for join method #4421

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open

Add type for join method #4421

wants to merge 1 commit into from

Conversation

ruudk
Copy link
Contributor

@ruudk ruudk commented Oct 28, 2024

Looking at the code, this method is very forgiving in what it accepts.

This helps PHPStan to not complain when something other than an array is passed.

Did I miss other types?

/cc @stof

* @param array $value An array
* @param string $glue The separator
* @param string|null $and The separator for the last pair
* @param iterable|array|string|float|int|bool|object|null $value An array
Copy link
Member

Choose a reason for hiding this comment

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

object should probably be Stringable instead, as non-stringable objects won't work in implode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is casted to array, https://3v4l.org/FqgLS

Copy link
Member

Choose a reason for hiding this comment

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

oh. This is probably unexpected behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So what to do?

/cc @fabpot

Copy link
Member

@stof stof Oct 30, 2024

Choose a reason for hiding this comment

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

I would suggest not including object in the type here (without changing the implementation for now). This would make TwigStan report cases triggering this weird behavior as mistakes.
I'm not sure about the scalar types, for which the casting is more usable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, done!

@ruudk ruudk requested a review from stof October 28, 2024 09:19
Looking at the code, this method is very forgiving in what it accepts.
@ruudk
Copy link
Contributor Author

ruudk commented Nov 1, 2024

@fabpot this one is ready

@ruudk
Copy link
Contributor Author

ruudk commented Nov 1, 2024

You can see here how it works:
twigstan/twigstan#90

I had to ignore the error that is fixed by this PR:
https://github.com/twigstan/twigstan/blob/d7a85dab53b9d9146169185e9d0225d0b6c52c24/tests/EndToEnd/Filters/errors.json

@ruudk
Copy link
Contributor Author

ruudk commented Nov 5, 2024

@fabpot What's needed to get this PR merged? Do I need to do changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants