Apply PHP CS Fixer formatting rules
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Mime\Email;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class CspReportController extends AbstractController
|
||||
@@ -23,8 +23,9 @@ class CspReportController extends AbstractController
|
||||
|
||||
$report = json_decode($data, true);
|
||||
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$logger->error('CSP Report JSON decode error: ' . json_last_error_msg());
|
||||
if (JSON_ERROR_NONE !== json_last_error()) {
|
||||
$logger->error('CSP Report JSON decode error: '.json_last_error_msg());
|
||||
|
||||
return new Response('Invalid JSON', 400);
|
||||
}
|
||||
|
||||
@@ -38,24 +39,25 @@ class CspReportController extends AbstractController
|
||||
$shouldIgnore = false;
|
||||
|
||||
if (
|
||||
str_contains($sourceFile, 'extension://') ||
|
||||
str_contains($sourceFile, 'chrome-extension') ||
|
||||
str_contains($sourceFile, 'moz-extension') ||
|
||||
str_contains($documentUri, '.local') ||
|
||||
str_contains($sourceFile, 'localhost') ||
|
||||
$blockedUri === 'wasm-eval' ||
|
||||
$blockedUri === 'inline' && str_contains($sourceFile, 'node_modules') ||
|
||||
$blockedUri === 'about:blank'
|
||||
str_contains($sourceFile, 'extension://')
|
||||
|| str_contains($sourceFile, 'chrome-extension')
|
||||
|| str_contains($sourceFile, 'moz-extension')
|
||||
|| str_contains($documentUri, '.local')
|
||||
|| str_contains($sourceFile, 'localhost')
|
||||
|| 'wasm-eval' === $blockedUri
|
||||
|| 'inline' === $blockedUri && str_contains($sourceFile, 'node_modules')
|
||||
|| 'about:blank' === $blockedUri
|
||||
) {
|
||||
$shouldIgnore = true;
|
||||
}
|
||||
|
||||
if ($shouldIgnore) {
|
||||
$logger->info('CSP Violation ignored (Extension or Local Dev): ' . $sourceFile);
|
||||
$logger->info('CSP Violation ignored (Extension or Local Dev): '.$sourceFile);
|
||||
|
||||
return new Response('Report ignored', 204);
|
||||
}
|
||||
|
||||
$logger->warning('REAL CSP VIOLATION: ' . $data);
|
||||
$logger->warning('REAL CSP VIOLATION: '.$data);
|
||||
|
||||
$email = (new Email())
|
||||
->from('security-notify@e-cosplay.fr')
|
||||
@@ -63,19 +65,19 @@ class CspReportController extends AbstractController
|
||||
->subject('Alerte Securite : Violation CSP detectee')
|
||||
->priority(Email::PRIORITY_HIGH)
|
||||
->text(
|
||||
"Un rapport de violation CSP potentiellement critique a ete intercepte.\n\n" .
|
||||
"Document: " . $documentUri . "\n" .
|
||||
"Directive violee: " . $violatedDirective . "\n" .
|
||||
"Element bloque: " . $blockedUri . "\n" .
|
||||
"Fichier source: " . $sourceFile . "\n\n" .
|
||||
"Details complets :\n" .
|
||||
"Un rapport de violation CSP potentiellement critique a ete intercepte.\n\n".
|
||||
'Document: '.$documentUri."\n".
|
||||
'Directive violee: '.$violatedDirective."\n".
|
||||
'Element bloque: '.$blockedUri."\n".
|
||||
'Fichier source: '.$sourceFile."\n\n".
|
||||
"Details complets :\n".
|
||||
json_encode($report, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
|
||||
);
|
||||
|
||||
try {
|
||||
$mailer->send($email);
|
||||
} catch (\Exception $e) {
|
||||
$logger->error('Failed to send CSP report email: ' . $e->getMessage());
|
||||
$logger->error('Failed to send CSP report email: '.$e->getMessage());
|
||||
}
|
||||
|
||||
return new Response('Report processed', 204);
|
||||
|
||||
@@ -21,12 +21,12 @@ class EmailTrackingController extends AbstractController
|
||||
): Response {
|
||||
$tracking = $repository->findOneBy(['messageId' => $messageId]);
|
||||
|
||||
if ($tracking !== null) {
|
||||
if (null !== $tracking) {
|
||||
$tracking->markAsOpened();
|
||||
$em->flush();
|
||||
}
|
||||
|
||||
$response = new BinaryFileResponse($projectDir . '/public/logo.jpg');
|
||||
$response = new BinaryFileResponse($projectDir.'/public/logo.jpg');
|
||||
$response->headers->set('Content-Type', 'image/jpeg');
|
||||
$response->headers->set('Cache-Control', 'no-store');
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ class RegistrationController extends AbstractController
|
||||
foreach ($errors as $error) {
|
||||
$this->addFlash('error', $error->getMessage());
|
||||
}
|
||||
|
||||
return $this->render('security/register.html.twig');
|
||||
}
|
||||
|
||||
@@ -45,6 +46,7 @@ class RegistrationController extends AbstractController
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', 'Compte créé avec succès ! Connectez-vous.');
|
||||
|
||||
return $this->redirectToRoute('app_login');
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class SitemapController extends AbstractController
|
||||
['loc' => $this->generateUrl('app_sitemap_main', [], UrlGeneratorInterface::ABSOLUTE_URL)],
|
||||
];
|
||||
|
||||
for ($i = 1; $i <= $eventPages; $i++) {
|
||||
for ($i = 1; $i <= $eventPages; ++$i) {
|
||||
$sitemaps[] = [
|
||||
'loc' => $this->generateUrl('app_sitemap_events', ['page' => $i], UrlGeneratorInterface::ABSOLUTE_URL),
|
||||
];
|
||||
|
||||
@@ -25,7 +25,7 @@ class UnsubscribeController extends AbstractController
|
||||
'email' => $email,
|
||||
'breadcrumbs' => [
|
||||
['name' => 'Accueil', 'url' => '/'],
|
||||
['name' => 'Desinscription', 'url' => '/unsubscribe/' . $token],
|
||||
['name' => 'Desinscription', 'url' => '/unsubscribe/'.$token],
|
||||
],
|
||||
]);
|
||||
}
|
||||
@@ -35,7 +35,7 @@ class UnsubscribeController extends AbstractController
|
||||
'token' => $token,
|
||||
'breadcrumbs' => [
|
||||
['name' => 'Accueil', 'url' => '/'],
|
||||
['name' => 'Desinscription', 'url' => '/unsubscribe/' . $token],
|
||||
['name' => 'Desinscription', 'url' => '/unsubscribe/'.$token],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ class EmailTracking
|
||||
|
||||
public function markAsOpened(): void
|
||||
{
|
||||
if ($this->state === 'sent') {
|
||||
if ('sent' === $this->state) {
|
||||
$this->state = 'opened';
|
||||
$this->openedAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
@@ -85,6 +85,7 @@ class MessengerLog
|
||||
public function setStatus(string $status): static
|
||||
{
|
||||
$this->status = $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
public function setEmail(string $email): static
|
||||
{
|
||||
$this->email = $email;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -66,6 +67,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
public function setFirstName(string $firstName): static
|
||||
{
|
||||
$this->firstName = $firstName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -77,6 +79,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
public function setLastName(string $lastName): static
|
||||
{
|
||||
$this->lastName = $lastName;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -90,6 +93,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
{
|
||||
$roles = $this->roles;
|
||||
$roles[] = 'ROLE_USER';
|
||||
|
||||
return array_unique($roles);
|
||||
}
|
||||
|
||||
@@ -97,6 +101,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
public function setRoles(array $roles): static
|
||||
{
|
||||
$this->roles = $roles;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -108,6 +113,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
||||
public function setPassword(string $password): static
|
||||
{
|
||||
$this->password = $password;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,16 +6,17 @@ use App\Entity\MessengerLog;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Mime\Email;
|
||||
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;
|
||||
use Symfony\Component\Messenger\Stamp\RedeliveryStamp;
|
||||
use Symfony\Component\Mime\Email;
|
||||
|
||||
class MessengerFailureSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public function __construct(
|
||||
private EntityManagerInterface $em,
|
||||
private MailerInterface $mailer,
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
@@ -40,7 +41,7 @@ class MessengerFailureSubscriber implements EventSubscriberInterface
|
||||
try {
|
||||
$messageBody = serialize($message);
|
||||
} catch (\Throwable) {
|
||||
$messageBody = get_class($message) . ' (not serializable)';
|
||||
$messageBody = get_class($message).' (not serializable)';
|
||||
}
|
||||
|
||||
$log = new MessengerLog(
|
||||
@@ -62,12 +63,12 @@ class MessengerFailureSubscriber implements EventSubscriberInterface
|
||||
->subject('Alerte Messenger : Echec de traitement')
|
||||
->priority(Email::PRIORITY_HIGH)
|
||||
->text(
|
||||
"Un message Messenger a echoue.\n\n" .
|
||||
"Message: " . get_class($message) . "\n" .
|
||||
"Transport: " . $event->getReceiverName() . "\n" .
|
||||
"Retry: " . $retryCount . "\n" .
|
||||
"Erreur: " . $throwable->getMessage() . "\n\n" .
|
||||
"Stack trace:\n" . $throwable->getTraceAsString()
|
||||
"Un message Messenger a echoue.\n\n".
|
||||
'Message: '.get_class($message)."\n".
|
||||
'Transport: '.$event->getReceiverName()."\n".
|
||||
'Retry: '.$retryCount."\n".
|
||||
'Erreur: '.$throwable->getMessage()."\n\n".
|
||||
"Stack trace:\n".$throwable->getTraceAsString()
|
||||
);
|
||||
|
||||
$this->mailer->send($email);
|
||||
|
||||
@@ -11,5 +11,6 @@ class MeilisearchMessage
|
||||
public readonly string $action,
|
||||
public readonly string $index,
|
||||
public readonly array $payload = [],
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ class MeilisearchMessageHandler
|
||||
{
|
||||
public function __construct(
|
||||
private MeilisearchService $meilisearch,
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(MeilisearchMessage $message): void
|
||||
{
|
||||
|
||||
@@ -9,7 +9,8 @@ class CacheService
|
||||
{
|
||||
public function __construct(
|
||||
private CacheItemPoolInterface $cache,
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
public function get(CacheKey $key, string|int ...$params): mixed
|
||||
{
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\EmailTracking;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\Mailer\Messenger\SendEmailMessage;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Component\Mime\Crypto\SMimeSigner;
|
||||
use Symfony\Component\Mime\Email;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Component\Mailer\Messenger\SendEmailMessage;
|
||||
use App\Entity\EmailTracking;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class MailerService
|
||||
{
|
||||
@@ -24,18 +24,19 @@ class MailerService
|
||||
private UrlGeneratorInterface $urlGenerator,
|
||||
private UnsubscribeManager $unsubscribeManager,
|
||||
private EntityManagerInterface $em,
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
public function send(Email $email): void
|
||||
{
|
||||
$publicKeyPath = $this->projectDir . '/public/key.asc';
|
||||
$publicKeyPath = $this->projectDir.'/public/key.asc';
|
||||
|
||||
if (file_exists($publicKeyPath)) {
|
||||
$email->attachFromPath($publicKeyPath, 'public_key.asc', 'application/pgp-keys');
|
||||
}
|
||||
|
||||
$certificate = $this->projectDir . '/config/cert/certificate.pem';
|
||||
$privateKey = $this->projectDir . '/config/cert/private-key.pem';
|
||||
$certificate = $this->projectDir.'/config/cert/certificate.pem';
|
||||
$privateKey = $this->projectDir.'/config/cert/private-key.pem';
|
||||
|
||||
if (file_exists($certificate) && file_exists($privateKey)) {
|
||||
$signer = new SMimeSigner($certificate, $privateKey, $this->smimePassphrase);
|
||||
@@ -73,7 +74,7 @@ class MailerService
|
||||
}
|
||||
|
||||
$messageId = bin2hex(random_bytes(16));
|
||||
$email->getHeaders()->addIdHeader('Message-ID', $messageId . '@e-cosplay.fr');
|
||||
$email->getHeaders()->addIdHeader('Message-ID', $messageId.'@e-cosplay.fr');
|
||||
|
||||
$tracking = new EmailTracking($messageId, $to, $subject);
|
||||
$this->em->persist($tracking);
|
||||
|
||||
@@ -14,15 +14,17 @@ class MeilisearchService
|
||||
private MessageBusInterface $bus,
|
||||
#[Autowire(env: 'MEILISEARCH_URL')] private string $url,
|
||||
#[Autowire(env: 'MEILISEARCH_API_KEY')] private string $apiKey,
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
public function indexExists(string $index): bool
|
||||
{
|
||||
try {
|
||||
$response = $this->httpClient->request('GET', $this->url . "/indexes/{$index}", [
|
||||
$response = $this->httpClient->request('GET', $this->url."/indexes/{$index}", [
|
||||
'headers' => ['Authorization' => "Bearer {$this->apiKey}"],
|
||||
]);
|
||||
return $response->getStatusCode() === 200;
|
||||
|
||||
return 200 === $response->getStatusCode();
|
||||
} catch (\Throwable) {
|
||||
return false;
|
||||
}
|
||||
@@ -84,6 +86,7 @@ class MeilisearchService
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function search(string $index, string $query, array $options = []): array
|
||||
@@ -103,6 +106,7 @@ class MeilisearchService
|
||||
|
||||
/**
|
||||
* @param array<string, mixed>|null $body
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function request(string $method, string $path, ?array $body = null): array
|
||||
@@ -114,13 +118,13 @@ class MeilisearchService
|
||||
],
|
||||
];
|
||||
|
||||
if ($body !== null && $method !== 'GET' && $method !== 'DELETE') {
|
||||
if (null !== $body && 'GET' !== $method && 'DELETE' !== $method) {
|
||||
$options['json'] = $body;
|
||||
}
|
||||
|
||||
$response = $this->httpClient->request($method, $this->url . $path, $options);
|
||||
$response = $this->httpClient->request($method, $this->url.$path, $options);
|
||||
|
||||
if ($response->getStatusCode() === 204) {
|
||||
if (204 === $response->getStatusCode()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class UnsubscribeManager
|
||||
#[Autowire('%kernel.project_dir%')] string $projectDir,
|
||||
#[Autowire('%kernel.secret%')] string $appSecret,
|
||||
) {
|
||||
$this->storagePath = $projectDir . '/var/unsubscribed.json';
|
||||
$this->storagePath = $projectDir.'/var/unsubscribed.json';
|
||||
$this->secret = $appSecret;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
namespace App\Twig;
|
||||
|
||||
use Detection\MobileDetect;
|
||||
use Nelmio\SecurityBundle\EventListener\ContentSecurityPolicyListener;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
use Nelmio\SecurityBundle\EventListener\ContentSecurityPolicyListener;
|
||||
|
||||
class ViteAssetExtension extends AbstractExtension
|
||||
{
|
||||
const CACHE_KEY = 'vite_manifest';
|
||||
public const CACHE_KEY = 'vite_manifest';
|
||||
/** @var array<string, array<string, mixed>>|null */
|
||||
private ?array $manifestData = null;
|
||||
private readonly bool $isDev;
|
||||
@@ -20,7 +20,7 @@ class ViteAssetExtension extends AbstractExtension
|
||||
private readonly CacheItemPoolInterface $cache,
|
||||
private readonly ?ContentSecurityPolicyListener $cspListener = null,
|
||||
) {
|
||||
$this->isDev = $_ENV['VITE_LOAD'] === "0";
|
||||
$this->isDev = '0' === $_ENV['VITE_LOAD'];
|
||||
}
|
||||
|
||||
/** @return list<TwigFunction> */
|
||||
@@ -29,7 +29,7 @@ class ViteAssetExtension extends AbstractExtension
|
||||
return [
|
||||
new TwigFunction('vite_asset', $this->asset(...), ['is_safe' => ['html']]),
|
||||
new TwigFunction('isMobile', $this->isMobile(...), ['is_safe' => ['html']]),
|
||||
new TwigFunction('vite_favicons', $this->favicons(...), ['is_safe' => ['html']])
|
||||
new TwigFunction('vite_favicons', $this->favicons(...), ['is_safe' => ['html']]),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -41,21 +41,23 @@ class ViteAssetExtension extends AbstractExtension
|
||||
public function isMobile(): bool
|
||||
{
|
||||
$detect = new MobileDetect();
|
||||
|
||||
return $detect->isMobile() || $detect->isTablet();
|
||||
}
|
||||
|
||||
private function loadManifest(): void
|
||||
{
|
||||
if ($this->manifestData === null) {
|
||||
if (null === $this->manifestData) {
|
||||
$item = $this->cache->getItem(self::CACHE_KEY);
|
||||
if ($item->isHit()) {
|
||||
$this->manifestData = $item->get();
|
||||
} else {
|
||||
if (!file_exists($this->manifest)) {
|
||||
$this->manifestData = [];
|
||||
|
||||
return;
|
||||
}
|
||||
$this->manifestData = json_decode((string)file_get_contents($this->manifest), true);
|
||||
$this->manifestData = json_decode((string) file_get_contents($this->manifest), true);
|
||||
$item->set($this->manifestData);
|
||||
$this->cache->save($item);
|
||||
}
|
||||
@@ -76,6 +78,7 @@ class ViteAssetExtension extends AbstractExtension
|
||||
public function assetDev(string $entry, array $deps): string
|
||||
{
|
||||
$nonce = $this->getNonce();
|
||||
|
||||
return <<<HTML
|
||||
<script type="module" src="http://localhost:5173/assets/@vite/client" nonce="{$nonce}"></script>
|
||||
<script type="module" src="http://localhost:5173/assets/{$entry}" nonce="{$nonce}" defer></script>
|
||||
@@ -109,12 +112,13 @@ HTML;
|
||||
private function faviconsProd(): string
|
||||
{
|
||||
$this->loadManifest();
|
||||
$faviconHtml = "";
|
||||
$faviconHtml = '';
|
||||
foreach ($this->manifestData as $key => $favicon) {
|
||||
if(!str_contains($key, ".js") && isset($favicon['file'])) {
|
||||
if (!str_contains($key, '.js') && isset($favicon['file'])) {
|
||||
$faviconHtml .= '<link rel="icon" href="/build/'.$favicon['file'].'" type="image/x-icon">';
|
||||
}
|
||||
}
|
||||
|
||||
return $faviconHtml;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user