Completed
Push — master ( b2c37d...136e36 )
by Nicolas
02:36
created

GeoPolygon::count()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Elastica\Query;
3
4
/**
5
 * Geo polygon query.
6
 *
7
 * @author Michael Maclean <[email protected]>
8
 *
9
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-query.html
10
 */
11
class GeoPolygon extends AbstractQuery
12
{
13
    /**
14
     * Key.
15
     *
16
     * @var string Key
17
     */
18
    protected $_key;
19
20
    /**
21
     * Points making up polygon.
22
     *
23
     * @var array Points making up polygon
24
     */
25
    protected $_points;
26
27
    /**
28
     * Construct polygon query.
29
     *
30
     * @param string $key    Key
31
     * @param array  $points Points making up polygon
32
     */
33
    public function __construct($key, array $points)
34
    {
35
        $this->_key = $key;
36
        $this->_points = $points;
37
    }
38
39
    /**
40
     * Converts query to array.
41
     *
42
     * @see \Elastica\Query\AbstractQuery::toArray()
43
     *
44
     * @return array
45
     */
46
    public function toArray()
47
    {
48
        return [
49
            'geo_polygon' => [
50
                $this->_key => [
51
                    'points' => $this->_points,
52
                ],
53
            ],
54
        ];
55
    }
56
57
    /**
58
     * @inheritdoc
59
     *
60
     * @return int
61
     */
62
    public function count()
63
    {
64
        return count($this->_key);
65
    }
66
67
}
68