Completed
Push — master ( 4cdb71...eee063 )
by Nicolas
02:28
created

lib/Elastica/Index/Stats.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Elastica\Index;
3
4
use Elastica\Index as BaseIndex;
5
6
/**
7
 * Elastica index stats object.
8
 *
9
 * @author Nicolas Ruflin <[email protected]>
10
 *
11
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-stats.html
12
 */
13
class Stats
14
{
15
    /**
16
     * Response.
17
     *
18
     * @var \Elastica\Response Response object
19
     */
20
    protected $_response;
21
22
    /**
23
     * Stats info.
24
     *
25
     * @var array Stats info
26
     */
27
    protected $_data = [];
28
29
    /**
30
     * Index.
31
     *
32
     * @var \Elastica\Index Index object
33
     */
34
    protected $_index;
35
36
    /**
37
     * Construct.
38
     *
39
     * @param \Elastica\Index $index Index object
40
     */
41
    public function __construct(BaseIndex $index)
42
    {
43
        $this->_index = $index;
44
        $this->refresh();
45
    }
46
47
    /**
48
     * Returns the raw stats info.
49
     *
50
     * @return array Stats info
51
     */
52
    public function getData()
53
    {
54
        return $this->_data;
55
    }
56
57
    /**
58
     * Returns the entry in the data array based on the params.
59
     * Various params possible.
60
     *
61
     * @return mixed Data array entry or null if not found
62
     */
63 View Code Duplication
    public function get()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        $data = $this->getData();
66
67
        foreach (func_get_args() as $arg) {
68
            if (isset($data[$arg])) {
69
                $data = $data[$arg];
70
            } else {
71
                return;
72
            }
73
        }
74
75
        return $data;
76
    }
77
78
    /**
79
     * Returns the index object.
80
     *
81
     * @return \Elastica\Index Index object
82
     */
83
    public function getIndex()
84
    {
85
        return $this->_index;
86
    }
87
88
    /**
89
     * Returns response object.
90
     *
91
     * @return \Elastica\Response Response object
92
     */
93
    public function getResponse()
94
    {
95
        return $this->_response;
96
    }
97
98
    /**
99
     * Reloads all status data of this object.
100
     */
101
    public function refresh()
102
    {
103
        $this->_response = $this->getIndex()->requestEndpoint(new \Elasticsearch\Endpoints\Indices\Stats());
104
        $this->_data = $this->getResponse()->getData();
105
    }
106
}
107