Skip to content

Commit

Permalink
chore: fix codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
schneider-felix committed Oct 6, 2024
1 parent 8317f9d commit 3ac50a1
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/Content/MailArchive/MailArchiveDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function defineFields(): FieldCollection
(new StringField('subject', 'subject', 998))->addFlags(new Required())->addFlags(new SearchRanking(SearchRanking::HIGH_SEARCH_RANKING)),
(new LongTextField('plainText', 'plainText'))->addFlags(new AllowHtml()),
(new LongTextField('htmlText', 'htmlText'))->addFlags(new AllowHtml(), new SearchRanking(SearchRanking::LOW_SEARCH_RANKING)),
(new StringField('eml_path', 'emlPath', 2048)),
new StringField('eml_path', 'emlPath', 2048),
(new StringField('transport_state', 'transportState'))->addFlags(new Required()),

(new OneToManyAssociationField('attachments', MailArchiveAttachmentDefinition::class, 'mail_archive_id', 'id'))->addFlags(new CascadeDelete()),
Expand Down
9 changes: 6 additions & 3 deletions src/Content/MailArchive/MailArchiveEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ class MailArchiveEntity extends Entity
{
use EntityIdTrait;

/** @var array<string, string> */
/**
* @var array<string, string>
*/
protected array $sender;

/** @var array<string, string> */
/**
* @var array<string, string>
*/
protected array $receiver;

protected string $subject;
Expand Down Expand Up @@ -52,7 +56,6 @@ class MailArchiveEntity extends Entity
*/
protected ?EntityCollection $sourceMails = null;


/**
* @return array<string, string>
*/
Expand Down
17 changes: 8 additions & 9 deletions src/Controller/Api/MailArchiveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ class MailArchiveController extends AbstractController
* @param EntityRepository<EntityCollection<MailArchiveAttachmentEntity>> $froshMailArchiveAttachmentRepository
*/
public function __construct(
private readonly EntityRepository $froshMailArchiveRepository,
private readonly EntityRepository $froshMailArchiveAttachmentRepository,
private readonly EntityRepository $froshMailArchiveRepository,
private readonly EntityRepository $froshMailArchiveAttachmentRepository,
#[Autowire(service: MailSender::class)]
private readonly AbstractMailSender $mailSender,
private readonly RequestStack $requestStack,
private readonly EmlFileManager $emlFileManager,
)
{
private readonly RequestStack $requestStack,
private readonly EmlFileManager $emlFileManager,
) {
}

#[Route(path: '/api/_action/frosh-mail-archive/resend-mail', name: 'api.action.frosh-mail-archive.resend-mail')]
Expand Down Expand Up @@ -209,7 +208,7 @@ private function enrichFromEml(string $emlPath, Email $email): void
}

