Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ThrottlingRepository | |
0.00% |
0 / 12 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| getLastOccurrenceOf | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| recordOccurrenceOf | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Repository; |
| 4 | |
| 5 | use Olz\Entity\Throttling; |
| 6 | use Olz\Repository\Common\OlzRepository; |
| 7 | |
| 8 | /** |
| 9 | * @extends OlzRepository<Throttling> |
| 10 | */ |
| 11 | class ThrottlingRepository extends OlzRepository { |
| 12 | public function getLastOccurrenceOf(string $event_name): ?\DateTime { |
| 13 | $throttling = $this->findOneBy(['event_name' => $event_name]); |
| 14 | if (!$throttling) { |
| 15 | return null; |
| 16 | } |
| 17 | return $throttling->getLastOccurrence(); |
| 18 | } |
| 19 | |
| 20 | public function recordOccurrenceOf(string $event_name, \DateTime|string $datetime): void { |
| 21 | $throttling = $this->findOneBy(['event_name' => $event_name]); |
| 22 | if (!$throttling) { |
| 23 | $throttling = new Throttling(); |
| 24 | $throttling->setEventName($event_name); |
| 25 | $this->entityManager()->persist($throttling); |
| 26 | } |
| 27 | $sane_datetime = is_string($datetime) ? new \DateTime($datetime) : $datetime; |
| 28 | $throttling->setLastOccurrence($sane_datetime); |
| 29 | $this->entityManager()->flush(); |
| 30 | } |
| 31 | } |