Skip to content

Commit

Permalink
partially satisfying psalm, updating baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
bapcltd-marv committed Jan 15, 2020
1 parent a04d3aa commit b5fff71
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
23 changes: 4 additions & 19 deletions psalm.baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
<code>$mail-&gt;id</code>
<code>$option &amp;&amp; FT_PREFETCHTEXT</code>
</InvalidScalarArgument>
<LessSpecificReturnStatement occurrences="2">
<code>$out</code>
</LessSpecificReturnStatement>
<MissingParamType occurrences="5">
<code>$str</code>
<code>$str</code>
Expand All @@ -34,7 +31,7 @@
<MissingReturnType occurrences="1">
<code>initMailPart</code>
</MissingReturnType>
<MixedArgument occurrences="51">
<MixedArgument occurrences="50">
<code>$mail-&gt;subject</code>
<code>$mail-&gt;subject</code>
<code>$mail-&gt;from</code>
Expand Down Expand Up @@ -75,7 +72,6 @@
<code>$params['filename']</code>
<code>$fileName</code>
<code>$partStructure-&gt;id</code>
<code>$params['charset']</code>
<code>$element-&gt;charset</code>
<code>$element-&gt;text</code>
<code>$recipient-&gt;mailbox</code>
Expand All @@ -87,7 +83,7 @@
<code>$t[1]-&gt;personal</code>
<code>$t[1]-&gt;personal</code>
</MixedArgument>
<MixedAssignment occurrences="16">
<MixedAssignment occurrences="14">
<code>$value</code>
<code>$mail</code>
<code>$to</code>
Expand All @@ -100,24 +96,21 @@
<code>$subPartStructure</code>
<code>$fileName</code>
<code>$attachment-&gt;disposition</code>
<code>$attachment-&gt;charset</code>
<code>$element</code>
<code>$item</code>
<code>$out[]</code>
</MixedAssignment>
<MixedInferredReturnType occurrences="2">
<code>string</code>
<code>string</code>
</MixedInferredReturnType>
<MixedOperand occurrences="8">
<MixedOperand occurrences="7">
<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>
<code>$out[0]</code>
</MixedOperand>
<MixedPropertyAssignment occurrences="4">
<code>$mail</code>
Expand Down Expand Up @@ -155,10 +148,6 @@
<code>$str</code>
<code>$str</code>
</MixedReturnStatement>
<MoreSpecificReturnType occurrences="2">
<code>array{0:string, 1:string}|null</code>
<code>array{0:string|string, 1:string|null, 2:string}</code>
</MoreSpecificReturnType>
<PossiblyFalseOperand occurrences="1">
<code>strpos($name, '}')</code>
</PossiblyFalseOperand>
Expand All @@ -168,9 +157,6 @@
<PossiblyInvalidPropertyFetch occurrences="1">
<code>$mailStructure-&gt;parts</code>
</PossiblyInvalidPropertyFetch>
<PossiblyNullOperand occurrences="1">
<code>$this-&gt;getAttachmentsDir()</code>
</PossiblyNullOperand>
<PossiblyUndefinedArrayOffset occurrences="2">
<code>$t[0]</code>
<code>$t[1]</code>
Expand Down Expand Up @@ -221,9 +207,8 @@
<code>null != $params and !empty($params)</code>
<code>!\is_resource($this-&gt;imapStream) || !imap_ping($this-&gt;imapStream)</code>
</RedundantConditionGivenDocblockType>
<UnusedVariable occurrences="2">
<UnusedVariable occurrences="1">
<code>$value</code>
<code>$convertedString</code>
</UnusedVariable>
</file>
<file src="tests/unit/MailboxTest.php">
Expand Down
22 changes: 16 additions & 6 deletions src/PhpImap/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,8 @@ protected function initMailPart(IncomingMail $mail, $partStructure, $partNum, $m
* @param int $mailId ID of mail
* @param bool $emlOrigin True, if it indicates, that the attachment comes from an EML (mail) file
*
* @psalm-param array<string, mixed> $params
*
* @return IncomingMailAttachment $attachment
*/
public function downloadAttachment(DataPartInfo $dataInfo, $params, $partStructure, $mailId, $emlOrigin = false)
Expand All @@ -1328,20 +1330,25 @@ public function downloadAttachment(DataPartInfo $dataInfo, $params, $partStructu
$attachment->contentId = $partStructure->ifid ? trim($partStructure->id, ' <>') : null;
$attachment->name = $fileName;
$attachment->disposition = (isset($partStructure->disposition) ? $partStructure->disposition : null);
if (isset($params['charset']) && !\is_string($params['charset'])) {
throw new InvalidArgumentException('Argument 2 passed to '.__METHOD__.'() must specify charset as a string when specified!');
}
$attachment->charset = (isset($params['charset']) and !empty(trim($params['charset']))) ? $params['charset'] : null;
$attachment->emlOrigin = $emlOrigin;

$attachment->addDataPartInfo($dataInfo);

if (null != $this->getAttachmentsDir()) {
$attachmentsDir = $this->getAttachmentsDir();

if (null != $attachmentsDir) {
$replace = [
'/\s/' => '_',
'/[^\w\.]/iu' => '',
'/_+/' => '_',
'/(^_)|(_$)/' => '',
];
$fileSysName = preg_replace('~[\\\\/]~', '', $mailId.'_'.$attachment->id.'_'.preg_replace(array_keys($replace), $replace, $fileName));
$filePath = $this->getAttachmentsDir().\DIRECTORY_SEPARATOR.$fileSysName;
$filePath = $attachmentsDir.\DIRECTORY_SEPARATOR.$fileSysName;

if (\strlen($filePath) > 255) {
$ext = pathinfo($filePath, PATHINFO_EXTENSION);
Expand Down Expand Up @@ -1459,7 +1466,6 @@ public function convertStringEncoding($string, $fromEncoding, $toEncoding)
if (preg_match('/default|ascii/i', $fromEncoding) || !$string || $fromEncoding == $toEncoding) {
return $string;
}
$convertedString = '';
$supportedEncodings = array_map('strtolower', mb_list_encodings());
if (\in_array(strtolower($fromEncoding), $supportedEncodings) && \in_array(strtolower($toEncoding), $supportedEncodings)) {
$convertedString = mb_convert_encoding($string, $toEncoding, $fromEncoding);
Expand Down Expand Up @@ -1655,7 +1661,7 @@ protected function getCombinedPath($folder, $absolute = false)
/**
* @return array|null
*
* @psalm-return array{0:string, 1:string}|null
* @psalm-return array{0:string, 1:string|null}|null
*/
protected function possiblyGetEmailAndNameFromRecipient(object $recipient)
{
Expand Down Expand Up @@ -1703,15 +1709,19 @@ protected function possiblyGetMailboxes($t)
*
* @return array
*
* @psalm-return array{0:string|string, 1:string|null, 2:string}
* @psalm-return array{0:string|null, 1:string|null, 2:string}
*/
protected function possiblyGetHostNameAndAddress($t)
{
$out = [];
/** @var string|null */
$out[] = isset($t[0]->host) ? $t[0]->host : (isset($t[1]->host) ? $t[1]->host : null);
/** @var string|null */
$out[] = (isset($t[0]->personal) and !empty(trim($t[0]->personal))) ? $this->decodeMimeStr($t[0]->personal, $this->getServerEncoding()) : ((isset($t[1]->personal) and (!empty(trim($t[1]->personal)))) ? $this->decodeMimeStr($t[1]->personal, $this->getServerEncoding()) : null);
$out[] = strtolower($t[0]->mailbox.'@'.$out[0]);
/** @var string */
$out[] = strtolower($t[0]->mailbox.'@'.(string)$out[0]);

/** @var array{0:string|null, 1:string|null, 2:string} */
return $out;
}

Expand Down

0 comments on commit b5fff71

Please sign in to comment.