Remove useless NewInstance

Bugfix: BodyStructure->SearchCharset return value
This commit is contained in:
djmaze 2020-05-08 11:49:18 +02:00
parent 82e560bc53
commit 693e0f4c10
61 changed files with 802 additions and 1345 deletions

View file

@ -32,7 +32,7 @@ class Attachment
*/
private $oBodyStructure;
private function __construct()
function __construct()
{
$this->Clear();
}
@ -148,14 +148,9 @@ class Attachment
return $this->oBodyStructure ? $this->oBodyStructure->IsPgpSignature() : false;
}
public static function NewInstance() : self
{
return new self();
}
public static function NewBodyStructureInstance(string $sFolder, int $iUid, \MailSo\Imap\BodyStructure $oBodyStructure) : self
{
return self::NewInstance()->InitByBodyStructure($sFolder, $iUid, $oBodyStructure);
return (new self)->InitByBodyStructure($sFolder, $iUid, $oBodyStructure);
}
public function InitByBodyStructure(string $sFolder, int $iUid, \MailSo\Imap\BodyStructure $oBodyStructure) : self

View file

@ -17,11 +17,6 @@ namespace MailSo\Mail;
*/
class AttachmentCollection extends \MailSo\Base\Collection
{
public static function NewInstance() : self
{
return new self();
}
public function append($oAttachment, bool $bToTop = false) : void
{
assert($oAttachment instanceof Attachment);

View file

@ -50,7 +50,7 @@ class Folder
/**
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
private function __construct(\MailSo\Imap\Folder $oImapFolder, bool $bSubscribed = true, bool $bExisten = true)
function __construct(\MailSo\Imap\Folder $oImapFolder, bool $bSubscribed = true, bool $bExisten = true)
{
$this->oImapFolder = $oImapFolder;
$this->oSubFolders = null;
@ -69,22 +69,14 @@ class Folder
$this->bExisten = $bExisten;
}
/**
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public static function NewInstance(\MailSo\Imap\Folder $oImapFolder, bool $bSubscribed = true, bool $bExisten = true) : self
{
return new self($oImapFolder, $bSubscribed, $bExisten);
}
/**
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public static function NewNonExistenInstance(string $sFullNameRaw, string $sDelimiter) : self
{
return self::NewInstance(
\MailSo\Imap\Folder::NewInstance($sFullNameRaw, $sDelimiter, array('\NoSelect')), true, false);
return new self(
new \MailSo\Imap\Folder($sFullNameRaw, $sDelimiter, array('\NoSelect')), true, false);
}
public function Name() : string
@ -142,7 +134,7 @@ class Folder
{
if ($bCreateIfNull && !$this->oSubFolders)
{
$this->oSubFolders = FolderCollection::NewInstance();
$this->oSubFolders = new FolderCollection;
}
return $this->oSubFolders;

View file

@ -42,9 +42,9 @@ class FolderCollection extends \MailSo\Base\Collection
*/
public $SystemFolders;
protected function __construct()
function __construct($input = array())
{
parent::__construct();
parent::__construct($input);
$this->Namespace = '';
$this->FoldersHash = '';
@ -53,11 +53,6 @@ class FolderCollection extends \MailSo\Base\Collection
$this->Optimized = false;
}
public static function NewInstance() : self
{
return new self();
}
public function append($oFolder, bool $bToTop = false) : void
{
assert($oFolder instanceof Folder);

View file

@ -27,19 +27,14 @@ class MailClient
*/
private $oImapClient;
private function __construct()
function __construct()
{
$this->oLogger = null;
$this->oImapClient = \MailSo\Imap\ImapClient::NewInstance();
$this->oImapClient = new \MailSo\Imap\ImapClient;
$this->oImapClient->SetTimeOuts(10, \MailSo\Config::$ImapTimeout);
}
public static function NewInstance() : self
{
return new self();
}
public function ImapClient() : \MailSo\Imap\ImapClient
{
return $this->oImapClient;
@ -274,7 +269,7 @@ class MailClient
{
if (!\MailSo\Base\Validator::RangeInt($iIndex, 1))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->FolderSelect($sFolderName);
@ -364,7 +359,7 @@ class MailClient
{
if (!is_callable($mCallback))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->FolderSelect($sFolderName);
@ -390,7 +385,7 @@ class MailClient
if (0 < \strlen($sMime))
{
$oHeaders = \MailSo\Mime\HeaderCollection::NewInstance()->Parse($sMime);
$oHeaders = new \MailSo\Mime\HeaderCollection($sMime);
if (0 < \strlen($sMimeIndex))
{
@ -455,7 +450,7 @@ class MailClient
{
if (0 === \strlen($sFolder) || 0 === \count($aIndexRange))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->FolderSelect($sFolder);
@ -484,7 +479,7 @@ class MailClient
{
if (!$sFromFolder || !$sToFolder || 0 === \count($aIndexRange))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->FolderSelect($sFromFolder);
@ -514,7 +509,7 @@ class MailClient
{
if (!$sFromFolder || !$sToFolder || 0 === \count($aIndexRange))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->FolderSelect($sFromFolder);
@ -545,7 +540,7 @@ class MailClient
{
if (!\is_resource($rMessageStream) || 0 === \strlen($sFolderToSave))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->MessageAppendStream(
@ -558,7 +553,7 @@ class MailClient
{
if (!\is_file($sMessageFileName) || !\is_readable($sMessageFileName))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$iMessageStreamSize = \filesize($sMessageFileName);
@ -650,7 +645,7 @@ class MailClient
$sUid = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::UID);
$sHeaders = $oFetchResponse->GetHeaderFieldsValue();
$oHeaders = \MailSo\Mime\HeaderCollection::NewInstance()->Parse($sHeaders);
$oHeaders = new \MailSo\Mime\HeaderCollection($sHeaders);
$sContentTypeCharset = $oHeaders->ParameterValue(
\MailSo\Mime\Enumerations\Header::CONTENT_TYPE,
@ -1563,14 +1558,14 @@ class MailClient
if (!\MailSo\Base\Validator::RangeInt($iOffset, 0) ||
!\MailSo\Base\Validator::RangeInt($iLimit, 0, 999))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$bUseFilter = '' !== $sFilter;
$this->oImapClient->FolderSelect($sFolderName);
$oMessageCollection = MessageCollection::NewInstance();
$oMessageCollection = new MessageCollection;
$oMessageCollection->FolderName = $sFolderName;
$oMessageCollection->Offset = $iOffset;
$oMessageCollection->Limit = $iLimit;
@ -1596,7 +1591,7 @@ class MailClient
if (!empty($sThreadUid) && !$bUseThreadSortIfSupported)
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
if (!$oCacher || !($oCacher instanceof \MailSo\Cache\CacheClient))
@ -1805,7 +1800,7 @@ class MailClient
{
if (0 === \strlen($sMessageId))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->FolderExamine($sFolderName);
@ -1974,7 +1969,7 @@ class MailClient
foreach ($aFolders as /* @var $oImapFolder \MailSo\Imap\Folder */ $oImapFolder)
{
$aMailFoldersHelper[] = Folder::NewInstance($oImapFolder,
$aMailFoldersHelper[] = new Folder($oImapFolder,
(null === $aImapSubscribedFoldersHelper || \in_array($oImapFolder->FullNameRaw(), $aImapSubscribedFoldersHelper)) ||
$oImapFolder->IsInbox()
);
@ -1985,7 +1980,7 @@ class MailClient
if ($aMailFoldersHelper)
{
$oFolderCollection = FolderCollection::NewInstance();
$oFolderCollection = new FolderCollection;
$oFolderCollection->InitByUnsortedMailFolderArray($aMailFoldersHelper);
$oFolderCollection->Optimized = $iCount !== \count($aMailFoldersHelper);
@ -2027,7 +2022,7 @@ class MailClient
{
if (!strlen(\trim($sFolderNameInUtf8)))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$sFolderNameInUtf8 = \trim($sFolderNameInUtf8);
@ -2097,7 +2092,7 @@ class MailClient
{
if (0 === \strlen($sPrevFolderFullNameRaw) || 0 === \strlen($sNextFolderNameInUtf))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$aFolders = $this->oImapClient->FolderList('', $sPrevFolderFullNameRaw);
@ -2161,7 +2156,7 @@ class MailClient
{
if (0 === \strlen($sFolderFullNameRaw) || 'INBOX' === $sFolderFullNameRaw)
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->FolderExamine($sFolderFullNameRaw);
@ -2169,7 +2164,7 @@ class MailClient
$aIndexOrUids = $this->oImapClient->MessageSimpleSearch('ALL');
if (0 < \count($aIndexOrUids))
{
throw new \MailSo\Mail\Exceptions\NonEmptyFolder();
throw new \MailSo\Mail\Exceptions\NonEmptyFolder;
}
$this->oImapClient->FolderExamine('INBOX');
@ -2212,7 +2207,7 @@ class MailClient
{
if (0 === \strlen($sFolderFullNameRaw))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oImapClient->{($bSubscribe) ? 'FolderSubscribe' : 'FolderUnSubscribe'}($sFolderFullNameRaw);
@ -2227,7 +2222,7 @@ class MailClient
{
if (!($oLogger instanceof \MailSo\Log\Logger))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oLogger = $oLogger;

View file

@ -123,7 +123,7 @@ class Message
private $sHtml;
/**
* @var \MailSo\Mail\AttachmentCollection
* @var AttachmentCollection
*/
private $oAttachments;
@ -187,12 +187,12 @@ class Message
*/
private $bPgpEncrypted;
private function __construct()
function __construct()
{
$this->Clear();
}
public function Clear() : \MailSo\Mail\Message
public function Clear() : self
{
$this->sFolder = '';
$this->iUid = 0;
@ -240,11 +240,6 @@ class Message
return $this;
}
public static function NewInstance() : \MailSo\Mail\Message
{
return new self();
}
public function Plain() : string
{
return $this->sPlain;
@ -375,7 +370,7 @@ class Message
return $this->oBcc;
}
public function Attachments() : ?\MailSo\Mail\AttachmentCollection
public function Attachments() : ?AttachmentCollection
{
return $this->oAttachments;
}
@ -430,12 +425,12 @@ class Message
return $this->bTextPartIsTrimmed;
}
public static function NewFetchResponseInstance(string $sFolder, \MailSo\Imap\FetchResponse $oFetchResponse, ?\MailSo\Imap\BodyStructure $oBodyStructure = null) : \MailSo\Mail\Message
public static function NewFetchResponseInstance(string $sFolder, \MailSo\Imap\FetchResponse $oFetchResponse, ?\MailSo\Imap\BodyStructure $oBodyStructure = null) : self
{
return self::NewInstance()->InitByFetchResponse($sFolder, $oFetchResponse, $oBodyStructure);
return (new self)->InitByFetchResponse($sFolder, $oFetchResponse, $oBodyStructure);
}
public function InitByFetchResponse(string $sFolder, \MailSo\Imap\FetchResponse $oFetchResponse, ?\MailSo\Imap\BodyStructure $oBodyStructure = null) : \MailSo\Mail\Message
public function InitByFetchResponse(string $sFolder, \MailSo\Imap\FetchResponse $oFetchResponse, ?\MailSo\Imap\BodyStructure $oBodyStructure = null) : self
{
if (!$oBodyStructure)
{
@ -460,9 +455,9 @@ class Message
$sCharset = \MailSo\Base\Utils::NormalizeCharset($sCharset);
$sHeaders = $oFetchResponse->GetHeaderFieldsValue();
if (0 < \strlen($sHeaders))
if (\strlen($sHeaders))
{
$oHeaders = \MailSo\Mime\HeaderCollection::NewInstance()->Parse($sHeaders, false, $sCharset);
$oHeaders = new \MailSo\Mime\HeaderCollection($sHeaders, false, $sCharset);
$sContentTypeCharset = $oHeaders->ParameterValue(
\MailSo\Mime\Enumerations\Header::CONTENT_TYPE,
@ -589,7 +584,7 @@ class Message
$sFolder = '';
$sUid = '';
$oParameters = \MailSo\Mime\ParameterCollection::NewInstance($sDraftInfo);
$oParameters = new \MailSo\Mime\ParameterCollection($sDraftInfo);
foreach ($oParameters as $oParameter) {
switch (\strtolower($oParameter->Name()))
{
@ -737,11 +732,11 @@ class Message
$aAttachmentsParts = $oBodyStructure->SearchAttachmentsParts();
if ($aAttachmentsParts && 0 < count($aAttachmentsParts))
{
$this->oAttachments = AttachmentCollection::NewInstance();
$this->oAttachments = new AttachmentCollection;
foreach ($aAttachmentsParts as /* @var $oAttachmentItem \MailSo\Imap\BodyStructure */ $oAttachmentItem)
{
$this->oAttachments->append(
\MailSo\Mail\Attachment::NewBodyStructureInstance($this->sFolder, $this->iUid, $oAttachmentItem)
Attachment::NewBodyStructureInstance($this->sFolder, $this->iUid, $oAttachmentItem)
);
}
}

View file

@ -77,18 +77,13 @@ class MessageCollection extends \MailSo\Base\Collection
*/
public $Filtered;
protected function __construct()
function __construct()
{
parent::__construct();
$this->Clear();
}
public static function NewInstance() : self
{
return new self();
}
public function append($oMessage, bool $bToTop = false) : void
{
assert($oMessage instanceof Message);