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

Add @mixin to FieldItemListInterface to explain that properties of its first item are being forwarded #782

Open
ceesgeene opened this issue Jul 10, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@ceesgeene
Copy link
Contributor

Feature request

Using @mixin it is possible to explain that instances of FieldItemListInterface forward the properties its items:

/**
 * @template T of FieldItemInterface
 * @extends ListInterface<T>
 * @property mixed $value
 * @mixin T
 */
interface FieldItemListInterface extends ListInterface {
}

This would allow for things like:

/** @var \Drupal\Core\Field\FieldItemListInterface<\Drupal\text\Plugin\Field\FieldType\TextWithSummaryItem> $node_body */
$node_body = $node->get('body');

$body = $node_body->processed;

Unfortunately @mixin also forwards methods. Hopefully @mixin-properties will be introduced, or @mixin will auto-detect what is being forwarded:

phpstan/phpstan #11259: Fine-grained mixin support

@ceesgeene ceesgeene added the enhancement New feature or request label Jul 10, 2024
@ceesgeene ceesgeene changed the title Add @mixin to FieldItemListInterface to explain that item properties are being forwarded Add @mixin to FieldItemListInterface to explain that properties of its first item are being forwarded Jul 10, 2024
@mglaman
Copy link
Owner

mglaman commented Jul 10, 2024

Unfortunately @mixin also forwards methods

What would be the consequence? That BodyItem methods would appear as valid on the list?

@ceesgeene
Copy link
Contributor Author

Yes, so for example phpstan incorrectly assumes $node->get('body')->mainPropertyName() is valid.

@mglaman
Copy link
Owner

mglaman commented Jul 11, 2024

Ah, yeah. It'd be great for some kind of mixin that only supported certain magic methods

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