Methods typed to return MessageIteratorInterface
Many methods that are typed to return MessageIteratorInterface, actually return MessageIterator. (see Mailbox class). The interface lacks every method stub from ArrayIterator class, which MessageIterator extends from.
This is ~~wrong~~ incomplete method typing, and causes IDE inspectors to complain when using array functions (count, sort, ...) to a MessageIteratorInterface result, and also to not autocomplete any of the ArrayIterator methods.
Maybe making the MessageIteratorInterface implement every other interface that ArrayIterator too implements should do the trick.
For now, only solution is to PHPDoc:
/** @var MessageIterator $messages */
$messages = $inbox->getMessages($search);
This is wrong method typing, and causes IDE inspectors to complain when using array functions (count, sort, ...) to a MessageIteratorInterface result, and also to not autocomplete any of the ArrayIterator methods.
This is not wrong, it's perfectly legit to declare a contract and return an extension of that contract. The contract states that you are capable and allowed to do everything and only the contract states, and use the extensions at your own risk. Those are the principles of Covariance and contravariance
Maybe making the MessageIteratorInterface implement every other interface that ArrayIterator too implements should do the trick.
This would help for sure, but cannot solve all the use cases: all the sorting functions of ArrayIterator lack a corresponding interface.
Would you create a PR that implement what you're saying please?