Skip to content

Commit

Permalink
Merge pull request #1308 from Mopolo/refactor-date-interval-var-isset
Browse files Browse the repository at this point in the history
Refactor de la validation `\DateInterval`
  • Loading branch information
agallou committed Jul 2, 2023
2 parents f7cba70 + 2a1eb9a commit 4289b4f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions sources/AppBundle/Security/ActionThrottling/ActionThrottling.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ public function isActionBlocked($action, $ip = null, $objectId = null)
}

$delay = $limitations[$action]['delay'];
$interval = new \DateInterval($delay);
if (isset($interval) === false) { // Si le delay est invalide alors le dateinterval n'est pas créé et une warning générée mais pas d'exception
throw new \RuntimeException(sprintf('Sorry, I could not understand the delay "%s" for the action "%s"', $delay, $action));

try {
$interval = new \DateInterval($delay);
} catch (\Exception $dateIntervalException) {
throw new \RuntimeException(
sprintf('Sorry, I could not understand the delay "%s" for the action "%s"', $delay, $action),
0,
$dateIntervalException
);
}

$logs = $this->logRepository->getApplicableLogs($action, $ip, $objectId, $interval);

if ($logs['ip'] > $limitations[$action]['limit'] || $logs['object'] > $limitations[$action]['limit']) {
Expand Down

0 comments on commit 4289b4f

Please sign in to comment.