fix: SonarQube ActionService - $mailer supprime, constante, log 9->6 params
- Suppression champ $mailer inutilise - REASON_PAYMENT_RECEIVED constante (3 occurrences) - log() : 9 params -> 6 via array $extra (previous, new, entityId, entityType) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -10,17 +10,18 @@ use App\Entity\Website;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Service centralise pour les actions destructrices et critiques.
|
||||
* Chaque action est loggee de facon exhaustive (ActionLog + Psr\Log).
|
||||
*/
|
||||
class ActionService
|
||||
{
|
||||
private const REASON_PAYMENT_RECEIVED = 'Paiement recu';
|
||||
|
||||
public function __construct(
|
||||
private EntityManagerInterface $em,
|
||||
private LoggerInterface $logger,
|
||||
/** @phpstan-ignore-next-line */
|
||||
private MailerService $mailer,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -41,7 +42,7 @@ class ActionService
|
||||
|
||||
$this->log(ActionLog::ACTION_SUSPEND_CUSTOMER, $customer,
|
||||
'Debut suspension client '.$customer->getFullName().' ('.$customer->getEmail().') - Raison: '.$reason,
|
||||
'critical', true, $previousState, Customer::STATE_SUSPENDED
|
||||
'critical', true, ['previous' => $previousState, 'new' => Customer::STATE_SUSPENDED]
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -84,7 +85,7 @@ class ActionService
|
||||
/**
|
||||
* Retablit un client suspendu : reactive le compte + reactive les sites + reactive les emails.
|
||||
*/
|
||||
public function unsuspendCustomer(Customer $customer, string $reason = 'Paiement recu'): bool
|
||||
public function unsuspendCustomer(Customer $customer, string $reason = self::REASON_PAYMENT_RECEIVED): bool
|
||||
{
|
||||
$previousState = $customer->getState();
|
||||
|
||||
@@ -96,7 +97,7 @@ class ActionService
|
||||
|
||||
$this->log(ActionLog::ACTION_UNSUSPEND_CUSTOMER, $customer,
|
||||
'Debut retablissement client '.$customer->getFullName().' - Raison: '.$reason,
|
||||
'info', true, $previousState, Customer::STATE_ACTIVE
|
||||
'info', true, ['previous' => $previousState, 'new' => Customer::STATE_ACTIVE]
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -144,12 +145,11 @@ class ActionService
|
||||
|
||||
$this->log(ActionLog::ACTION_SUSPEND_WEBSITE, $customer,
|
||||
'Site '.$website->getName().' (UUID '.$website->getUuid().') suspendu - Raison: '.$reason,
|
||||
'critical', true, $prev, Website::STATE_SUSPENDED,
|
||||
$website->getId(), 'Website'
|
||||
'critical', true, ['previous' => $prev, 'new' => Website::STATE_SUSPENDED, 'entityId' => $website->getId(), 'entityType' => 'Website']
|
||||
);
|
||||
}
|
||||
|
||||
public function unsuspendWebsite(Website $website, Customer $customer, string $reason = 'Paiement recu'): void
|
||||
public function unsuspendWebsite(Website $website, Customer $customer, string $reason = self::REASON_PAYMENT_RECEIVED): void
|
||||
{
|
||||
$prev = $website->getState();
|
||||
$website->setState(Website::STATE_OPEN);
|
||||
@@ -157,8 +157,7 @@ class ActionService
|
||||
|
||||
$this->log(ActionLog::ACTION_UNSUSPEND_WEBSITE, $customer,
|
||||
'Site '.$website->getName().' retabli - Raison: '.$reason,
|
||||
'info', true, $prev, Website::STATE_OPEN,
|
||||
$website->getId(), 'Website'
|
||||
'info', true, ['previous' => $prev, 'new' => Website::STATE_OPEN, 'entityId' => $website->getId(), 'entityType' => 'Website']
|
||||
);
|
||||
}
|
||||
|
||||
@@ -176,12 +175,11 @@ class ActionService
|
||||
|
||||
$this->log(ActionLog::ACTION_SUSPEND_DOMAIN_EMAIL, $customer,
|
||||
'Email '.$email->getFullEmail().' suspendu - Raison: '.$reason,
|
||||
'critical', true, $prev, 'suspended',
|
||||
$email->getId(), 'DomainEmail'
|
||||
'critical', true, ['previous' => $prev, 'new' => 'suspended', 'entityId' => $email->getId(), 'entityType' => 'DomainEmail']
|
||||
);
|
||||
}
|
||||
|
||||
public function unsuspendDomainEmail(DomainEmail $email, Customer $customer, string $reason = 'Paiement recu'): void
|
||||
public function unsuspendDomainEmail(DomainEmail $email, Customer $customer, string $reason = self::REASON_PAYMENT_RECEIVED): void
|
||||
{
|
||||
$prev = $email->getState();
|
||||
$email->setState('active');
|
||||
@@ -189,8 +187,7 @@ class ActionService
|
||||
|
||||
$this->log(ActionLog::ACTION_UNSUSPEND_DOMAIN_EMAIL, $customer,
|
||||
'Email '.$email->getFullEmail().' retabli - Raison: '.$reason,
|
||||
'info', true, $prev, 'active',
|
||||
$email->getId(), 'DomainEmail'
|
||||
'info', true, ['previous' => $prev, 'new' => 'active', 'entityId' => $email->getId(), 'entityType' => 'DomainEmail']
|
||||
);
|
||||
}
|
||||
|
||||
@@ -205,7 +202,7 @@ class ActionService
|
||||
|
||||
$this->log(ActionLog::ACTION_DISABLE_CUSTOMER, $customer,
|
||||
'Desactivation definitive '.$customer->getFullName().' - Raison: '.$reason,
|
||||
'critical', true, $previousState, Customer::STATE_DISABLED
|
||||
'critical', true, ['previous' => $previousState, 'new' => Customer::STATE_DISABLED]
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -229,7 +226,7 @@ class ActionService
|
||||
|
||||
$this->log(ActionLog::ACTION_DELETE_CUSTOMER_DATA, $customer,
|
||||
'Marquage suppression client '.$customer->getFullName().' ('.$customer->getEmail().') - Raison: '.$reason.' - Toutes les donnees seront supprimees par le cron nocturne.',
|
||||
'critical', true, $previousState, Customer::STATE_PENDING_DELETE,
|
||||
'critical', true, ['previous' => $previousState, 'new' => Customer::STATE_PENDING_DELETE]
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -248,17 +245,22 @@ class ActionService
|
||||
|
||||
// ──────── Logging ────────
|
||||
|
||||
/**
|
||||
* @param array{previous?: ?string, new?: ?string, entityId?: ?int, entityType?: ?string} $extra
|
||||
*/
|
||||
private function log(
|
||||
string $action,
|
||||
Customer $customer,
|
||||
string $message,
|
||||
string $severity = 'info',
|
||||
bool $success = true,
|
||||
?string $previousState = null,
|
||||
?string $newState = null,
|
||||
?int $entityId = null,
|
||||
?string $entityType = null,
|
||||
array $extra = [],
|
||||
): void {
|
||||
$previousState = $extra['previous'] ?? null;
|
||||
$newState = $extra['new'] ?? null;
|
||||
$entityId = $extra['entityId'] ?? null;
|
||||
$entityType = $extra['entityType'] ?? null;
|
||||
|
||||
$log = new ActionLog($action, $message, $severity, $success);
|
||||
$log->setCustomer($customer);
|
||||
$log->setPreviousState($previousState);
|
||||
|
||||
Reference in New Issue
Block a user