improve code style
This commit is contained in:
parent
d6a2373c31
commit
47b7e03552
@ -46,19 +46,19 @@ class MailConfigCheck extends AdminDetailsController
|
|||||||
|
|
||||||
Assert::lazy()
|
Assert::lazy()
|
||||||
->setExceptionClass(d3TranslatableLazyAssertionException::class)
|
->setExceptionClass(d3TranslatableLazyAssertionException::class)
|
||||||
->that( $shop->getFieldData( 'oxsmtp' ), $lang->translateString('SHOP_MAIN_SMTPSERVER') )
|
->that($shop->getFieldData('oxsmtp'), $lang->translateString('SHOP_MAIN_SMTPSERVER'))
|
||||||
->notBlank( $lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET') )
|
->notBlank($lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET'))
|
||||||
->regex( '/.*:(587|2525)$/m', $lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOPORT') )
|
->regex('/.*:(587|2525)$/m', $lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOPORT'))
|
||||||
->that( $shop->getFieldData( 'oxsmtpuser' ), $lang->translateString('SHOP_MAIN_SMTPUSER') )
|
->that($shop->getFieldData('oxsmtpuser'), $lang->translateString('SHOP_MAIN_SMTPUSER'))
|
||||||
->notBlank( $lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET') )
|
->notBlank($lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET'))
|
||||||
->that( $shop->getFieldData( 'oxsmtppwd' ), $lang->translateString('SHOP_MAIN_SMTPPASSWORD') )
|
->that($shop->getFieldData('oxsmtppwd'), $lang->translateString('SHOP_MAIN_SMTPPASSWORD'))
|
||||||
->notBlank( $lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET') )
|
->notBlank($lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET'))
|
||||||
->that( $shop->getFieldData( 'oxinfoemail' ), $lang->translateString('SHOP_MAIN_INFOEMAIL') )
|
->that($shop->getFieldData('oxinfoemail'), $lang->translateString('SHOP_MAIN_INFOEMAIL'))
|
||||||
->email( $lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET') )
|
->email($lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET'))
|
||||||
->that( $shop->getFieldData( 'oxorderemail' ), $lang->translateString('SHOP_MAIN_ORDEREMAIL') )
|
->that($shop->getFieldData('oxorderemail'), $lang->translateString('SHOP_MAIN_ORDEREMAIL'))
|
||||||
->email( $lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET') )
|
->email($lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET'))
|
||||||
->that( $shop->getFieldData( 'oxowneremail' ), $lang->translateString('SHOP_MAIN_OWNEREMAIL') )
|
->that($shop->getFieldData('oxowneremail'), $lang->translateString('SHOP_MAIN_OWNEREMAIL'))
|
||||||
->email( $lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET') )
|
->email($lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET'))
|
||||||
->verifyNow();
|
->verifyNow();
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (InvalidArgumentException $e) {
|
||||||
Registry::getUtilsView()->addErrorToDisplay(nl2br($e->getMessage()));
|
Registry::getUtilsView()->addErrorToDisplay(nl2br($e->getMessage()));
|
||||||
@ -73,12 +73,12 @@ class MailConfigCheck extends AdminDetailsController
|
|||||||
protected function getCurrentMailer()
|
protected function getCurrentMailer()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$mail = oxNew( Email::class );
|
$mail = oxNew(Email::class);
|
||||||
$mail->setRecipient( $this->testMailAddress );
|
$mail->setRecipient($this->testMailAddress);
|
||||||
$mail->setBody('.');
|
$mail->setBody('.');
|
||||||
$mail->send();
|
$mail->send();
|
||||||
$this->addTplParam('mailer', $mail->getMailer());
|
$this->addTplParam('mailer', $mail->getMailer());
|
||||||
} catch ( Exception $e) {
|
} catch (Exception $e) {
|
||||||
Registry::getUtilsView()->addErrorToDisplay($e);
|
Registry::getUtilsView()->addErrorToDisplay($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,19 +31,19 @@ class MailTester extends AdminDetailsController
|
|||||||
try {
|
try {
|
||||||
$request = Registry::getRequest();
|
$request = Registry::getRequest();
|
||||||
|
|
||||||
$from = trim($request->getRequestEscapedParameter( 'from' ));
|
$from = trim($request->getRequestEscapedParameter('from'));
|
||||||
$this->addTplParam('sender', $from);
|
$this->addTplParam('sender', $from);
|
||||||
$to = trim($request->getRequestEscapedParameter( 'to' ));
|
$to = trim($request->getRequestEscapedParameter('to'));
|
||||||
$this->addTplParam('recipient', $to);
|
$this->addTplParam('recipient', $to);
|
||||||
$subject = trim($request->getRequestEscapedParameter( 'subject' ));
|
$subject = trim($request->getRequestEscapedParameter('subject'));
|
||||||
$this->addTplParam('subject', $subject);
|
$this->addTplParam('subject', $subject);
|
||||||
$body = trim($request->getRequestEscapedParameter( 'body' ));
|
$body = trim($request->getRequestEscapedParameter('body'));
|
||||||
$this->addTplParam('body', $body);
|
$this->addTplParam('body', $body);
|
||||||
|
|
||||||
$this->assertContent();
|
$this->assertContent();
|
||||||
|
|
||||||
$mail = oxNew( Email::class );
|
$mail = oxNew(Email::class);
|
||||||
$mail->setFrom( $from );
|
$mail->setFrom($from);
|
||||||
$mail->sendEmail($to, $subject, $body);
|
$mail->sendEmail($to, $subject, $body);
|
||||||
$this->addTplParam('success', true);
|
$this->addTplParam('success', true);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -59,19 +59,19 @@ class MailTester extends AdminDetailsController
|
|||||||
Assert::lazy()
|
Assert::lazy()
|
||||||
->setExceptionClass(d3TranslatableLazyAssertionException::class)
|
->setExceptionClass(d3TranslatableLazyAssertionException::class)
|
||||||
->that(
|
->that(
|
||||||
$request->getRequestEscapedParameter( 'from' ),
|
$request->getRequestEscapedParameter('from'),
|
||||||
$lang->translateString('D3_MAILCHECKER_SMTPCHECK_SENDER')
|
$lang->translateString('D3_MAILCHECKER_SMTPCHECK_SENDER')
|
||||||
)->email($lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET'))
|
)->email($lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET'))
|
||||||
->that(
|
->that(
|
||||||
$request->getRequestEscapedParameter( 'to' ),
|
$request->getRequestEscapedParameter('to'),
|
||||||
$lang->translateString('D3_MAILCHECKER_SMTPCHECK_RECIPIENT')
|
$lang->translateString('D3_MAILCHECKER_SMTPCHECK_RECIPIENT')
|
||||||
)->email($lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET'))
|
)->email($lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET'))
|
||||||
->that(
|
->that(
|
||||||
$request->getRequestEscapedParameter( 'subject' ),
|
$request->getRequestEscapedParameter('subject'),
|
||||||
$lang->translateString('D3_MAILCHECKER_TESTMAIL_SUBJECT')
|
$lang->translateString('D3_MAILCHECKER_TESTMAIL_SUBJECT')
|
||||||
)->notBlank($lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET'))
|
)->notBlank($lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET'))
|
||||||
->that(
|
->that(
|
||||||
$request->getRequestEscapedParameter( 'body' ),
|
$request->getRequestEscapedParameter('body'),
|
||||||
$lang->translateString('D3_MAILCHECKER_TESTMAIL_BODY')
|
$lang->translateString('D3_MAILCHECKER_TESTMAIL_BODY')
|
||||||
)->notBlank($lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET'))
|
)->notBlank($lang->translateString('D3_MAILCHECKER_ASSERTIONS_NOTSET'))
|
||||||
->verifyNow();
|
->verifyNow();
|
||||||
|
@ -47,9 +47,9 @@ class SmtpChecker extends AdminDetailsController
|
|||||||
$activeShop = Registry::getConfig()->getActiveShop();
|
$activeShop = Registry::getConfig()->getActiveShop();
|
||||||
|
|
||||||
if ($localHost = Registry::getRequest()->getRequestEscapedParameter('smtpHost')) {
|
if ($localHost = Registry::getRequest()->getRequestEscapedParameter('smtpHost')) {
|
||||||
list( 'host' => $shopHost, 'port' => $shopPort ) = parse_url( trim($localHost) );
|
['host' => $shopHost, 'port' => $shopPort] = parse_url(trim($localHost));
|
||||||
} else {
|
} else {
|
||||||
list( 'host' => $shopHost, 'port' => $shopPort ) = parse_url( trim($activeShop->getFieldData( 'oxsmtp' )) );
|
['host' => $shopHost, 'port' => $shopPort] = parse_url(trim($activeShop->getFieldData('oxsmtp')));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->host = $shopHost;
|
$this->host = $shopHost;
|
||||||
@ -123,7 +123,7 @@ class SmtpChecker extends AdminDetailsController
|
|||||||
{
|
{
|
||||||
$this->action = __FUNCTION__;
|
$this->action = __FUNCTION__;
|
||||||
Assert::that(
|
Assert::that(
|
||||||
( $this->smtp = new Net_SMTP( $this->host, $this->port ) ),
|
($this->smtp = new Net_SMTP($this->host, $this->port)),
|
||||||
Registry::getLang()->translateString('D3_MAILCHECKER_SMTPCHECK_INSTANCE')
|
Registry::getLang()->translateString('D3_MAILCHECKER_SMTPCHECK_INSTANCE')
|
||||||
)->isInstanceOf(
|
)->isInstanceOf(
|
||||||
Net_SMTP::class,
|
Net_SMTP::class,
|
||||||
@ -179,7 +179,7 @@ class SmtpChecker extends AdminDetailsController
|
|||||||
{
|
{
|
||||||
$this->action = __FUNCTION__;
|
$this->action = __FUNCTION__;
|
||||||
Assert::that(
|
Assert::that(
|
||||||
$this->smtp->rcptTo( $this->to),
|
$this->smtp->rcptTo($this->to),
|
||||||
Registry::getLang()->translateString('D3_MAILCHECKER_SMTPCHECK_RECIPIENT')
|
Registry::getLang()->translateString('D3_MAILCHECKER_SMTPCHECK_RECIPIENT')
|
||||||
)->notIsInstanceOf(
|
)->notIsInstanceOf(
|
||||||
PEAR_Error::class,
|
PEAR_Error::class,
|
||||||
@ -198,7 +198,7 @@ class SmtpChecker extends AdminDetailsController
|
|||||||
$subj = "Subject: Test Message\n";
|
$subj = "Subject: Test Message\n";
|
||||||
$body = "Body Line 1\nBody Line 2";
|
$body = "Body Line 1\nBody Line 2";
|
||||||
Assert::that(
|
Assert::that(
|
||||||
$this->smtp->data( $subj . "\r\n" . $body),
|
$this->smtp->data($subj . "\r\n" . $body),
|
||||||
Registry::getLang()->translateString('D3_MAILCHECKER_SMTPCHECK_TRANSMIT')
|
Registry::getLang()->translateString('D3_MAILCHECKER_SMTPCHECK_TRANSMIT')
|
||||||
)->notIsInstanceOf(
|
)->notIsInstanceOf(
|
||||||
PEAR_Error::class,
|
PEAR_Error::class,
|
||||||
|
@ -41,7 +41,7 @@ class SpfChecker extends AdminDetailsController
|
|||||||
$mailDomains = $this->getMailDomains();
|
$mailDomains = $this->getMailDomains();
|
||||||
array_walk(
|
array_walk(
|
||||||
$mailDomains,
|
$mailDomains,
|
||||||
function($domain) use (&$result) {
|
function ($domain) use (&$result) {
|
||||||
$this->checkSpfByDomain($domain, $result);
|
$this->checkSpfByDomain($domain, $result);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -58,15 +58,15 @@ class SpfChecker extends AdminDetailsController
|
|||||||
array_filter(
|
array_filter(
|
||||||
array_unique(
|
array_unique(
|
||||||
array_map(
|
array_map(
|
||||||
function($mailAddress) {
|
function ($mailAddress) {
|
||||||
$mailAddress = trim($mailAddress);
|
$mailAddress = trim($mailAddress);
|
||||||
try {
|
try {
|
||||||
if ( ! strstr( $mailAddress, '@' ) ) {
|
if (! strstr($mailAddress, '@')) {
|
||||||
throw oxNew( InvalidArgumentException::class );
|
throw oxNew(InvalidArgumentException::class);
|
||||||
}
|
}
|
||||||
$addressChunks = explode( '@', $mailAddress );
|
$addressChunks = explode('@', $mailAddress);
|
||||||
|
|
||||||
return array_pop( $addressChunks );
|
return array_pop($addressChunks);
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (InvalidArgumentException $e) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@ -79,7 +79,6 @@ class SpfChecker extends AdminDetailsController
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function checkSpfByDomain($domain, &$summarize)
|
protected function checkSpfByDomain($domain, &$summarize)
|
||||||
|
@ -23,11 +23,11 @@ class d3TranslatableLazyAssertionException extends LazyAssertionException
|
|||||||
public static function fromErrors(array $errors): LazyAssertionException
|
public static function fromErrors(array $errors): LazyAssertionException
|
||||||
{
|
{
|
||||||
$text = Registry::getLang()->translateString('D3_MAILCHECKER_ASSERTIONS_FAILED');
|
$text = Registry::getLang()->translateString('D3_MAILCHECKER_ASSERTIONS_FAILED');
|
||||||
$message = sprintf( $text, count( $errors ) ) . "\n";
|
$message = sprintf($text, count($errors)) . "\n";
|
||||||
|
|
||||||
$i = 1;
|
$i = 1;
|
||||||
foreach ($errors as $error) {
|
foreach ($errors as $error) {
|
||||||
$message .= sprintf( "%d) %s: %s\n", $i ++, $error->getPropertyPath(), $error->getMessage() );
|
$message .= sprintf("%d) %s: %s\n", $i ++, $error->getPropertyPath(), $error->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return new LazyAssertionException($message, $errors);
|
return new LazyAssertionException($message, $errors);
|
||||||
|
@ -14,11 +14,12 @@
|
|||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace D3\MailConfigChecker\Application\Model;
|
namespace D3\MailConfigChecker\Application\Model;
|
||||||
|
|
||||||
class SpfResult
|
class SpfResult
|
||||||
{
|
{
|
||||||
const SET = 'set';
|
public const SET = 'set';
|
||||||
const MISSING = 'missing';
|
public const MISSING = 'missing';
|
||||||
const ERROR = 'error';
|
public const ERROR = 'error';
|
||||||
|
|
||||||
protected $status;
|
protected $status;
|
||||||
protected $record;
|
protected $record;
|
||||||
|
Loading…
Reference in New Issue
Block a user