Lines 100.00% 14 / 14
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 import 100.00% 13 / 13 100.00% 1 / 1 3
14readonly class Importer
15{
16    public function __construct(
17        private CityRepository $cityRepository,
18    ) {
19    }
20
21    public function import(CityDTO $cityDTO): void
22    {
23        $city = $this->cityRepository->findByName($cityDTO->name);
24        if ($city !== null) {
25            $city->removeAllDistricts();
26            $this->cityRepository->update($city);
27        } else {
28            $city = new City($cityDTO->name);
29            $this->cityRepository->add($city);
30        }
31        foreach ($cityDTO->districts as $districtDTO) {
32            $city->addDistrict(
33                new Name($districtDTO->name),
34                new Area($districtDTO->area),
35                new Population($districtDTO->population),
36            );
37        }
38        $this->cityRepository->update($city);
39    }
40}