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

Support more consequences of non-empty collections #113

Open
janopae opened this issue Mar 2, 2022 · 1 comment
Open

Support more consequences of non-empty collections #113

janopae opened this issue Mar 2, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@janopae
Copy link

janopae commented Mar 2, 2022

Since #94, this extension supports the scenario of checking a Collections's emptiness and then using first() and last() on that collection without worrying about the return type being false. This is great, however, a Collection being empty has more effects than this, including:

  • toArray() returning a non-empty-array
  • getKeys() returning a non-empty-list
  • getValues() returning a non-empty-list
  • code in loops iterating over a non-empty array will be executed at least once

Also, a Collection being empty could be asserted by

  • checking count() returns a value other than 0
  • calling add() at least once
  • calling set() at least once
  • calling a custom method that was annotated with @psalm-assert !$collection->isEmpty() with the collection
  • checking contains() returns true
  • checking current() doesn't return false
  • checking key() doesn't return null
  • checking next() doesn't return false
  • the Collection being created using the map() method of another non-empty Collection
  • checking indexOf() doesn't return false
@janopae janopae changed the title Support more consequences consequences of non-empty collections Support more consequences of non-empty collections Mar 2, 2022
@orklah
Copy link
Collaborator

orklah commented Mar 3, 2022

Seems cool! Can you propose a PR based on this?

@orklah orklah added the enhancement New feature or request label Mar 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants