Lines 100.00% 11 / 11
Methods 100.00% 6 / 6
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 get 100.00% 4 / 4 100.00% 1 / 1 2
 findByName 100.00% 1 / 1 100.00% 1 / 1 1
 list 100.00% 1 / 1 100.00% 1 / 1 1
 add 100.00% 2 / 2 100.00% 1 / 1 1
 update 100.00% 2 / 2 100.00% 1 / 1 1
12final readonly class CityRepository implements CityRepositoryInterface
13{
14    public function __construct(
15        private EntityManager $entityManager,
16    ) {
17    }
18
19    public function get(int $id): City
20    {
21        $city = $this->entityManager->getRepository(City::class)->find($id);
22        if ($city === null) {
23            throw new NotFoundInRepositoryException();
24        }
25        return $city;
26    }
27
28    public function findByName(string $name): ?City
29    {
30        return $this->entityManager->getRepository(City::class)->findOneBy(["name" => $name]);
31    }
32
33    /**
34     * @return City[]
35     */
36    public function list(): array
37    {
38        return $this->entityManager->getRepository(City::class)->findAll();
39    }
40
41    public function add(City $city): void
42    {
43        $this->entityManager->persist($city);
44        $this->entityManager->flush();
45    }
46
47    public function update(City $city): void
48    {
49        $this->entityManager->persist($city);
50        $this->entityManager->flush();
51    }
52}