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

Fix method annotations in ClientInterface for lpush and similar #1160

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

Conversation

kwidua
Copy link

@kwidua kwidua commented Feb 17, 2023

I adjusted the second parameter of lpush and other methods where this also applies to be array|string ...$values instead of just array $values, in order to fix psalm warning.

Fixes #1146

@tillkruss
Copy link
Member

@vladvildanov What the correct annotation for this?

@vladvildanov
Copy link
Contributor

@tillkruss Are you talking about broken CI or...?

@tillkruss
Copy link
Member

@tillkruss Are you talking about broken CI or...?

No, I mean array|string ...$fields. Does that not imply function($array, $array) would also work?

@vladvildanov
Copy link
Contributor

@tillkruss In my opinion, we should only support string ...$fields and do not specify array at all, so user won't be confused and this fits original documentation https://redis.io/commands/hdel/. All the existing functionality won't break because under the hood we still support array, but we don't need to specify this and stick to original documentation 👌

@tillkruss
Copy link
Member

@kwidua What do you think about just using string ...?

@kwidua
Copy link
Author

kwidua commented Feb 23, 2023

What about everyone that has used array before, for them the psalm checks would fail then?

@tillkruss
Copy link
Member

What about everyone that has used array before, for them the psalm checks would fail then?

I'm not sure if array|string ...$value works, doesn't that imply call_me([], []) must work as well? If so, we need a test case for that.

@vladvildanov
Copy link
Contributor

vladvildanov commented Feb 24, 2023

@tillkruss Exactly, it means that it could be call_me([], []), that's why I'm against this approach. I believe that we need to support it the way it represented in Redis docs as string ...argument, yeah it will break IDE psalm check, but it will softly force people to change it in code with just prepend ... to existing array, we need to stop support incorrect interface.

P.S New commands support includes only ... approach if it's possible

@tillkruss
Copy link
Member

I agree with @vladvildanov here, @kwidua. array|string ...$fields does not seem like a valid signature.

We can update the signatures to string ...$fields in the 3.x branch if you like.

If this is causing issues with your linters right now, feel free to update the test suite to resolve it in the 2.x branch.

@tillkruss tillkruss self-assigned this Feb 24, 2023
@kwidua
Copy link
Author

kwidua commented Feb 28, 2023

@tillkruss sorry for the delayed reply. If you prefer string ...$fields that's fine.
I don't quite understand what you mean by to update the test suite to resolve it in the 2.x branch. - can you maybe explain that? :)

@tillkruss
Copy link
Member

@tillkruss sorry for the delayed reply. If you prefer string ...$fields that's fine.

No worries. string ... is great.

I don't quite understand what you mean by to update the test suite to resolve it in the 2.x branch. - can you maybe explain that? :)

Yes, I meant if any of the tests in the Predis suite need to be adjusted to please your local or CI linters, you can to adjust the code in tests/ as well.

@tillkruss tillkruss force-pushed the 1146-clientinterface-annotations branch from edaba2b to fa40521 Compare September 13, 2023 16:52
@tillkruss tillkruss self-requested a review as a code owner September 13, 2023 16:52
@tillkruss
Copy link
Member

tillkruss commented Sep 13, 2023

@szepeviktor: What's the correct notation to support foo($array) as well as foo($string, $string, $string)?

@szepeviktor
Copy link
Contributor

szepeviktor commented Sep 13, 2023

@tillkruss I am sorry. That is called bad design.
PHP type hints are not/will not be able to describe that after the first parameter ($array) there must not be a second nor a third parameter.

@@ -161,15 +161,15 @@
* @method int setnx(string $key, $value)
* @method int setrange(string $key, $offset, $value)
* @method int strlen(string $key)
* @method int hdel(string $key, array $fields)
* @method int hdel(string $key, array|string ...$fields)
Copy link
Member

Choose a reason for hiding this comment

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

@kwidua @szepeviktor: Wouldn't the correct notation be this?

hdel(string $key, array|string $fields, string ...$extra_fields)

Copy link
Contributor

Choose a reason for hiding this comment

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

No. Variable-length argument lists cannot be in union with something else.

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

Successfully merging this pull request may close these issues.

Second parameter of lpush should be variable-length argument list
4 participants