Replies: 1 comment
-
The message:
Tells you your code is wrong in this case: class MyListItemDto extends ListItemDto {}
/** @param ListItemToDtoTransformer<ListItemEntity, MyListItemDto> $transformer */
function foo(ListItemToDtoTransformer $transformer): void
{
$item = $transformer->createDto(); // I know the method is protected, but I need to show the example
// $item is supposed to be MyListItemDto but you're always returning ListItemDto
} If I remove generics altogether from your code (https://phpstan.org/r/f4a1e8e6-19a5-43fa-bd6c-f88fcd30ae3c), the types describe exactly what's going on and there's no error. In order to help you I need to hear from you what kind of problem you're trying to describe and solve. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I currently can't figure out why this snippet
https://phpstan.org/r/6d8637e6-e82f-419a-9f0e-3f75ad87fd06
breaks contract:
Method ListItemToDtoTransformer::createDto() should return TListItemDto of ListItemDto but returns ListItemDto.
Type ListItemDto is not always the same as TListItemDto. It breaks the contract for some argument types, typically subtypes.
My intention is to create subclass of Transformer when I need to transform extra parameters of ListItemEntity to some DTO which will be subclass of ListItemDto. Such DTO will be created in overriden method createDto. Also need to run transformation when no extra fields are needed, no child classes present -> and here I run into issue.
Beta Was this translation helpful? Give feedback.
All reactions