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

@ -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

@ -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

@ -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"
}