mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
refactor: create StatService
This commit is contained in:
26
src/Service/StatService.php
Normal file
26
src/Service/StatService.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user