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

Generic PHPDoc support #165

Closed
Hornet-Wing opened this issue Aug 17, 2020 · 4 comments
Closed

Generic PHPDoc support #165

Hornet-Wing opened this issue Aug 17, 2020 · 4 comments

Comments

@Hornet-Wing
Copy link

Hornet-Wing commented Aug 17, 2020

Would it be possible to support Generic PHPDocs?

For example:

class Zoo
{
    /** @var Animal[] */
    public $animals;
}

would be:

class Zoo
{
    /** @var array<Animal> */
    public $animals;
}
@cweiske
Copy link
Owner

cweiske commented Oct 6, 2020

Is that only for arrays, or are there other types that need to be handled differently?
Also, where do you get that from? Any official sources for that type of array definition?

@dktapps
Copy link
Contributor

dktapps commented Oct 10, 2020

Not sure about Psalm docs, but PHPStan implements generics which are mostly equivalent to Psalm's: https://phpstan.org/blog/generics-in-php-using-phpdocs

@Hornet-Wing
Copy link
Author

Yes, that is correct. I was looking at PHPStan's implementation, but mostly just for array annotation.

@cweiske
Copy link
Owner

cweiske commented Nov 2, 2020

When looking at https://phpstan.org/blog/generics-in-php-using-phpdocs#these-rules-are-useful%2C-but-sometimes-limiting it gets complicated:

/**
 * @template T of Message
 */
interface Consumer
{
  /**
   * @param T $message
   */
  function consume(Message $message);
}

/**
 * @implements Consumer<SendMailMessage>
 */
class SendMailMessageConsumer implements Consumer
{
	function consume(Message $message) { ... }
}

This means that JsonMapper would need to fetch and combine information from different classes in complicated ways.
I will not do that.

Patches welcome, but I guess they complicate the code a lot, for little gain in my eyes. So I'll probably reject them.

@cweiske cweiske closed this as completed Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants