Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| CounterRepository | |
0.00% |
0 / 17 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| recordVisit | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| recordLatency | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getCounter | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Repository; |
| 4 | |
| 5 | use Olz\Entity\Counter; |
| 6 | use Olz\Repository\Common\OlzRepository; |
| 7 | |
| 8 | /** |
| 9 | * @extends OlzRepository<Counter> |
| 10 | */ |
| 11 | class CounterRepository extends OlzRepository { |
| 12 | public function recordVisit(string $page): void { |
| 13 | $counter = $this->getCounter($page); |
| 14 | $counter->incrementCounter(); |
| 15 | $this->getEntityManager()->flush(); |
| 16 | } |
| 17 | |
| 18 | public function recordLatency(string $page, float $latency_ms): void { |
| 19 | $counter = $this->getCounter($page); |
| 20 | $counter->addLatencyMeasurment($latency_ms); |
| 21 | $this->getEntityManager()->flush(); |
| 22 | } |
| 23 | |
| 24 | public function getCounter(string $page): Counter { |
| 25 | $date_range = $this->dateUtils()->getCurrentDateInFormat('Y-m'); |
| 26 | $counter = $this->findOneBy(['page' => $page, 'date_range' => $date_range]); |
| 27 | if (!$counter) { |
| 28 | $counter = new Counter(); |
| 29 | $counter->setPage($page); |
| 30 | $counter->setDateRange($date_range); |
| 31 | $counter->setCounter(0); |
| 32 | $counter->setLatencyAvgMs(0); |
| 33 | $counter->setLatencyNum(0); |
| 34 | $this->getEntityManager()->persist($counter); |
| 35 | } |
| 36 | return $counter; |
| 37 | } |
| 38 | } |