From ed85f12b7f33f7076a3254e81dbb83a890868d3e Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Thu, 22 Aug 2024 10:11:08 +0200 Subject: [PATCH] improve code --- .php-cs-fixer.php | 18 +++++++++++++++++- .../Controller/Admin/MailConfigCheck.php | 4 ++-- Application/Controller/Admin/MailTester.php | 2 +- Application/Controller/Admin/SpfChecker.php | 16 ++++++++-------- Application/Model/Constants.php | 2 +- Application/Model/DmarcResult.php | 4 ++-- .../d3TranslatableLazyAssertionException.php | 2 +- Application/views/en/translations.php | 2 +- composer.json | 2 +- 9 files changed, 34 insertions(+), 18 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index f0512a0..27ca8e8 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -4,9 +4,25 @@ $finder = PhpCsFixer\Finder::create() ->in(__DIR__) ; +$fileHeaderComment = << +@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) diff --git a/Application/Controller/Admin/MailConfigCheck.php b/Application/Controller/Admin/MailConfigCheck.php index c276f74..fd1f85e 100644 --- a/Application/Controller/Admin/MailConfigCheck.php +++ b/Application/Controller/Admin/MailConfigCheck.php @@ -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(); diff --git a/Application/Controller/Admin/MailTester.php b/Application/Controller/Admin/MailTester.php index 7723405..bb73c9e 100644 --- a/Application/Controller/Admin/MailTester.php +++ b/Application/Controller/Admin/MailTester.php @@ -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())); } } diff --git a/Application/Controller/Admin/SpfChecker.php b/Application/Controller/Admin/SpfChecker.php index 728ddc3..8225830 100644 --- a/Application/Controller/Admin/SpfChecker.php +++ b/Application/Controller/Admin/SpfChecker.php @@ -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', diff --git a/Application/Model/Constants.php b/Application/Model/Constants.php index 71d7fe1..0139485 100644 --- a/Application/Model/Constants.php +++ b/Application/Model/Constants.php @@ -18,4 +18,4 @@ namespace D3\MailConfigChecker\Application\Model; class Constants { public const OXID_MODULE_ID = 'd3mailconfigchecker'; -} \ No newline at end of file +} diff --git a/Application/Model/DmarcResult.php b/Application/Model/DmarcResult.php index c32f1fb..3888d9e 100644 --- a/Application/Model/DmarcResult.php +++ b/Application/Model/DmarcResult.php @@ -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) { diff --git a/Application/Model/Exception/d3TranslatableLazyAssertionException.php b/Application/Model/Exception/d3TranslatableLazyAssertionException.php index c8ce644..4975cb9 100644 --- a/Application/Model/Exception/d3TranslatableLazyAssertionException.php +++ b/Application/Model/Exception/d3TranslatableLazyAssertionException.php @@ -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); diff --git a/Application/views/en/translations.php b/Application/views/en/translations.php index af1c083..297f611 100644 --- a/Application/views/en/translations.php +++ b/Application/views/en/translations.php @@ -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: support@shopmodule.com
Your (D3) D3 Data Development team.', -]; \ No newline at end of file +]; diff --git a/composer.json b/composer.json index d0247f0..a568fdd 100644 --- a/composer.json +++ b/composer.json @@ -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" }