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

@ -92,7 +92,7 @@ class BodyStructure
*/
private $aSubParts;
private function __construct(string $sContentType, ?string $sCharset, array $aBodyParams, ?string $sContentID,
function __construct(string $sContentType, ?string $sCharset, array $aBodyParams, ?string $sContentID,
?string $sDescription, ?string $sMailEncodingName, ?string $sDisposition, ?array $aDispositionParams, string $sFileName,
?string $sLanguage, ?string $sLocation, int $iSize, int $iTextLineCount, string $sPartID, array $aSubParts)
{
@ -300,29 +300,26 @@ class BodyStructure
foreach ($mParts as $oPart)
{
$sResult = $oPart ? $oPart->Charset() : '';
if (!empty($sResult))
if ($sResult)
{
break;
}
}
if (0 === strlen($sResult))
if (!$sResult)
{
$aParts = $this->SearchAttachmentsParts();
foreach ($aParts as $oPart)
{
if (0 === \strlen($sResult))
{
$sResult = $oPart ? $oPart->Charset() : '';
}
else
$sResult = $oPart ? $oPart->Charset() : '';
if ($sResult)
{
break;
}
}
}
return $sResult;
return $sResult ?: '';
}
/**

View file

@ -27,17 +27,12 @@ class FetchResponse
*/
private $aEnvelopeCache;
private function __construct(Response $oImapResponse)
function __construct(Response $oImapResponse)
{
$this->oImapResponse = $oImapResponse;
$this->aEnvelopeCache = null;
}
public static function NewInstance(Response $oImapResponse) : self
{
return new self($oImapResponse);
}
public function GetEnvelope(bool $bForce = false) : ?array
{
if (null === $this->aEnvelopeCache || $bForce)
@ -61,7 +56,7 @@ class FetchResponse
$aEmails = $this->GetFetchEnvelopeValue($iIndex);
if (is_array($aEmails) && 0 < count($aEmails))
{
$oResult = \MailSo\Mime\EmailCollection::NewInstance();
$oResult = new \MailSo\Mime\EmailCollection;
foreach ($aEmails as $aEmailItem)
{
if (is_array($aEmailItem) && 4 === count($aEmailItem))
@ -78,7 +73,7 @@ class FetchResponse
if (0 < strlen($sLocalPart) && 0 < strlen($sDomainPart))
{
$oResult->append(
\MailSo\Mime\Email::NewInstance($sLocalPart.'@'.$sDomainPart, $sDisplayName)
new \MailSo\Mime\Email($sLocalPart.'@'.$sDomainPart, $sDisplayName)
);
}
}

View file

@ -50,7 +50,7 @@ class Folder
/**
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
private function __construct(string $sFullNameRaw, string $sDelimiter, array $aFlags)
function __construct(string $sFullNameRaw, string $sDelimiter = '.', array $aFlags = array())
{
$sDelimiter = 'NIL' === \strtoupper($sDelimiter) ? '' : $sDelimiter;
if (empty($sDelimiter))
@ -60,7 +60,7 @@ class Folder
if (1 < \strlen($sDelimiter) || 0 === \strlen($sFullNameRaw))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->sFullNameRaw = $sFullNameRaw;
@ -82,21 +82,13 @@ class Folder
$aNames = \explode($this->sDelimiter, $this->sFullNameRaw);
if (false !== \array_search('', $aNames))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->sNameRaw = \end($aNames);
}
}
/**
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public static function NewInstance(string $sFullNameRaw, string $sDelimiter = '.', array $aFlags = array()) : self
{
return new self($sFullNameRaw, $sDelimiter, $aFlags);
}
public function NameRaw() : string
{
return $this->sNameRaw;

View file

@ -67,7 +67,7 @@ class FolderInformation
*/
public $HighestModSeq;
private function __construct(string $sFolderName, bool $bIsWritable)
function __construct(string $sFolderName, bool $bIsWritable)
{
$this->FolderName = $sFolderName;
$this->IsWritable = $bIsWritable;
@ -81,11 +81,6 @@ class FolderInformation
$this->HighestModSeq = null;
}
public static function NewInstance(string $sFolderName, bool $bIsWritable) : self
{
return new self($sFolderName, $bIsWritable);
}
public function IsFlagSupported(string $sFlag) : bool
{
return \in_array('\\*', $this->PermanentFlags) ||

View file

@ -82,7 +82,7 @@ class ImapClient extends \MailSo\Net\NetClient
*/
public $__FORCE_SELECT_ON_EXAMINE__;
protected function __construct()
function __construct()
{
parent::__construct();
@ -90,7 +90,7 @@ class ImapClient extends \MailSo\Net\NetClient
$this->aCapabilityItems = null;
$this->oCurrentFolderInfo = null;
$this->oLastResponse = new ResponseCollection();
$this->oLastResponse = new ResponseCollection;
$this->bNeedNext = true;
$this->aTagTimeouts = array();
@ -104,11 +104,6 @@ class ImapClient extends \MailSo\Net\NetClient
\ini_set('xdebug.max_nesting_level', 500);
}
public static function NewInstance() : self
{
return new self();
}
public function GetLogginedUser() : string
{
return $this->sLogginedUser;
@ -157,7 +152,7 @@ class ImapClient extends \MailSo\Net\NetClient
if (!strlen(\trim($sLogin)) || !strlen(\trim($sPassword)))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -193,14 +188,14 @@ class ImapClient extends \MailSo\Net\NetClient
else
{
$this->writeLogException(
new Exceptions\LoginException(),
new Exceptions\LoginException,
\MailSo\Log\Enumerations\Type::NOTICE, true);
}
}
else
{
$this->writeLogException(
new Exceptions\LoginException(),
new Exceptions\LoginException,
\MailSo\Log\Enumerations\Type::NOTICE, true);
}
}
@ -239,7 +234,7 @@ class ImapClient extends \MailSo\Net\NetClient
// else
// {
// $this->writeLogException(
// new Exceptions\LoginBadMethodException(),
// new Exceptions\LoginBadMethodException,
// \MailSo\Log\Enumerations\Type::NOTICE, true);
// }
@ -505,7 +500,7 @@ class ImapClient extends \MailSo\Net\NetClient
if (!strlen(\trim($sFolderName)))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
throw new \MailSo\Base\Exceptions\InvalidArgumentException;
}
$this->oCurrentFolderInfo = $this->SendRequestGetResponse($bIsWritable ? 'SELECT' : 'EXAMINE',
@ -562,7 +557,7 @@ class ImapClient extends \MailSo\Net\NetClient
if (!strlen(\trim($sIndexRange)))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -614,13 +609,13 @@ class ImapClient extends \MailSo\Net\NetClient
if (!$aSortTypes)
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
if (!$this->IsSupported('SORT'))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -650,14 +645,14 @@ class ImapClient extends \MailSo\Net\NetClient
if ($bSort && (!$aSortTypes || !$this->IsSupported('SORT')))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
if (!$this->IsSupported($bSort ? 'ESORT' : 'ESEARCH'))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -821,7 +816,7 @@ class ImapClient extends \MailSo\Net\NetClient
if (0 === \strlen($sIndexRange))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -841,7 +836,7 @@ class ImapClient extends \MailSo\Net\NetClient
if (0 === \strlen($sIndexRange))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -958,7 +953,7 @@ class ImapClient extends \MailSo\Net\NetClient
if (!\strlen($sCommand))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
new \MailSo\Base\Exceptions\InvalidArgumentException,
\MailSo\Log\Enumerations\Type::ERROR, true);
}
@ -1026,18 +1021,18 @@ class ImapClient extends \MailSo\Net\NetClient
private function getResponse(string $sEndTag = null) : ResponseCollection
{
try {
$oResult = new ResponseCollection();
$oResult = new ResponseCollection;
if (\is_resource($this->rConnect)) {
$sEndTag = (null === $sEndTag) ? $this->getCurrentTag() : $sEndTag;
while (true) {
$oResponse = Response::NewInstance();
$oResponse = new Response;
$this->partialParseResponseBranch($oResponse);
if (Enumerations\ResponseType::UNKNOWN === $oResponse->ResponseType) {
throw new Exceptions\ResponseNotFoundException();
throw new Exceptions\ResponseNotFoundException;
}
$oResult->append($oResponse);

View file

@ -47,7 +47,7 @@ class NamespaceResult
*/
private $sSharedDelimiter;
private function __construct()
function __construct()
{
$this->sPersonal = '';
$this->sPersonalDelimiter = '';
@ -57,11 +57,6 @@ class NamespaceResult
$this->sSharedDelimiter = '';
}
public static function NewInstance() : self
{
return new self();
}
public function InitByImapResponse(\MailSo\Imap\Response $oImapResponse) : self
{
if ($oImapResponse && $oImapResponse instanceof \MailSo\Imap\Response)

View file

@ -52,7 +52,7 @@ class Response
*/
public $Tag;
private function __construct()
function __construct()
{
$this->ResponseList = array();
$this->OptionalResponse = null;
@ -63,11 +63,6 @@ class Response
$this->Tag = '';
}
public static function NewInstance() : self
{
return new self();
}
private function recToLine(array $aList) : string
{
$aResult = array();

View file

@ -18,11 +18,6 @@ namespace MailSo\Imap;
*/
class ResponseCollection extends \MailSo\Base\Collection
{
public static function NewInstance() : self
{
return new self();
}
public function append($oResponse, bool $bToTop = false) : void
{
assert($oResponse instanceof Response);
@ -39,7 +34,7 @@ class ResponseCollection extends \MailSo\Base\Collection
{
$oItem = $this->getLast();
if (!$oItem) {
throw new Exceptions\ResponseNotFoundException();
throw new Exceptions\ResponseNotFoundException;
}
if ($oItem->ResponseType !== Enumerations\ResponseType::CONTINUATION) {
@ -87,7 +82,7 @@ class ResponseCollection extends \MailSo\Base\Collection
foreach ($this as $oResponse) {
if (FetchResponse::IsValidFetchImapResponse($oResponse)) {
if (FetchResponse::IsNotEmptyFetchImapResponse($oResponse)) {
$aReturn[] = FetchResponse::NewInstance($oResponse);
$aReturn[] = new FetchResponse($oResponse);
} else if ($this->oLogger) {
$this->oLogger->Write('Skipped Imap Response! ['.$oResponse->ToLine().']', \MailSo\Log\Enumerations\Type::NOTICE);
}
@ -109,7 +104,7 @@ class ResponseCollection extends \MailSo\Base\Collection
{
try
{
$oFolder = Folder::NewInstance($oResponse->ResponseList[4],
$oFolder = new Folder($oResponse->ResponseList[4],
$oResponse->ResponseList[3], $oResponse->ResponseList[2]);
if ($oFolder->IsInbox()) {
@ -132,7 +127,7 @@ class ResponseCollection extends \MailSo\Base\Collection
}
if (!$bInbox && !empty($sDelimiter)) {
$aReturn[] = Folder::NewInstance('INBOX', $sDelimiter);
$aReturn[] = new Folder('INBOX', $sDelimiter);
}
if ($bUseListStatus) {
@ -241,7 +236,7 @@ class ResponseCollection extends \MailSo\Base\Collection
public function getCurrentFolderInformation(string $sFolderName, bool $bIsWritable) : FolderInformation
{
$oResult = FolderInformation::NewInstance($sFolderName, $bIsWritable);
$oResult = new FolderInformation($sFolderName, $bIsWritable);
foreach ($this as $oResponse) {
if (\MailSo\Imap\Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType) {
if (\count($oResponse->ResponseList) > 2 &&
@ -306,12 +301,12 @@ class ResponseCollection extends \MailSo\Base\Collection
if (Enumerations\ResponseType::UNTAGGED === $oResponse->ResponseType &&
'NAMESPACE' === $oResponse->StatusOrIndex)
{
$oReturn = NamespaceResult::NewInstance();
$oReturn = new NamespaceResult;
$oReturn->InitByImapResponse($oResponse);
return $oReturn;
}
}
throw new Exceptions\ResponseException();
throw new Exceptions\ResponseException;
}
public function getQuotaResult() : array