Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.86% covered (success)
92.86%
13 / 14
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
MeasurementRepository
92.86% covered (success)
92.86%
13 / 14
66.67% covered (warning)
66.67%
2 / 3
5.01
0.00% covered (danger)
0.00%
0 / 1
 get
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 set
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
2
 remove
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
1<?php
2
3namespace Olz\Repository;
4
5use Olz\Entity\Measurement;
6use Olz\Repository\Common\OlzRepository;
7
8/**
9 * @extends OlzRepository<Measurement>
10 */
11class MeasurementRepository extends OlzRepository {
12    public function get(string $name, ?int $year, ?int $month): ?Measurement {
13        return $this->findOneBy(['name' => $name, 'year' => $year, 'month' => $month]);
14    }
15
16    public function set(string $name, ?int $year, ?int $month, ?float $value, int $version): Measurement {
17        $measurement = $this->get($name, $year, $month);
18        if (!$measurement) {
19            $measurement = new Measurement();
20            $measurement->setName($name);
21            $measurement->setYear($year);
22            $measurement->setMonth($month);
23        }
24        $measurement->setValue($value);
25        $measurement->setVersion($version);
26        $this->getEntityManager()->persist($measurement);
27        return $measurement;
28    }
29
30    public function remove(string $name, ?int $year, ?int $month): void {
31        $measurement = $this->get($name, $year, $month);
32        if ($measurement !== null) {
33            $this->getEntityManager()->remove($measurement);
34        }
35    }
36}