Skip to content

Commit

Permalink
refactoring conditional to for type safety (re: vimeo/psalm#2619 & vi…
Browse files Browse the repository at this point in the history
  • Loading branch information
markovlatkovic committed Jan 16, 2020
1 parent 27c8181 commit a9bfb12
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
8 changes: 2 additions & 6 deletions psalm.baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<code>$mailId</code>
<code>$mailId</code>
</MissingParamType>
<MixedArgument occurrences="50">
<MixedArgument occurrences="48">
<code>$mail-&gt;subject</code>
<code>$mail-&gt;subject</code>
<code>$mail-&gt;from</code>
Expand Down Expand Up @@ -74,8 +74,6 @@
<code>$partStructure-&gt;id</code>
<code>$element-&gt;charset</code>
<code>$element-&gt;text</code>
<code>$recipient-&gt;mailbox</code>
<code>$recipient-&gt;host</code>
<code>$recipient-&gt;personal</code>
<code>$recipient-&gt;personal</code>
<code>$t[0]-&gt;personal</code>
Expand All @@ -102,13 +100,11 @@
<code>string</code>
<code>string</code>
</MixedInferredReturnType>
<MixedOperand occurrences="7">
<MixedOperand occurrences="5">
<code>$params[$paramName]</code>
<code>$subPartNum</code>
<code>$subPartNum</code>
<code>$partStructure-&gt;ifid ? $partStructure-&gt;id : ''</code>
<code>$recipient-&gt;mailbox</code>
<code>$recipient-&gt;host</code>
<code>$t[0]-&gt;mailbox</code>
</MixedOperand>
<MixedPropertyFetch occurrences="20">
Expand Down
18 changes: 16 additions & 2 deletions src/PhpImap/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -1677,14 +1677,28 @@ protected function getCombinedPath($folder, $absolute = false)
*/
protected function possiblyGetEmailAndNameFromRecipient(object $recipient)
{
if (isset($recipient->mailbox, $recipient->host) && '' !== trim($recipient->mailbox) && '' !== trim($recipient->host)) {
$recipientEmail = strtolower($recipient->mailbox.'@'.$recipient->host);
if (isset($recipient->mailbox, $recipient->host)) {
/** @var mixed */
$recipientMailbox = $recipient->mailbox;

/** @var mixed */
$recipientHost = $recipient->host;

if (!\is_string($recipientMailbox)) {
throw new UnexpectedValueException('mailbox was present on argument 1 passed to '.__METHOD__.'() but was not a string!');
} elseif (!\is_string($recipientHost)) {
throw new UnexpectedValueException('host was present on argument 1 passed to '.__METHOD__.'() but was not a string!');
}

if ('' !== trim($recipientMailbox) && '' !== trim($recipientHost)) {
$recipientEmail = strtolower($recipientMailbox.'@'.$recipientHost);
$recipientName = (isset($recipient->personal) and !empty(trim($recipient->personal))) ? $this->decodeMimeStr($recipient->personal, $this->getServerEncoding()) : null;

return [
$recipientEmail,
$recipientName,
];
}
}

return null;
Expand Down

0 comments on commit a9bfb12

Please sign in to comment.