// Extract first item for return-path since Symfony/Mailer needs to be a string value here
if ($header->getName() === 'Return-Path' && is_array($headerValue)) {
if ($header->getName() === 'Return-Path' && \is_array($headerValue)) {
$headerValue = array_pop($headerValue);
}

Expand Down Expand Up @@ -244,7 +243,7 @@ private function enrichFromDatabase(MailArchiveEntity $mailArchive, Email $email
/**
* @return string|array<Address>|\DateTimeImmutable|null
*/
private function getHeaderValue(IHeader $header): string|array|null|\DateTimeImmutable
private function getHeaderValue(IHeader $header): string|array|\DateTimeImmutable|null
{
if ($header instanceof AddressHeader) {
/** @var AddressPart[] $addressParts */
Expand All @@ -267,7 +266,7 @@ private function getHeaderValue(IHeader $header): string|array|null|\DateTimeImm
*/
private function getFileName(array $fileNameParts): string
{
return (string)preg_replace(
return (string) preg_replace(
'/[\x00-\x1F\x7F-\xFF]/',
'',
\implode(' ', $fileNameParts),
Expand Down
4 changes: 3 additions & 1 deletion src/Migration/Migration1598204175SenderToJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ public function update(Connection $connection): void
CHANGE `sender` `sender` json NOT NULL AFTER `id`;');
}

public function updateDestructive(Connection $connection): void {}
public function updateDestructive(Connection $connection): void
{
}
}
4 changes: 3 additions & 1 deletion src/Migration/Migration1690743548AddEmlPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public function update(Connection $connection): void
ADD `eml_path` varchar(2048) NULL;');
}

public function updateDestructive(Connection $connection): void {}
public function updateDestructive(Connection $connection): void
{
}
}
4 changes: 3 additions & 1 deletion src/Migration/Migration1691326842Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ public function update(Connection $connection): void
');
}

public function updateDestructive(Connection $connection): void {}
public function updateDestructive(Connection $connection): void
{
}
}
6 changes: 4 additions & 2 deletions src/Migration/Migration1694604822AddSourceMailId.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ public function getCreationTimestamp(): int

public function update(Connection $connection): void
{
$connection->executeStatement("ALTER TABLE `frosh_mail_archive` ADD `source_mail_id` BINARY(16) NULL;");
$connection->executeStatement('ALTER TABLE `frosh_mail_archive` ADD `source_mail_id` BINARY(16) NULL;');
}

public function updateDestructive(Connection $connection): void {}
public function updateDestructive(Connection $connection): void
{
}
}
6 changes: 4 additions & 2 deletions src/Migration/Migration1694714751TransportInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ public function getCreationTimestamp(): int

public function update(Connection $connection): void
{
$connection->executeStatement("ALTER TABLE `frosh_mail_archive` ADD `transport_state` VARCHAR(255) NULL;");
$connection->executeStatement('ALTER TABLE `frosh_mail_archive` ADD `transport_state` VARCHAR(255) NULL;');
}

public function updateDestructive(Connection $connection): void {}
public function updateDestructive(Connection $connection): void
{
}
}
4 changes: 3 additions & 1 deletion src/Migration/Migration1707002823DropEmlFiled.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public function update(Connection $connection): void
$connection->executeStatement('ALTER TABLE `frosh_mail_archive` DROP COLUMN `eml`');
}

public function updateDestructive(Connection $connection): void {}
public function updateDestructive(Connection $connection): void
{
}
}
4 changes: 3 additions & 1 deletion src/Migration/Migration1713775973AlterSubjectFieldLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public function update(Connection $connection): void
$connection->executeStatement('ALTER TABLE `frosh_mail_archive` MODIFY `subject` VARCHAR(998) NOT NULL;');
}

public function updateDestructive(Connection $connection): void {}
public function updateDestructive(Connection $connection): void
{
}
}
3 changes: 2 additions & 1 deletion src/Services/EmlFileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class EmlFileManager
public function __construct(
#[Autowire(service: 'frosh_platform_mail_archive.filesystem.private')]
private readonly FilesystemOperator $filesystem,
) {}
) {
}

/**
* @return string Path to the eml file
Expand Down
15 changes: 8 additions & 7 deletions src/Services/MailSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ class MailSender extends AbstractMailSender
*/
public function __construct(
private readonly AbstractMailSender $mailSender,
private readonly RequestStack $requestStack,
private readonly EntityRepository $froshMailArchiveRepository,
private readonly EntityRepository $customerRepository,
private readonly EmlFileManager $emlFileManager,
) {}
private readonly RequestStack $requestStack,
private readonly EntityRepository $froshMailArchiveRepository,
private readonly EntityRepository $customerRepository,
private readonly EmlFileManager $emlFileManager,
) {
}

public function send(Email $email, ?Envelope $envelope = null): void
{
Expand All @@ -51,7 +52,6 @@ public function send(Email $email, ?Envelope $envelope = null): void
// save the mail first, to make sure it exists in the database when we want to update its state
$this->saveMail($id, $email);
$this->mailSender->send($email, $envelope);

}

