Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
28 / 28
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
WaypointRepository
100.00% covered (success)
100.00%
28 / 28
100.00% covered (success)
100.00%
5 / 5
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 findByIds
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 findDetailsByIds
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 findLatLon
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 findInBounds
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace App\Repository;
6
7use App\Entity\Waypoint;
8use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
9use Doctrine\Persistence\ManagerRegistry;
10
11/**
12 * @extends ServiceEntityRepository<Waypoint>
13 */
14class WaypointRepository extends ServiceEntityRepository
15{
16    public function __construct(ManagerRegistry $registry)
17    {
18        parent::__construct($registry, Waypoint::class);
19    }
20
21    /**
22     * @param array<int> $ids
23     *
24     * @return Waypoint[]
25     */
26    public function findByIds(array $ids): array
27    {
28        /** @var Waypoint[] */
29        return $this->createQueryBuilder('w')
30            ->andWhere('w.id IN (:val)')
31            ->setParameter('val', $ids)
32            ->getQuery()
33            ->getResult();
34    }
35
36    /**
37     * @param array<int> $ids
38     *
39     * @return Waypoint[]
40     */
41    public function findDetailsByIds(array $ids): array
42    {
43        /** @var Waypoint[] */
44        return $this->createQueryBuilder('w')
45            ->select('w.id, w.guid, w.name, w.lat, w.lon as lng')
46            ->andWhere('w.id IN (:val)')
47            ->setParameter('val', $ids)
48            ->getQuery()
49            ->getResult();
50    }
51
52    /**
53     * @return list<string>
54     */
55    public function findLatLon(): array
56    {
57        /** @var array<array{lat_lon: string}> $result */
58        $result = $this->createQueryBuilder('w')
59            ->select("CONCAT(w.lat, ',', w.lon) AS lat_lon")
60            ->getQuery()
61            ->getResult();
62
63        return array_column($result, 'lat_lon');
64    }
65
66    /**
67     * 50.140165627475554,
68     * 8.537063598632814,
69     * 49.975734392872745,
70     * 8.02207946777344
71     *
72     * @return Waypoint[]
73     */
74    public function findInBounds(
75        float $latMax,
76        float $lonMax,
77        float $latMin,
78        float $lonMin,
79    ): array
80    {
81        /** @var Waypoint[] */
82        return $this->createQueryBuilder('w')
83            ->andWhere('w.lat >= :latMin')
84            ->andWhere('w.lat <= :latMax')
85            ->andWhere('w.lon >= :lonMin')
86            ->andWhere('w.lon <= :lonMax')
87            ->setParameter('latMin', $latMin)
88            ->setParameter('latMax', $latMax)
89            ->setParameter('lonMin', $lonMin)
90            ->setParameter('lonMax', $lonMax)
91            ->getQuery()
92            ->getResult();
93    }
94}