Changed: MailSo\*Collection now extends \ArrayObject

Changed: fixed __constructor param type hinting
Replace: &$o with $o as objects don't need & referencing
This commit is contained in:
djmaze 2020-03-18 23:14:00 +01:00
parent 9bb44e7f98
commit f6fdb69c65
30 changed files with 290 additions and 736 deletions

View file

@ -22,7 +22,7 @@ class AttachmentCollection extends \MailSo\Base\Collection
parent::__construct();
}
public static function NewInstance() : \MailSo\Mail\AttachmentCollection
public static function NewInstance() : self
{
return new self();
}

View file

@ -61,7 +61,7 @@ class FolderCollection extends \MailSo\Base\Collection
public function GetByFullNameRaw(string $sFullNameRaw) : ?\MailSo\Mail\Folder
{
$mResult = null;
foreach ($this->aItems as /* @var $oFolder \MailSo\Mail\Folder */ $oFolder)
foreach ($this as /* @var $oFolder \MailSo\Mail\Folder */ $oFolder)
{
if ($oFolder->FullNameRaw() === $sFullNameRaw)
{
@ -88,7 +88,7 @@ class FolderCollection extends \MailSo\Base\Collection
public function CountRec() : int
{
$iResult = $this->Count();
foreach ($this->aItems as /* @var $oFolder \MailSo\Mail\Folder */ $oFolder)
foreach ($this as /* @var $oFolder \MailSo\Mail\Folder */ $oFolder)
{
if ($oFolder)
{
@ -110,9 +110,9 @@ class FolderCollection extends \MailSo\Base\Collection
$sDelimiter = '/';
$oFolder = $this->GetByFullNameRaw('INBOX');
if (!$oFolder)
if (!$oFolder && isset($this[0]))
{
$oFolder = $this->GetByIndex(0);
$oFolder = $this[0];
}
if ($oFolder)
@ -123,7 +123,7 @@ class FolderCollection extends \MailSo\Base\Collection
return $sDelimiter;
}
public function SetNamespace(string $sNamespace) : \MailSo\Mail\FolderCollection
public function SetNamespace(string $sNamespace) : self
{
$this->Namespace = $sNamespace;
@ -135,7 +135,7 @@ class FolderCollection extends \MailSo\Base\Collection
$this->Clear();
$aSortedByLenImapFolders = array();
foreach ($aUnsortedMailFolders as /* @var $oMailFolder \MailSo\Mail\Folder */ &$oMailFolder)
foreach ($aUnsortedMailFolders as /* @var $oMailFolder \MailSo\Mail\Folder */ $oMailFolder)
{
$aSortedByLenImapFolders[$oMailFolder->FullNameRaw()] =& $oMailFolder;
unset($oMailFolder);
@ -181,7 +181,7 @@ class FolderCollection extends \MailSo\Base\Collection
return \strnatcmp($oFolderA->FullNameRaw(), $oFolderB->FullNameRaw());
});
foreach ($aSortedByLenImapFolders as /* @var $oMailFolder \MailSo\Mail\Folder */ &$oMailFolder)
foreach ($aSortedByLenImapFolders as /* @var $oMailFolder \MailSo\Mail\Folder */ $oMailFolder)
{
$this->AddWithPositionSearch($oMailFolder);
unset($oMailFolder);
@ -194,9 +194,8 @@ class FolderCollection extends \MailSo\Base\Collection
{
$oItemFolder = null;
$bIsAdded = false;
$aList =& $this->GetAsArray();
foreach ($aList as /* @var $oItemFolder \MailSo\Mail\Folder */ $oItemFolder)
foreach ($this as /* @var $oItemFolder \MailSo\Mail\Folder */ $oItemFolder)
{
if ($oMailFolder instanceof \MailSo\Mail\Folder &&
0 === \strpos($oMailFolder->FullNameRaw(), $oItemFolder->FullNameRaw().$oItemFolder->Delimiter()))
@ -213,24 +212,21 @@ class FolderCollection extends \MailSo\Base\Collection
if (!$bIsAdded && $oMailFolder instanceof \MailSo\Mail\Folder)
{
$bIsAdded = true;
$this->Add($oMailFolder);
$this->append($oMailFolder);
}
return $bIsAdded;
}
/**
* @param callable $fCallback
*/
public function SortByCallback($fCallback) : void
public function SortByCallback(callable $fCallback) : void
{
if (\is_callable($fCallback))
{
$aList =& $this->GetAsArray();
$aList = $this->getArrayCopy();
\usort($aList, $fCallback);
foreach ($aList as &$oItemFolder)
foreach ($aList as $oItemFolder)
{
if ($oItemFolder->HasSubFolders())
{

View file

@ -1502,7 +1502,7 @@ class MailClient
{
$aFetchIndexArray = array();
$oFetchResponseItem = null;
foreach ($aFetchResponse as /* @var $oFetchResponseItem \MailSo\Imap\FetchResponse */ &$oFetchResponseItem)
foreach ($aFetchResponse as /* @var $oFetchResponseItem \MailSo\Imap\FetchResponse */ $oFetchResponseItem)
{
$aFetchIndexArray[($bIndexAsUid)
? $oFetchResponseItem->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::UID)
@ -1515,7 +1515,7 @@ class MailClient
{
if (isset($aFetchIndexArray[$iFUid]))
{
$oMessageCollection->Add(
$oMessageCollection->append(
Message::NewFetchResponseInstance(
$oMessageCollection->FolderName, $aFetchIndexArray[$iFUid]));
}
@ -1534,28 +1534,6 @@ class MailClient
$this->oImapClient->IsSupported('THREAD=ORDEREDSUBJECT');
}
/**
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Imap\Exceptions\Exception
*/
public function MessageListSimple(string $sFolderName, array $aUids) : \MailSo\Mail\MessageCollection
{
if (0 === \strlen($sFolderName) || !\MailSo\Base\Validator::NotEmptyArray($aUids))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
}
$this->oImapClient->FolderExamine($sFolderName);
$oMessageCollection = \MailSo\Mail\MessageCollection::NewInstance();
$oMessageCollection->FolderName = $sFolderName;
$this->MessageListByRequestIndexOrUids($oMessageCollection, $aUids, true, true);
return $oMessageCollection->GetAsArray();
}
/**
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
* @throws \MailSo\Net\Exceptions\Exception

View file

@ -742,7 +742,7 @@ class Message
$this->oAttachments = AttachmentCollection::NewInstance();
foreach ($aAttachmentsParts as /* @var $oAttachmentItem \MailSo\Imap\BodyStructure */ $oAttachmentItem)
{
$this->oAttachments->Add(
$this->oAttachments->append(
\MailSo\Mail\Attachment::NewBodyStructureInstance($this->sFolder, $this->iUid, $oAttachmentItem)
);
}