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

[BUG]: ResultsetInterface missing methods #16534

Open
noone-silent opened this issue Feb 27, 2024 · 1 comment
Open

[BUG]: ResultsetInterface missing methods #16534

noone-silent opened this issue Feb 27, 2024 · 1 comment
Labels
bug A bug report status: unverified Unverified

Comments

@noone-silent
Copy link

Describe the bug
The ResultInterface is missing methods that are available to all result sets. Simple and Complex both only extend Resultset. Resultset is the only Class that implements ResultsetInterface. Therefor all methods from Resultset should also be in ResultsetInterface. For example currently the count() method is missing. So to make static code analyzer happy, we need to add a phpdoc overwrite of the type, or use count($model->toArray()).

To Reproduce
Read code

Expected behavior
In general all Interfaces should be checked for missing methods.

Screenshots

Details

  • Phalcon version: 5.6.1
  • PHP Version: 8.1
  • Operating System: debian
  • Installation type: sury
  • Zephir version (if any): -
  • Server: nginx
  • Other related info (Database, table schema): mariadb
@noone-silent noone-silent added bug A bug report status: unverified Unverified labels Feb 27, 2024
@jturbide
Copy link
Sponsor Contributor

I strongly agree for this one. I was about to open another issue but it seems to be exactly my problem as well. Static code analyzers such as Psalm, PHPStan will report false-positive error when iterating results from "Model::find()" requests.

Argument of an invalid type Phalcon\Mvc\Model\ResultsetInterface supplied for foreach, only iterables are supported.

\Phalcon\Mvc\Model\ResultsetInterface should extend \Iterator, \SeekableIterator, \Countable, \ArrayAccess, \Serializable, \JsonSerializable directly from the interface definition instead of implementing those in the "Resultset" class.

Using the current Phalcon version 5.6.2, just to make the static code analyzers happy, we have to do unnecessary ignores or assertations like this:

$users = User::find();
assert($users instanceof \Iterator);
foreach ($users as $user) {
    // ...
}

If it's not possible to alter the \Phalcon\Mvc\Model\ResultsetInterface, then I would opt for another interface \Phalcon\Mvc\Model\IterableResultsetInterface which would extend \Phalcon\Mvc\Model\ResultsetInterface, \Iterator, \SeekableIterator, \Countable, \ArrayAccess, \Serializable, \JsonSerializable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: unverified Unverified
Projects
None yet
Development

No branches or pull requests

2 participants