public function getDecorated(): AbstractMailSender
Expand All @@ -70,7 +70,7 @@ private function saveMail(string $id, Email $message): void
'sender' => [$message->getFrom()[0]->getAddress() => $message->getFrom()[0]->getName()],
'receiver' => $this->convertAddress($message->getTo()),
'subject' => $message->getSubject(),
'plainText' => nl2br((string)$message->getTextBody()),
'plainText' => nl2br((string) $message->getTextBody()),
'htmlText' => $message->getHtmlBody(),
'emlPath' => $emlPath,
'salesChannelId' => $this->getCurrentSalesChannelId(),
Expand Down Expand Up @@ -138,6 +138,7 @@ private function getCustomerIdByMail(array $to): ?string

/**
* @param Address[] $addresses
*
* @return array<string, string>
*/
private function convertAddress(array $addresses): array
Expand Down
9 changes: 5 additions & 4 deletions src/Subscriber/MailArchiveDeleteSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use Frosh\MailArchive\Services\EmlFileManager;
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityDeleteEvent;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class MailArchiveDeleteSubscriber implements EventSubscriberInterface
Expand All @@ -20,8 +20,9 @@ class MailArchiveDeleteSubscriber implements EventSubscriberInterface
*/
public function __construct(
private readonly EntityRepository $froshMailArchiveRepository,
private readonly EmlFileManager $emlFileManager,
) {}
private readonly EmlFileManager $emlFileManager,
) {
}

public static function getSubscribedEvents(): array
{
Expand All @@ -48,7 +49,7 @@ public function beforeDelete(EntityDeleteEvent $event): void
continue;
}

$event->addSuccess(function () use ($emlPath) {
$event->addSuccess(function () use ($emlPath): void {
$this->emlFileManager->deleteEmlFile($emlPath);
});
}
Expand Down
14 changes: 6 additions & 8 deletions src/Subscriber/MailTransportSubscriber.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace Frosh\MailArchive\Subscriber;

Expand All @@ -22,9 +22,8 @@ class MailTransportSubscriber implements EventSubscriberInterface
*/
public function __construct(
private readonly EntityRepository $froshMailArchiveRepository,
private readonly EmlFileManager $emlFileManager,
)
{
private readonly EmlFileManager $emlFileManager,
) {
}

public static function getSubscribedEvents(): array
Expand Down Expand Up @@ -53,7 +52,7 @@ private function updateArchiveState(RawMessage $message, string $newState): void
return;
}

$context = Context::createCLIContext();
$context = Context::createDefaultContext();
$archiveId = $this->getArchiveIdByMessage($message);

if (!$archiveId) {
Expand All @@ -66,9 +65,8 @@ private function updateArchiveState(RawMessage $message, string $newState): void
$this->froshMailArchiveRepository->update([[
'id' => $archiveId,
'transportState' => $newState,
'attachments' => $attachments
'attachments' => $attachments,
]], $context);

}

private function getAttachments(Email $message): array

Check failure on line 72 in src/Subscriber/MailTransportSubscriber.php

View workflow job for this annotation

GitHub Actions / phpstan / Static Analyse

Method Frosh\MailArchive\Subscriber\MailTransportSubscriber::getAttachments() return type has no value type specified in iterable type array.
Expand All @@ -79,7 +77,7 @@ private function getAttachments(Email $message): array
return [
'fileName' => $attachment->getFilename(),
'contentType' => $attachment->getContentType(),
'fileSize' => strlen($attachment->getBody())
'fileSize' => \strlen($attachment->getBody()),
];
}, $attachments);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Task/CleanupTaskHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Frosh\MailArchive\Task;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Frosh\MailArchive\Content\MailArchive\MailArchiveDefinition;
use Frosh\MailArchive\Services\EmlFileManager;
use Shopware\Core\Defaults;
Expand Down Expand Up @@ -39,7 +39,7 @@ public function run(): void
}

$time = new \DateTime();
$time->modify(sprintf('-%s days', $days));
$time->modify(\sprintf('-%s days', $days));

$query = $this->connection->createQueryBuilder();

Expand Down

0 comments on commit 3ac50a1

Please sign in to comment.