NeighbourhoodRepository   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 20
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A findByLatlng() 0 13 1
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\Neighbourhood;
6
use LongitudeOne\Spatial\PHP\Types\Geometry\Point;
7
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
8
use Doctrine\Persistence\ManagerRegistry;
9
10
/**
11
 * @method Neighbourhood|null find($id, $lockMode = null, $lockVersion = null)
12
 * @method Neighbourhood|null findOneBy(array $criteria, array $orderBy = null)
13
 * @method Neighbourhood[]    findAll()
14
 * @method Neighbourhood[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
15
 */
16
class NeighbourhoodRepository extends ServiceEntityRepository
17
{
18
    public function __construct(ManagerRegistry $registry)
19
    {
20
        parent::__construct($registry, Neighbourhood::class);
21
    }
22
23
    public function findByLatlng(float $lat, float $lng): ?Neighbourhood
24
    {
25
        $point = new Point($lng, $lat);
26
        $queryBuilder = $this->createQueryBuilder('n');
27
28
        /** @var ?Neighbourhood $result */
29
        $result = $queryBuilder
30
            ->andWhere("st_contains(n.boundingPolygon, :p) = true")
31
            ->setParameter('p', $point, 'point')
32
            ->setMaxResults(1)
33
            ->getQuery()
34
            ->getOneOrNullResult();
35
        return $result;
36
    }
37
38
    // /**
39
    //  * @return Neighbourhood[] Returns an array of Neighbourhood objects
40
    //  */
41
    /*
42
    public function findByExampleField($value)
43
    {
44
        return $this->createQueryBuilder('n')
45
            ->andWhere('n.exampleField = :val')
46
            ->setParameter('val', $value)
47
            ->orderBy('n.id', 'ASC')
48
            ->setMaxResults(10)
49
            ->getQuery()
50
            ->getResult()
51
        ;
52
    }
53
    */
54
55
    /*
56
    public function findOneBySomeField($value): ?Neighbourhood
57
    {
58
        return $this->createQueryBuilder('n')
59
            ->andWhere('n.exampleField = :val')
60
            ->setParameter('val', $value)
61
            ->getQuery()
62
            ->getOneOrNullResult()
63
        ;
64
    }
65
    */
66
}
67