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