improve code

This commit is contained in:
Daniel Seifert 2024-08-22 10:11:08 +02:00
parent f9e040a671
commit ed85f12b7f
9 changed files with 34 additions and 18 deletions

View File

@ -4,9 +4,25 @@ $finder = PhpCsFixer\Finder::create()
->in(__DIR__)
;
$fileHeaderComment = <<<EOF
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
https://www.d3data.de
@copyright (C) D3 Data Development (Inh. Thomas Dartsch)
@author D3 Data Development - Daniel Seifert <info@shopmodule.com>
@link https://www.oxidmodule.com
EOF;
$config = new PhpCsFixer\Config();
return $config->setRules([
'@PHP73Migration' => true,
'header_comment' => [
'header' => $fileHeaderComment,
'comment_type' => 'PHPDoc',
'location' => 'after_open'
],
'@PHP80Migration' => true,
'@PSR12' => true
])
->setFinder($finder)

View File

@ -88,14 +88,14 @@ class MailConfigCheck extends AdminDetailsController
protected function getCurrentMailer(): void
{
try {
$shop = Registry::getConfig()->getActiveShop();
$shop = Registry::getConfig()->getActiveShop();
$mail = oxNew(Email::class);
$mail->setRecipient(
trim(Registry::getRequest()->getRequestEscapedParameter('recipient')) ?: $this->testMailAddress
);
$mail->setBody('.');
$mail->setFrom($shop->getFieldData('oxowneremail'));
$mail->setFrom($shop->getFieldData('oxowneremail'));
$mail->set("SMTPDebug", true); // don't set via iDebug = 6 because different handling
$mail->setSmtp();

View File

@ -46,7 +46,7 @@ class MailTester extends AdminDetailsController
$mail->setFrom($from);
$mail->sendEmail($to, $subject, $body);
$this->addTplParam('success', true);
} catch ( Exception $e) {
} catch (Exception $e) {
Registry::getUtilsView()->addErrorToDisplay(nl2br($e->getMessage()));
}
}

View File

@ -81,7 +81,7 @@ class SpfChecker extends AdminDetailsController
function ($mailAddress) {
$mailAddress = trim($mailAddress);
try {
if ( ! str_contains( $mailAddress, '@' ) ) {
if (! str_contains($mailAddress, '@')) {
throw oxNew(InvalidArgumentException::class);
}
$addressChunks = explode('@', $mailAddress);
@ -107,7 +107,7 @@ class SpfChecker extends AdminDetailsController
$query = new Query('', $domain);
$result = $checker->getResult($query);
$status = match ( $result->getResult() ) {
$status = match ($result->getResult()) {
Result::FAIL, Result::NEUTRAL, Result::PASS, Result::SOFTFAIL => SpfResult::SET,
Result::NONE => SpfResult::MISSING,
default => SpfResult::ERROR,
@ -122,7 +122,7 @@ class SpfChecker extends AdminDetailsController
public function getSpfStatusColor(SpfResult $result): string
{
return match ( $result->getStatus() ) {
return match ($result->getStatus()) {
SpfResult::SET => 'success',
SpfResult::ERROR => 'warning',
default => 'danger',
@ -136,21 +136,21 @@ class SpfChecker extends AdminDetailsController
$query = new Query('', $domain);
$record = $check->getResult($query)->getRecord();
$status = match ( $record->getRejectPolicy()->getValue() ) {
$status = match ($record->getRejectPolicy()->getValue()) {
DMARCResult::REJECT_QUARANTINE, DMARCResult::REJECT_REJECT => OxDmarcResult::SET,
DMARCResult::REJECT_NONE => OxDmarcResult::MISSING,
default => OxDmarcResult::ERROR,
};
$summarize[$domain] = oxNew( OxDmarcResult::class, $status, $record->getRawRecord());
} catch ( LogicException) {
$summarize[$domain] = oxNew( OxDmarcResult::class, OxDmarcResult::MISSING, '');
$summarize[$domain] = oxNew(OxDmarcResult::class, $status, $record->getRawRecord());
} catch (LogicException) {
$summarize[$domain] = oxNew(OxDmarcResult::class, OxDmarcResult::MISSING, '');
}
}
public function getDmarcStatusColor(OxDmarcResult $result): string
{
return match ( $result->getStatus() ) {
return match ($result->getStatus()) {
SpfResult::SET => 'success',
SpfResult::ERROR => 'warning',
default => 'danger',

View File

@ -18,4 +18,4 @@ namespace D3\MailConfigChecker\Application\Model;
class Constants
{
public const OXID_MODULE_ID = 'd3mailconfigchecker';
}
}

View File

@ -21,8 +21,8 @@ class DmarcResult
public const MISSING = 'missing';
public const ERROR = 'error';
protected $status;
protected $record;
protected string $status;
protected ?string $record;
public function __construct(string $status, ?string $record = null)
{

View File

@ -27,7 +27,7 @@ class d3TranslatableLazyAssertionException extends LazyAssertionException
$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);

View File

@ -78,4 +78,4 @@ return [
"D3_MAILCHECKER_INFO_1" => "This module can help you to identify difficulties when sending emails or undelivered emails. Please go through the following tabs. Any necessary rework will be displayed there.",
"D3_MAILCHECKER_INFO_2" => "Please note that the checks should not be active during productive operation of the shop!",
"D3_MAILCHECKER_INFO_3" => 'If you require more detailed information or technical support, please contact us at: <a href="mailto:support@shopmodule.com">support@shopmodule.com</a><br><br<br>Your <img src="https://logos.oxidmodule.com/d3logo.svg" alt="(D3)" style="height:1em;width:1em"> D3 Data Development team.',
];
];

View File

@ -39,7 +39,6 @@
"beberlei/assert": "^3.3"
},
"require-dev": {
"php": "^8",
"friendsofphp/php-cs-fixer": "^3.9",
"phpstan/phpstan": "^1.8",
"boxblinkracer/phpunuhi": "^1.12"
@ -50,6 +49,7 @@
}
},
"scripts": {
"php-cs-fixer": "./vendor/bin/php-cs-fixer fix --config=vendor/d3/mailconfigchecker/.php-cs-fixer.php",
"phpstan": "./vendor/bin/phpstan --configuration=./vendor/d3/mailconfigchecker/phpstan.neon",
"phpunuhi": "./vendor/bin/phpunuhi --configuration=vendor/d3/mailconfigchecker/phpunuhi.xml validate"
}