zbateson / mail-mime-parser

An email parser written in PHP
https://mail-mime-parser.org/
BSD 2-Clause "Simplified" License
441 stars 56 forks source link

"Header\IHeader" does not contain "getEmail()" #233

Open ghnp5 opened 3 months ago

ghnp5 commented 3 months ago
$message = Message::from($raw_email, true);
$from = $message->getHeader('From');
$email = mb_strtolower($from->getEmail());

getHeader returns IHeader, but IHeader does not contain getEmail.

The code works, but my IDE complains :)

Thanks!

zbateson commented 3 months ago

Hi @ghnp5 -- you're not wrong, getEmail is part of AddressHeader which is what's returned if you call getHeader('From') -- a class that implements IHeader.

I don't know what makes the most sense here, maybe in documentation I can specify all the concrete classes returned so IDEs are happy. Another option could be to put a docblock before the $from line, or actually specify all classes that could be returned in the function's signature. Open to suggestions if anyone has any.

/* @var AddressHeader $from /

postme commented 3 months ago

I apply the docblock approach, it keeps phpstorm happy