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:
@@ -8,7 +8,6 @@ use App\Entity\Connector;
|
||||
use App\Entity\User;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Exception;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
@@ -18,8 +17,7 @@ class ConnectorController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly SerializerInterface $serializer, private readonly EntityManagerInterface $em
|
||||
)
|
||||
{
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route(
|
||||
@@ -35,11 +33,12 @@ class ConnectorController extends AbstractController
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
return $user->getConnectors();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
#[Route(
|
||||
path: '/api/connectors',
|
||||
@@ -55,15 +54,16 @@ class ConnectorController extends AbstractController
|
||||
$connector = $this->serializer->deserialize($request->getContent(), Connector::class, 'json', ['groups' => 'connector:create']);
|
||||
$connector->setUser($this->getUser());
|
||||
|
||||
if ($connector->getProvider() === ConnectorProvider::OVH) {
|
||||
if (ConnectorProvider::OVH === $connector->getProvider()) {
|
||||
$authData = OvhConnector::verifyAuthData($connector->getAuthData());
|
||||
$connector->setAuthData($authData);
|
||||
} else throw new Exception('Unknown provider');
|
||||
} else {
|
||||
throw new \Exception('Unknown provider');
|
||||
}
|
||||
|
||||
$this->em->persist($connector);
|
||||
$this->em->flush();
|
||||
|
||||
return $connector;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ use App\Entity\WatchList;
|
||||
use App\Message\ProcessDomainTrigger;
|
||||
use App\Repository\DomainRepository;
|
||||
use App\Service\RDAPService;
|
||||
use DateTimeImmutable;
|
||||
use Exception;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
@@ -21,11 +19,10 @@ use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
|
||||
class DomainRefreshController extends AbstractController
|
||||
{
|
||||
|
||||
public function __construct(private readonly DomainRepository $domainRepository,
|
||||
private readonly RDAPService $RDAPService,
|
||||
private readonly RateLimiterFactory $authenticatedApiLimiter,
|
||||
private readonly MessageBusInterface $bus)
|
||||
public function __construct(private readonly DomainRepository $domainRepository,
|
||||
private readonly RDAPService $RDAPService,
|
||||
private readonly RateLimiterFactory $authenticatedApiLimiter,
|
||||
private readonly MessageBusInterface $bus)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -34,26 +31,30 @@ class DomainRefreshController extends AbstractController
|
||||
* @throws HttpExceptionInterface
|
||||
* @throws DecodingExceptionInterface
|
||||
* @throws ExceptionInterface
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __invoke(string $ldhName, KernelInterface $kernel): ?Domain
|
||||
{
|
||||
/** @var Domain $domain */
|
||||
$domain = $this->domainRepository->findOneBy(["ldhName" => $ldhName]);
|
||||
$domain = $this->domainRepository->findOneBy(['ldhName' => $ldhName]);
|
||||
|
||||
// If the domain name exists in the database, recently updated and not important, we return the stored Domain
|
||||
if ($domain !== null &&
|
||||
!$domain->getDeleted() &&
|
||||
($domain->getUpdatedAt()->diff(new DateTimeImmutable('now'))->days < 7) &&
|
||||
!$this->RDAPService::isToBeWatchClosely($domain, $domain->getUpdatedAt())
|
||||
) return $domain;
|
||||
if (null !== $domain
|
||||
&& !$domain->getDeleted()
|
||||
&& ($domain->getUpdatedAt()->diff(new \DateTimeImmutable('now'))->days < 7)
|
||||
&& !$this->RDAPService::isToBeWatchClosely($domain, $domain->getUpdatedAt())
|
||||
) {
|
||||
return $domain;
|
||||
}
|
||||
|
||||
if (false === $kernel->isDebug()) {
|
||||
$limiter = $this->authenticatedApiLimiter->create($this->getUser()->getUserIdentifier());
|
||||
if (false === $limiter->consume()->isAccepted()) throw new TooManyRequestsHttpException();
|
||||
if (false === $limiter->consume()->isAccepted()) {
|
||||
throw new TooManyRequestsHttpException();
|
||||
}
|
||||
}
|
||||
|
||||
$updatedAt = $domain === null ? new DateTimeImmutable('now') : $domain->getUpdatedAt();
|
||||
$updatedAt = null === $domain ? new \DateTimeImmutable('now') : $domain->getUpdatedAt();
|
||||
$domain = $this->RDAPService->registerDomain($ldhName);
|
||||
|
||||
/** @var WatchList $watchList */
|
||||
@@ -63,4 +64,4 @@ class DomainRefreshController extends AbstractController
|
||||
|
||||
return $domain;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,29 +12,30 @@ use Symfony\Component\Routing\RouterInterface;
|
||||
|
||||
class HomeController extends AbstractController
|
||||
{
|
||||
|
||||
public function __construct(private readonly RouterInterface $router)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route(path: "/", name: "index")]
|
||||
#[Route(path: '/', name: 'index')]
|
||||
public function index(): Response
|
||||
{
|
||||
return $this->render('base.html.twig');
|
||||
}
|
||||
|
||||
#[Route(path: "/login/oauth", name: "oauth_connect")]
|
||||
#[Route(path: '/login/oauth', name: 'oauth_connect')]
|
||||
public function connectAction(ClientRegistry $clientRegistry): Response
|
||||
{
|
||||
return $clientRegistry->getClient('oauth')->redirect();
|
||||
}
|
||||
|
||||
#[Route(path: "/logout", name: "logout")]
|
||||
#[Route(path: '/logout', name: 'logout')]
|
||||
public function logout(Security $security): ?RedirectResponse
|
||||
{
|
||||
$response = new RedirectResponse($this->router->generate('index'));
|
||||
$response->headers->clearCookie('BEARER');
|
||||
if ($security->isGranted('IS_AUTHENTICATED')) $security->logout(false);
|
||||
if ($security->isGranted('IS_AUTHENTICATED')) {
|
||||
$security->logout(false);
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
@@ -7,10 +7,8 @@ use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
class MeController extends AbstractController
|
||||
{
|
||||
|
||||
public function __invoke(): UserInterface
|
||||
{
|
||||
return $this->getUser();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ use Eluceo\iCal\Domain\ValueObject\Date;
|
||||
use Eluceo\iCal\Domain\ValueObject\EmailAddress;
|
||||
use Eluceo\iCal\Domain\ValueObject\SingleDay;
|
||||
use Eluceo\iCal\Presentation\Factory\CalendarFactory;
|
||||
use Exception;
|
||||
use Sabre\VObject\EofException;
|
||||
use Sabre\VObject\InvalidDataException;
|
||||
use Sabre\VObject\ParseException;
|
||||
@@ -30,17 +29,15 @@ use Symfony\Component\Serializer\SerializerInterface;
|
||||
|
||||
class WatchListController extends AbstractController
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
private readonly SerializerInterface $serializer,
|
||||
private readonly SerializerInterface $serializer,
|
||||
private readonly EntityManagerInterface $em,
|
||||
private readonly WatchListRepository $watchListRepository
|
||||
)
|
||||
{
|
||||
private readonly WatchListRepository $watchListRepository
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
#[Route(
|
||||
path: '/api/watchlists',
|
||||
@@ -66,7 +63,7 @@ class WatchListController extends AbstractController
|
||||
* @throws ParseException
|
||||
* @throws EofException
|
||||
* @throws InvalidDataException
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
#[Route(
|
||||
path: '/api/watchlists/{token}/calendar',
|
||||
@@ -79,7 +76,7 @@ class WatchListController extends AbstractController
|
||||
public function getWatchlistCalendar(string $token): Response
|
||||
{
|
||||
/** @var WatchList $watchList */
|
||||
$watchList = $this->watchListRepository->findOneBy(["token" => $token]);
|
||||
$watchList = $this->watchListRepository->findOneBy(['token' => $token]);
|
||||
|
||||
$calendar = new Calendar();
|
||||
|
||||
@@ -89,16 +86,18 @@ class WatchListController extends AbstractController
|
||||
/** @var DomainEntity $entity */
|
||||
foreach ($domain->getDomainEntities()->toArray() as $entity) {
|
||||
$vCard = Reader::readJson($entity->getEntity()->getJCard());
|
||||
$email = (string)$vCard->EMAIL;
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) continue;
|
||||
$email = (string) $vCard->EMAIL;
|
||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$attendees[] = (new Attendee(new EmailAddress($email)))->setDisplayName((string)$vCard->FN);
|
||||
$attendees[] = (new Attendee(new EmailAddress($email)))->setDisplayName((string) $vCard->FN);
|
||||
}
|
||||
|
||||
/** @var DomainEvent $event */
|
||||
foreach ($domain->getEvents()->toArray() as $event) {
|
||||
$calendar->addEvent((new Event())
|
||||
->setSummary($domain->getLdhName() . ' (' . $event->getAction() . ')')
|
||||
->setSummary($domain->getLdhName().' ('.$event->getAction().')')
|
||||
->addCategory(new Category($event->getAction()))
|
||||
->setAttendees($attendees)
|
||||
->setOccurrence(new SingleDay(new Date($event->getDate())))
|
||||
@@ -107,7 +106,7 @@ class WatchListController extends AbstractController
|
||||
}
|
||||
|
||||
return new Response((new CalendarFactory())->createCalendar($calendar), Response::HTTP_OK, [
|
||||
"Content-Type" => 'text/calendar; charset=utf-8'
|
||||
'Content-Type' => 'text/calendar; charset=utf-8',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -124,7 +123,7 @@ class WatchListController extends AbstractController
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
return $user->getWatchLists();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user