refactor: create StatService

This commit is contained in:
Maël Gangloff
2024-08-25 03:31:09 +02:00
parent 4bb3ba7765
commit 0e1658f6fe
4 changed files with 35 additions and 24 deletions

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Service;
use Psr\Cache\CacheItemPoolInterface;
readonly class StatService
{
public function __construct(
private CacheItemPoolInterface $pool
) {
}
public function incrementStat(string $key): bool
{
try {
$item = $this->pool->getItem($key);
$item->set(($item->get() ?? 0) + 1);
return $this->pool->save($item);
} catch (\Throwable) {
}
return false;
}
}