Skip to content

Commit

Permalink
Revert "[CS] Code cleanup (Part 9)"
Browse files Browse the repository at this point in the history
This reverts commit 961103e.

Revert "[CS] Code cleanup (Part 8)"

This reverts commit 17f89ae.

Revert "[CS] Code cleanup (Part 7)"

This reverts commit e58d99a.

Revert "[CS] Code cleanup (Part 6)"

This reverts commit f33f251.

Revert "[CS] Code cleanup (Part 5)"

This reverts commit ac62d05.

Revert "[CS] Code cleanup (Part 4)"

This reverts commit 2e2a00a.

Revert "[CS] Code cleanup (Part 3)"

This reverts commit ca1cffb.

Revert "[CS] Code cleanup (Part 2)"This reverts commit a700968.

Revert "[CS] Code cleanup (Part 1)"

This reverts commit 14d7eb6.
  • Loading branch information
HorstOeko committed Jan 16, 2025
1 parent 961103e commit c6c592b
Show file tree
Hide file tree
Showing 37 changed files with 582 additions and 471 deletions.
81 changes: 39 additions & 42 deletions build/phprectorconfig.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\SetList;
use Rector\Naming\Rector\Class_\RenamePropertyToMatchTypeRector;
use Rector\Naming\Rector\ClassMethod\RenameParamToMatchTypeRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
use Rector\Naming\Rector\ClassMethod\RenameVariableToMatchNewTypeRector;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/../src',
__DIR__ . '/../tests',
])
->withSkip([
__DIR__ . '/../examples',
__DIR__ . '/../make',
])
->withSkip([
//ClassPropertyAssignToConstructorPromotionRector::class
])
->withPhpSets(php73: true)
->withConfiguredRule(EncapsedStringsToSprintfRector::class, [
'always' => true,
])
->withPreparedSets(
codeQuality: true,
codingStyle: true,
deadCode: false,
typeDeclarations: true,
privatization: true,
naming: false,
instanceOf: true,
earlyReturn: true,
strictBooleans: true,
phpunitCodeQuality: true
);
<?php

declare(strict_types=1);

