Geo   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 78
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A geoPolygon() 0 14 3
A geoShape() 0 3 1
A geoDistance() 0 8 1
A geoBoundingBox() 0 14 3
1
<?php
2
namespace Triadev\Es\Dsl\Dsl\Query;
3
4
use ONGR\ElasticsearchDSL\Query\Geo\GeoBoundingBoxQuery;
5
use ONGR\ElasticsearchDSL\Query\Geo\GeoDistanceQuery;
6
use ONGR\ElasticsearchDSL\Query\Geo\GeoPolygonQuery;
7
use ONGR\ElasticsearchDSL\Query\Geo\GeoShapeQuery;
8
use Triadev\Es\Dsl\Dsl\AbstractDsl;
9
use Triadev\Es\Dsl\Model\Location;
10
11
class Geo extends AbstractDsl
12
{
13
    /**
14
     * Geo bounding box
15
     *
16
     * @param string $field
17
     * @param Location[] $locations
18
     * @param array $params
19
     * @return Geo
20
     */
21 1
    public function geoBoundingBox(string $field, array $locations, array $params = []): Geo
22
    {
23 1
        $l = [];
24
        
25 1
        foreach ($locations as $location) {
26 1
            if ($location instanceof Location) {
27 1
                $l[] = [
28 1
                    'lat' => $location->getLatitude(),
29 1
                    'lon' => $location->getLongitude()
30
                ];
31
            }
32
        }
33
        
34 1
        return $this->append(new GeoBoundingBoxQuery($field, $l, $params));
35
    }
36
    
37
    /**
38
     * Geo distance
39
     *
40
     * @param string $field
41
     * @param string $distance
42
     * @param Location $location
43
     * @return Geo
44
     */
45 1
    public function geoDistance(string $field, string $distance, Location $location): Geo
46
    {
47 1
        return $this->append(new GeoDistanceQuery(
48 1
            $field,
49 1
            $distance,
50
            [
51 1
                'lat' => $location->getLatitude(),
52 1
                'lon' => $location->getLongitude()
53
            ]
54
        ));
55
    }
56
    
57
    /**
58
     * Geo polygon
59
     *
60
     * @param string $field
61
     * @param Location[] $points
62
     * @return Geo
63
     */
64 1
    public function geoPolygon(string $field, array $points): Geo
65
    {
66 1
        $p = [];
67
        
68 1
        foreach ($points as $point) {
69 1
            if ($point instanceof Location) {
70 1
                $p[] = [
71 1
                    'lat' => $point->getLatitude(),
72 1
                    'lon' => $point->getLongitude()
73
                ];
74
            }
75
        }
76
        
77 1
        return $this->append(new GeoPolygonQuery($field, $p));
78
    }
79
    
80
    /**
81
     * Geo shape
82
     *
83
     * @param array $params
84
     * @return Geo
85
     */
86 1
    public function geoShape(array $params = []): Geo
87
    {
88 1
        return $this->append(new GeoShapeQuery($params));
89
    }
90
}
91