Re: [PSR-5][PSR-19] Is there a way to annotate interface that acts as iterator over some type?

2018-12-11 Thread Chuck Burgess
Yes, out of scope, at least here at the beginning. Once we get a baseline draft covering the minimal "already in use old stuff" covered, I'm expecting us to open up topics on "new stuff" to add, generics included. Not that I'm convinced we'll get that one nailed down to enough agreement that we ca

Re: [PSR-5][PSR-19] Is there a way to annotate interface that acts as iterator over some type?

2018-12-11 Thread Alessandro Lai
This is the issue traking the implementation on PHPStan: https://github.com/phpstan/phpstan/issues/652 Il giorno sabato 8 dicembre 2018 21:44:14 UTC+1, Chuck Burgess ha scritto: > > I'm thinking this use case will probably need to rely on some kind of > collection/generics syntax. Do we know if

Re: [PSR-5][PSR-19] Is there a way to annotate interface that acts as iterator over some type?

2018-12-10 Thread Jan TvrdĂ­k
Yes, it needs generics syntax, making it currently intentionally out-of-scope. If you don't mind ugly hacks with unclear semantics that may stop working in the future, you can also use `iterable|User[]`. On Saturday, December 8, 2018 at 9:44:14 PM UTC+1, Chuck Burgess wrote: > > I'm thinking th

Re: [PSR-5][PSR-19] Is there a way to annotate interface that acts as iterator over some type?

2018-12-08 Thread Chuck Burgess
I'm thinking this use case will probably need to rely on some kind of collection/generics syntax. Do we know if PhpStorm / PHPStan / etc have looked at syntaxes for this use case? CRB *about.me/ashnazg * On Mon, Nov 12, 2018 at 11:38 AM Woody Gilk wrote: > Could we use

Re: [PSR-5][PSR-19] Is there a way to annotate interface that acts as iterator over some type?

2018-11-12 Thread Woody Gilk
Could we use: @return iterable ? Also generators can return key => value: @return iterable Would imply: yield $key => $user; -- Woody Gilk https://shadowhand.me On Mon, Nov 12, 2018 at 11:34 AM Larry Garfield wrote: > On Monday, November 12, 2018 10:06:08 AM CST Chuck Burgess wrote: > >

Re: [PSR-5][PSR-19] Is there a way to annotate interface that acts as iterator over some type?

2018-11-12 Thread Larry Garfield
On Monday, November 12, 2018 10:06:08 AM CST Chuck Burgess wrote: > So here we do indeed have a special IDE implementation to try to deal with > the OP's kind of use case. > > Again, I can't envision a more standardized way to solve this with tags > themselves. > > > I'll mention this again, wit

Re: [PSR-5][PSR-19] Is there a way to annotate interface that acts as iterator over some type?

2018-11-12 Thread Chuck Burgess
So here we do indeed have a special IDE implementation to try to deal with the OP's kind of use case. Again, I can't envision a more standardized way to solve this with tags themselves. I'll mention this again, with regard to this use case though: Stepping back a moment... that /* @var */ usage.

Re: [PSR-5][PSR-19] Is there a way to annotate interface that acts as iterator over some type?

2018-11-12 Thread Chuck Burgess
In Larry's example, I could envision the usage of the same @param with the code signatures of (array $things) as well as (iterable $things), and both be acceptable. Both seem to say "a collection Things", with the difference being the expected retrieval mechanism in the code signature typehint (ar

Re: [PSR-5][PSR-19] Is there a way to annotate interface that acts as iterator over some type?

2018-11-12 Thread Alexey Gopachenko
Gents, in PhpStorm we had to specifically implement support for `Stream` implementing some magic interfaces public final static Map ARRAY_VALUE_PROVIDERS; static{ ARRAY_VALUE_PROVIDERS = new LinkedHashMap<>(); ARRAY_VALUE_PROVIDERS.put("\\Iterator", "#M#C*.current"); ARRAY_VALUE_PROVIDERS.p

Re: [PSR-5][PSR-19] Is there a way to annotate interface that acts as iterator over some type?

2018-11-10 Thread Larry Garfield
Hm, that's not quite what I mean. IDEs would only need to do that level of deep inspection to generate a doc; I don't need them to generate it in this case if it's hard. I'm thinking more like: /** * @param Things[] $things */ function do_stuff(iterable $things) { // ... } The docblock he

Re: [PSR-5][PSR-19] Is there a way to annotate interface that acts as iterator over some type?

2018-11-09 Thread Alan Gabriel Bem
How about allowing something like /** * @var Item[] */ interface Stream extends Traversable {} because I am sure this /** * @iterable Item */ interface Stream extends Traversable {} won't cut it as it is to much of an edge case to be pulled into standard. @Chuck I will outline your feature

Re: [PSR-5][PSR-19] Is there a way to annotate interface that acts as iterator over some type?

2018-11-09 Thread Chuck Burgess
I don't immediately see a way to accomplish this with tags. The closest thing to an idea I can come up with here will be dictating a rule to IDEs: for any variable representing a collection used by a foreach, the IDE must do deep class hierarchy mining to find *any and all potential return mechan

Re: [PSR-5][PSR-19] Is there a way to annotate interface that acts as iterator over some type?

2018-11-09 Thread Larry Garfield
"This variable/return is an iterable of Foo objects" seems like an entirely reasonable thing to do. We already have the de facto standard of Foo[] to mean "an array of Foo objects", but that doesn't technically cover any iterable. (I'm really big on iterables these days, as anyone who follows

Re: [PSR-5][PSR-19] Is there a way to annotate interface that acts as iterator over some type?

2018-11-08 Thread Chuck Burgess
Revisiting this, I'm leaning towards there *not* being a way to accomplish this in the "one place" manner that you are after. CRB On Wednesday, October 17, 2018 at 1:26:32 PM UTC-5, Woody Gilk wrote: > > Wouldn't the simple solution be: > > /** @var $stream Item[] */ > foreach ($stream as $item)

Re: [PSR-5][PSR-19] Is there a way to annotate interface that acts as iterator over some type?

2018-10-17 Thread Woody Gilk
Wouldn't the simple solution be: /** @var $stream Item[] */ foreach ($stream as $item) { /* ... */ } On Tuesday, October 16, 2018 at 2:02:21 PM UTC-5, Alan Gabriel Bem wrote: > > I think you missed my point - What I want to achieve is to *annotate* > somehow that *Stream* is *iterable* over

Re: [PSR-5][PSR-19] Is there a way to annotate interface that acts as iterator over some type?

2018-10-16 Thread Alan Bem
I think you missed my point - What I want to achieve is to *annotate* somehow that *Stream* is *iterable* over *Item* object and do it in *one place* instead of every place I'm using `Stream` implementation. As I mentioned I could enforce using *Iterator* or *IteratorAggregate* (as it opens the wa

Re: [PSR-5][PSR-19] Is there a way to annotate interface that acts as iterator over some type?

2018-10-16 Thread Chuck Burgess
I'm tempted to argue that you're *not* sticking to Design By Contract here, because your two `Stream` implementations do not themselves give the same contract... at least, the parts of the contract that you're wanting to be derived by the IDE. Since it's already necessary to use a `/* @var */`

[PSR-5][PSR-19] Is there a way to annotate interface that acts as iterator over some type?

2018-10-13 Thread Alan Gabeiel Bem
It is easy if such interface already extends some kind of iterator... interface Stream extends IteratorAggregate { /** * @return Item[] */ public function getIterator(); } ...or... interface Stream extends Iterator { /** * @return Item */ public function curr