use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\Naming\Rector\Class_\RenamePropertyToMatchTypeRector;
use Rector\Naming\Rector\ClassMethod\RenameParamToMatchTypeRector;
use Rector\Naming\Rector\ClassMethod\RenameVariableToMatchNewTypeRector;
use Rector\Set\ValueObject\SetList;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/../examples',
__DIR__ . '/../make',
__DIR__ . '/../src',
__DIR__ . '/../tests',
])
->withSkip([
RemoveUselessParamTagRector::class,
RemoveUselessReturnTagRector::class,
])
->withPhp73Sets()
->withSets([
SetList::DEAD_CODE,
SetList::CODE_QUALITY,
SetList::CODING_STYLE,
])
->withConfiguredRule(EncapsedStringsToSprintfRector::class, [
'always' => true,
])
->withRules([
RenamePropertyToMatchTypeRector::class,
RenameParamToMatchTypeRector::class,
RenameVariableToMatchNewTypeRector::class,
])
->withTypeCoverageLevel(0);
17 changes: 8 additions & 9 deletions build/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
parameters:
paths:
- ../src
- ../tests
level: 5
treatPhpDocTypesAsCertain: false
excludePaths:
- ../src/entities/*
- ../tests/helpers/TestOutputInterface.php
parameters:
paths:
- ../src
- ../tests
level: 5
treatPhpDocTypesAsCertain: false
excludePaths:
- ../src/entities/*
81 changes: 42 additions & 39 deletions build/phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="../vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false">
<testsuites>
<testsuite name="Classes">
<file>../tests/testcases/ZugferdMailConfigTest.php</file>
<file>../tests/testcases/ZugferdMailAccountTest.php</file>
<file>../tests/testcases/ZugferdMailStringHelperTest.php</file>
<file>../tests/testcases/ZugferdMailPlaceholderHelperTest.php</file>
</testsuite>
<testsuite name="Concerns">
<file>../tests/testcases/ZugferdMailConcernRaisesExceptionsTest.php</file>
<file>../tests/testcases/ZugferdMailConcernMessageBagTest.php</file>
<file>../tests/testcases/ZugferdMailConcernParsesPlaceholdersTest.php</file>
<file>../tests/testcases/ZugferdMailConcernConsoleOutputsMessageBagMessagesTest.php</file>
<file>../tests/testcases/ZugferdMailConcernConsoleHandlesConfigOptionsTest.php</file>
<file>../tests/testcases/ZugferdMailConcernConsoleHandlesMailAccountOptionsTest.php</file>
</testsuite>
<testsuite name="Handlers">
<file>../tests/testcases/BuiltinHandlersTest.php</file>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">../src</directory>
</include>
<exclude>
<file>../src/bin/ZugferdMailConsole.php</file>
</exclude>
<report>
<xml outputDirectory="coverage"/>
<html outputDirectory="coverage-html"/>
<clover outputFile="logs/clover.xml"/>
<crap4j outputFile="logs/crap4j.xml" threshold="50"/>
</report>
</coverage>
<logging>
<junit outputFile="./logs/junit.xml"/>
<testdoxHtml outputFile="./logs/testdox.html"/>
</logging>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="../vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false">
<testsuites>
<testsuite name="Basic">
<file>../tests/testcases/BasicTest.php</file>
</testsuite>
<testsuite name="Classes">
<file>../tests/testcases/ZugferdMailConfigTest.php</file>
<file>../tests/testcases/ZugferdMailAccountTest.php</file>
<file>../tests/testcases/ZugferdMailStringHelperTest.php</file>
<file>../tests/testcases/ZugferdMailPlaceholderHelperTest.php</file>
</testsuite>
<testsuite name="Concerns">
<file>../tests/testcases/ZugferdMailConcernRaisesExceptionsTest.php</file>
<file>../tests/testcases/ZugferdMailConcernMessageBagTest.php</file>
<file>../tests/testcases/ZugferdMailConcernParsesPlaceholdersTest.php</file>
<file>../tests/testcases/ZugferdMailConcernConsoleOutputsMessageBagMessagesTest.php</file>
<file>../tests/testcases/ZugferdMailConcernConsoleHandlesConfigOptionsTest.php</file>
<file>../tests/testcases/ZugferdMailConcernConsoleHandlesMailAccountOptionsTest.php</file>
</testsuite>
<testsuite name="Handlers">
<file>../tests/testcases/BuiltinHandlersTest.php</file>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">../src</directory>
</include>
<exclude>
<file>../src/bin/ZugferdMailConsole.php</file>
</exclude>
<report>
<xml outputDirectory="coverage"/>
<html outputDirectory="coverage-html"/>
<clover outputFile="logs/clover.xml"/>
<crap4j outputFile="logs/crap4j.xml" threshold="50"/>
</report>
</coverage>
<logging>
<junit outputFile="./logs/junit.xml"/>
<testdoxHtml outputFile="./logs/testdox.html"/>
</logging>
</phpunit>
24 changes: 12 additions & 12 deletions src/ZugferdMailMessageBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function addMessage(string $type, string $source, string $message, array
* @param array $additionalData
* @return ZugferdMailMessageBag
*/
public function addLogMessage(string $source, string $message, array $additionalData = []): self
public function addLogMessage(string $source, string $message, array $additionalData = [])
{
$this->addMessage(ZugferdMailMessageBagType::MESSAGETYPE_LOG, $source, $message, $additionalData);

Expand All @@ -130,7 +130,7 @@ public function addLogMessage(string $source, string $message, array $additional
* @param array $additionalData
* @return ZugferdMailMessageBag
*/
public function addLogSecondaryMessage(string $source, string $message, array $additionalData = []): self
public function addLogSecondaryMessage(string $source, string $message, array $additionalData = [])
{
$this->addMessage(ZugferdMailMessageBagType::MESSAGETYPE_LOG_SECONDARY, $source, $message, $additionalData);

Expand All @@ -145,7 +145,7 @@ public function addLogSecondaryMessage(string $source, string $message, array $a
* @param array $additionalData
* @return ZugferdMailMessageBag
*/
public function addWarningMessage(string $source, string $message, array $additionalData = []): self
public function addWarningMessage(string $source, string $message, array $additionalData = [])
{
$this->addMessage(ZugferdMailMessageBagType::MESSAGETYPE_WARN, $source, $message, $additionalData);

Expand All @@ -160,7 +160,7 @@ public function addWarningMessage(string $source, string $message, array $additi
* @param array $additionalData
* @return ZugferdMailMessageBag
*/
public function addErrorMessage(string $source, string $message, array $additionalData = []): self
public function addErrorMessage(string $source, string $message, array $additionalData = [])
{
$this->addMessage(ZugferdMailMessageBagType::MESSAGETYPE_ERROR, $source, $message, $additionalData);

Expand All @@ -175,7 +175,7 @@ public function addErrorMessage(string $source, string $message, array $addition
* @param array $additionalData
* @return ZugferdMailMessageBag
*/
public function addSuccessMessage(string $source, string $message, array $additionalData = []): self
public function addSuccessMessage(string $source, string $message, array $additionalData = [])
{
$this->addMessage(ZugferdMailMessageBagType::MESSAGETYPE_SUCCESS, $source, $message, $additionalData);

Expand Down Expand Up @@ -217,7 +217,7 @@ private function getMessageBagFilteredByType(string $messageType): array
{
return array_filter(
$this->messageContainer,
function (array $data) use ($messageType): bool {
function ($data) use ($messageType) {
return $data['type'] == $messageType;
}
);
Expand All @@ -240,7 +240,7 @@ public function getLogMessages(): array
*/
public function hasNoLogMessages(): bool
{
return $this->getLogMessages() === [];
return empty($this->getLogMessages());
}

/**
Expand Down Expand Up @@ -270,7 +270,7 @@ public function getLogSecondaryMessages(): array
*/
public function hasNoLogSecondaryMessages(): bool
{
return $this->getLogSecondaryMessages() === [];
return empty($this->getLogSecondaryMessages());
}

/**
Expand Down Expand Up @@ -300,7 +300,7 @@ public function getWarningMessages(): array
*/
public function hasNoWarningMessages(): bool
{
return $this->getWarningMessages() === [];
return empty($this->getWarningMessages());
}

/**
Expand Down Expand Up @@ -330,7 +330,7 @@ public function getErrorMessages(): array
*/
public function hasNoErrorMessages(): bool
{
return $this->getErrorMessages() === [];
return empty($this->getErrorMessages());
}

/**
Expand Down Expand Up @@ -360,7 +360,7 @@ public function getSuccessMessages(): array
*/
public function hasNoSuccessMessages(): bool
{
return $this->getSuccessMessages() === [];
return empty($this->getSuccessMessages());
}

/**
Expand Down Expand Up @@ -390,6 +390,6 @@ public function getAllMessages(): array
*/
public function hasAnyMessage(): bool
{
return $this->getAllMessages() !== [];
return !empty($this->getAllMessages());
}
}
36 changes: 19 additions & 17 deletions src/ZugferdMailReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
*/
class ZugferdMailReader
{
use ZugferdMailSendsMessagesToMessageBag;
use ZugferdMailReceivesMessagesFromMessageBag;
use ZugferdMailClearsMessageBag;
use ZugferdMailRaisesExceptions;
use ZugferdMailSendsMessagesToMessageBag,
ZugferdMailReceivesMessagesFromMessageBag,
ZugferdMailClearsMessageBag,
ZugferdMailRaisesExceptions;

/**
* The config
Expand Down Expand Up @@ -132,7 +132,7 @@ public function checkAllAccounts(): ZugferdMailReader
protected function checkSingleAccount(ZugferdMailAccount $account): void
{
$this->clientManager->account($account->getIdentifier())->connect()->getFolders()->each(
function (Folder $folder) use ($account): void {
function (Folder $folder) use ($account) {
$this->checkSingleAccountFolder($account, $folder);
}
);
Expand All @@ -157,14 +157,14 @@ function ($query) {
return $query->unseen();
}
)->get()->each(
function (Message $message) use ($account, $folder): void {
function (Message $message) use ($account, $folder) {
$this->checkSingleMessage($account, $folder, $message);
}
);
}

collect($folder->children)->each(
function (Folder $subFolder) use ($account): void {
function (Folder $subFolder) use ($account) {
$this->checkSingleAccountFolder($account, $subFolder);
}
);
Expand All @@ -181,7 +181,7 @@ function (Folder $subFolder) use ($account): void {
protected function checkSingleMessage(ZugferdMailAccount $account, Folder $folder, Message $message): void
{
$message->attachments()->each(
function (Attachment $attachment) use ($account, $folder, $message): void {
function (Attachment $attachment) use ($account, $folder, $message) {
$this->checkSingleMessageAttachment($account, $folder, $message, $attachment);
}
);
Expand Down Expand Up @@ -217,15 +217,17 @@ protected function checkSingleMessageAttachment(ZugferdMailAccount $account, Fol

$document = null;

try {
$this->addLogMessageToMessageBag('Checking for ZUGFeRD compatible PDF', $messageAdditionalData);
$document = ZugferdDocumentPdfReader::readAndGuessFromContent($attachment->getContent());
$this->addSuccessMessageToMessageBag('Mail contains a ZUGFeRD compatible PDF', $messageAdditionalData);
$this->validateDocument($document, $messageAdditionalData);
$this->triggerHandlers($account, $folder, $message, $attachment, $document, ZugferdMailReaderRecognitionType::ZFMAIL_RECOGNITION_TYPE_PDF_CII);
$this->triggerCallbacks($account, $folder, $message, $attachment, $document, ZugferdMailReaderRecognitionType::ZFMAIL_RECOGNITION_TYPE_PDF_CII);
} catch (Throwable $e) {
$this->addWarningMessageToMessageBag(sprintf("No ZUGFeRD compatible PDF found (%s)", $e->getMessage()), $messageAdditionalData);
if (is_null($document)) {
try {
$this->addLogMessageToMessageBag('Checking for ZUGFeRD compatible PDF', $messageAdditionalData);
$document = ZugferdDocumentPdfReader::readAndGuessFromContent($attachment->getContent());
$this->addSuccessMessageToMessageBag('Mail contains a ZUGFeRD compatible PDF', $messageAdditionalData);
$this->validateDocument($document, $messageAdditionalData);
$this->triggerHandlers($account, $folder, $message, $attachment, $document, ZugferdMailReaderRecognitionType::ZFMAIL_RECOGNITION_TYPE_PDF_CII);
$this->triggerCallbacks($account, $folder, $message, $attachment, $document, ZugferdMailReaderRecognitionType::ZFMAIL_RECOGNITION_TYPE_PDF_CII);
} catch (Throwable $e) {
$this->addWarningMessageToMessageBag(sprintf("No ZUGFeRD compatible PDF found (%s)", $e->getMessage()), $messageAdditionalData);
}
}

if (is_null($document)) {
Expand Down
6 changes: 2 additions & 4 deletions src/concerns/ZugferdMailConsoleHandlesMailAccountOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ protected function writeAccountInformation(OutputInterface $output, ZugferdMailA
$account->getPort(),
$account->getProtocol(),
$account->getEncryption(),
$account->getValidateCert() ? "Yes" : "No",
$account->getAuthentication() ?? "None",
$account->getValidateCert() === true ? "Yes" : "No",
$account->getAuthentication() === null ? "None" : $account->getAuthentication(),
$account->getUsername(),
],
]
Expand All @@ -166,7 +166,6 @@ protected function writeAccountFoldersToWatch(OutputInterface $output, ZugferdMa
foreach ($account->getFoldersTowatch() as $folderToWatch) {
$table->addRow([$folderToWatch]);
}

$table->render();
}

Expand All @@ -188,7 +187,6 @@ protected function writeAccountMimeTypesToWatch(OutputInterface $output, Zugferd
foreach ($account->getMimeTypesToWatch() as $mimeTypeToWatch) {
$table->addRow([$mimeTypeToWatch]);
}

$table->render();
}
}
Loading

0 comments on commit c6c592b

Please sign in to comment.