mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
ci: add php cs fixer
This commit is contained in:
@@ -14,63 +14,61 @@ use App\Entity\WatchListTrigger;
|
||||
use App\Message\ProcessDomainTrigger;
|
||||
use App\Repository\DomainRepository;
|
||||
use App\Repository\WatchListRepository;
|
||||
use Exception;
|
||||
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
use Symfony\Component\Mime\Email;
|
||||
use Throwable;
|
||||
|
||||
#[AsMessageHandler]
|
||||
final readonly class ProcessDomainTriggerHandler
|
||||
{
|
||||
public function __construct(
|
||||
private string $mailerSenderEmail,
|
||||
private MailerInterface $mailer,
|
||||
private string $mailerSenderEmail,
|
||||
private MailerInterface $mailer,
|
||||
private WatchListRepository $watchListRepository,
|
||||
private DomainRepository $domainRepository,
|
||||
private KernelInterface $kernel
|
||||
|
||||
)
|
||||
{
|
||||
private DomainRepository $domainRepository,
|
||||
private KernelInterface $kernel
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __invoke(ProcessDomainTrigger $message): void
|
||||
{
|
||||
/** @var WatchList $watchList */
|
||||
$watchList = $this->watchListRepository->findOneBy(["token" => $message->watchListToken]);
|
||||
$watchList = $this->watchListRepository->findOneBy(['token' => $message->watchListToken]);
|
||||
/** @var Domain $domain */
|
||||
$domain = $this->domainRepository->findOneBy(["ldhName" => $message->ldhName]);
|
||||
$domain = $this->domainRepository->findOneBy(['ldhName' => $message->ldhName]);
|
||||
|
||||
$connector = $watchList->getConnector();
|
||||
if (null !== $connector && $domain->getDeleted()) {
|
||||
try {
|
||||
if ($connector->getProvider() === ConnectorProvider::OVH) {
|
||||
$ovh = new OVHConnector($connector->getAuthData());
|
||||
if (ConnectorProvider::OVH === $connector->getProvider()) {
|
||||
$ovh = new OvhConnector($connector->getAuthData());
|
||||
$isDebug = $this->kernel->isDebug();
|
||||
|
||||
$ovh->orderDomain($domain, $isDebug);
|
||||
$this->sendEmailDomainOrdered($domain, $connector, $watchList->getUser());
|
||||
} else throw new Exception("Unknown provider");
|
||||
} catch (Throwable) {
|
||||
} else {
|
||||
throw new \Exception('Unknown provider');
|
||||
}
|
||||
} catch (\Throwable) {
|
||||
$this->sendEmailDomainOrderError($domain, $watchList->getUser());
|
||||
}
|
||||
}
|
||||
|
||||
/** @var DomainEvent $event */
|
||||
foreach ($domain->getEvents()->filter(fn($event) => $message->updatedAt < $event->getDate()) as $event) {
|
||||
foreach ($domain->getEvents()->filter(fn ($event) => $message->updatedAt < $event->getDate()) as $event) {
|
||||
$watchListTriggers = $watchList->getWatchListTriggers()
|
||||
->filter(fn($trigger) => $trigger->getEvent() === $event->getAction());
|
||||
->filter(fn ($trigger) => $trigger->getEvent() === $event->getAction());
|
||||
|
||||
/** @var WatchListTrigger $watchListTrigger */
|
||||
foreach ($watchListTriggers->getIterator() as $watchListTrigger) {
|
||||
if ($watchListTrigger->getAction() == TriggerAction::SendEmail) {
|
||||
if (TriggerAction::SendEmail == $watchListTrigger->getAction()) {
|
||||
$this->sendEmailDomainUpdated($event, $watchList->getUser());
|
||||
}
|
||||
}
|
||||
@@ -90,8 +88,8 @@ final readonly class ProcessDomainTriggerHandler
|
||||
->htmlTemplate('emails/success/domain_ordered.html.twig')
|
||||
->locale('en')
|
||||
->context([
|
||||
"domain" => $domain,
|
||||
"provider" => $connector->getProvider()->value
|
||||
'domain' => $domain,
|
||||
'provider' => $connector->getProvider()->value,
|
||||
]);
|
||||
|
||||
$this->mailer->send($email);
|
||||
@@ -109,7 +107,7 @@ final readonly class ProcessDomainTriggerHandler
|
||||
->htmlTemplate('emails/errors/domain_order.html.twig')
|
||||
->locale('en')
|
||||
->context([
|
||||
"domain" => $domain
|
||||
'domain' => $domain,
|
||||
]);
|
||||
|
||||
$this->mailer->send($email);
|
||||
@@ -128,10 +126,9 @@ final readonly class ProcessDomainTriggerHandler
|
||||
->htmlTemplate('emails/success/domain_updated.html.twig')
|
||||
->locale('en')
|
||||
->context([
|
||||
"event" => $domainEvent
|
||||
'event' => $domainEvent,
|
||||
]);
|
||||
|
||||
$this->mailer->send($email);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ use App\Message\ProcessDomainTrigger;
|
||||
use App\Message\ProcessWatchListTrigger;
|
||||
use App\Repository\WatchListRepository;
|
||||
use App\Service\RDAPService;
|
||||
use DateTimeImmutable;
|
||||
use Exception;
|
||||
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
||||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
@@ -18,36 +16,33 @@ use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
use Symfony\Component\Messenger\Exception\ExceptionInterface;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
|
||||
use Throwable;
|
||||
|
||||
#[AsMessageHandler]
|
||||
final readonly class ProcessWatchListTriggerHandler
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
private RDAPService $RDAPService,
|
||||
private MailerInterface $mailer,
|
||||
private string $mailerSenderEmail,
|
||||
private RDAPService $RDAPService,
|
||||
private MailerInterface $mailer,
|
||||
private string $mailerSenderEmail,
|
||||
private MessageBusInterface $bus,
|
||||
private WatchListRepository $watchListRepository
|
||||
)
|
||||
{
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
* @throws ExceptionInterface
|
||||
*/
|
||||
public function __invoke(ProcessWatchListTrigger $message): void
|
||||
{
|
||||
/** @var WatchList $watchList */
|
||||
$watchList = $this->watchListRepository->findOneBy(["token" => $message->watchListToken]);
|
||||
$watchList = $this->watchListRepository->findOneBy(['token' => $message->watchListToken]);
|
||||
/** @var Domain $domain */
|
||||
foreach ($watchList->getDomains()
|
||||
->filter(fn($domain) => $domain->getUpdatedAt()
|
||||
->filter(fn ($domain) => $domain->getUpdatedAt()
|
||||
->diff(
|
||||
new DateTimeImmutable('now'))->days >= 7
|
||||
new \DateTimeImmutable('now'))->days >= 7
|
||||
|| $this->RDAPService::isToBeWatchClosely($domain, $domain->getUpdatedAt())
|
||||
) as $domain
|
||||
) {
|
||||
@@ -55,8 +50,10 @@ final readonly class ProcessWatchListTriggerHandler
|
||||
|
||||
try {
|
||||
$domain = $this->RDAPService->registerDomain($domain->getLdhName());
|
||||
} catch (Throwable $e) {
|
||||
if (!($e instanceof HttpExceptionInterface)) continue;
|
||||
} catch (\Throwable $e) {
|
||||
if (!($e instanceof HttpExceptionInterface)) {
|
||||
continue;
|
||||
}
|
||||
$this->sendEmailDomainUpdateError($domain, $watchList->getUser());
|
||||
}
|
||||
|
||||
@@ -77,7 +74,6 @@ final readonly class ProcessWatchListTriggerHandler
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
@@ -90,7 +86,7 @@ final readonly class ProcessWatchListTriggerHandler
|
||||
->htmlTemplate('emails/errors/domain_update.html.twig')
|
||||
->locale('en')
|
||||
->context([
|
||||
"domain" => $domain
|
||||
'domain' => $domain,
|
||||
]);
|
||||
|
||||
$this->mailer->send($email);
|
||||
|
||||
@@ -11,14 +11,12 @@ use Symfony\Component\Messenger\Exception\ExceptionInterface;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
|
||||
#[AsMessageHandler]
|
||||
readonly final class ProcessWatchListsTriggerHandler
|
||||
final readonly class ProcessWatchListsTriggerHandler
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
private WatchListRepository $watchListRepository,
|
||||
private MessageBusInterface $bus
|
||||
)
|
||||
{
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -31,5 +29,4 @@ readonly final class ProcessWatchListsTriggerHandler
|
||||
$this->bus->dispatch(new ProcessWatchListTrigger($watchList->getToken()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,14 +10,12 @@ use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use Throwable;
|
||||
|
||||
#[AsMessageHandler]
|
||||
final readonly class UpdateRdapServersHandler
|
||||
{
|
||||
public function __construct(private RDAPService $RDAPService)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,23 +23,25 @@ final readonly class UpdateRdapServersHandler
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws DecodingExceptionInterface
|
||||
* @throws ClientExceptionInterface|Throwable
|
||||
* @throws ClientExceptionInterface|\Throwable
|
||||
*/
|
||||
public function __invoke(UpdateRdapServers $message): void
|
||||
{
|
||||
/** @var Throwable[] $throws */
|
||||
/** @var \Throwable[] $throws */
|
||||
$throws = [];
|
||||
try {
|
||||
$this->RDAPService->updateTldListIANA();
|
||||
$this->RDAPService->updateGTldListICANN();
|
||||
} catch (Throwable $throwable) {
|
||||
} catch (\Throwable $throwable) {
|
||||
$throws[] = $throwable;
|
||||
}
|
||||
try {
|
||||
$this->RDAPService->updateRDAPServers();
|
||||
} catch (Throwable $throwable) {
|
||||
} catch (\Throwable $throwable) {
|
||||
$throws[] = $throwable;
|
||||
}
|
||||
if (!empty($throws)) throw $throws[0];
|
||||
if (!empty($throws)) {
|
||||
throw $throws[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user