Sitelet https://github.com/predis/predis/pull/1160
Skip to content

Fix method annotations in ClientInterface for lpush and similar - #1160

Open
kwidua wants to merge 1 commit into
predis:v2.xfrom
kwidua:1146-clientinterface-annotations
Open

kwidua wants to merge 1 commit into
predis:v2.xfrom
kwidua:1146-clientinterface-annotations

Conversation

@kwidua

@kwidua kwidua commented Feb 17, 2023

Copy link
Copy Markdown

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
Copy Markdown
Member

@vladvildanov What the correct annotation for this?

@vladvildanov

Copy link
Copy Markdown
Contributor

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

@tillkruss

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

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

@kwidua

kwidua commented Feb 23, 2023

Copy link
Copy Markdown
Author

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

@tillkruss

Copy link
Copy Markdown
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

vladvildanov commented Feb 24, 2023 •

Copy link
Copy Markdown
Contributor

@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
Copy Markdown
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

kwidua commented Feb 28, 2023 •

Copy link
Copy Markdown
Author

@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
Copy Markdown
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

tillkruss commented Sep 13, 2023 •

Copy link
Copy Markdown
Member

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

@szepeviktor

szepeviktor commented Sep 13, 2023 •

Copy link
Copy Markdown
Contributor

@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.

Comment thread src/ClientInterface.php
* @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
Copy Markdown
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
Copy Markdown
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.

@tillkruss tillkruss removed their assignment Apr 15, 2025
@thePanz

thePanz commented Jun 26, 2025

Copy link
Copy Markdown

Any updates on this? Or any help needed?

@tillkruss

Copy link
Copy Markdown
Member

Any updates on this? Or any help needed?

Feel free to open a new PR targeting main with the correct annotations.

thePanz added a commit to thePanz/predis that referenced this pull request Jun 26, 2025
This integrates and extends changes from predis#1160 by @kwidua
@thePanz thePanz mentioned this pull request Jun 26, 2025
thePanz added a commit to thePanz/predis that referenced this pull request Jun 26, 2025
This integrates and extends changes from predis#1160 by @kwidua
@thePanz

thePanz commented Jun 26, 2025

Copy link
Copy Markdown

@tillkruss done in #1570

Would you be OK to get the same changes for the v2.x branch too?

thePanz added a commit to thePanz/predis that referenced this pull request Jun 26, 2025
This integrates and extends changes from predis#1160 by @kwidua
thePanz added a commit to thePanz/predis that referenced this pull request Jun 27, 2025
This integrates and extends changes from predis#1160 by @kwidua
thePanz added a commit to thePanz/predis that referenced this pull request Jun 27, 2025
This integrates and extends changes from predis#1160 by @kwidua
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

5 participants