Completed
Push — master ( 0d45ed...ea3502 )
by Nicolas
02:38
created

src/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
3
namespace Elastica\Index;
4
5
use Elastica\Index as BaseIndex;
6
use Elastica\Response;
7
8
/**
9
 * Elastica index stats object.
10
 *
11
 * @author Nicolas Ruflin <[email protected]>
12
 *
13
 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-stats.html
14
 */
15
class Stats
16
{
17
    /**
18
     * Response.
19
     *
20
     * @var Response Response object
21
     */
22
    protected $_response;
23
24
    /**
25
     * Stats info.
26
     *
27
     * @var array Stats info
28
     */
29
    protected $_data = [];
30
31
    /**
32
     * Index.
33
     *
34
     * @var BaseIndex Index object
35
     */
36
    protected $_index;
37
38
    /**
39
     * Construct.
40
     *
41
     * @param BaseIndex $index Index object
42
     */
43
    public function __construct(BaseIndex $index)
44
    {
45
        $this->_index = $index;
46
        $this->refresh();
47
    }
48
49
    /**
50
     * Returns the raw stats info.
51
     *
52
     * @return array Stats info
53
     */
54
    public function getData(): array
55
    {
56
        return $this->_data;
57
    }
58
59
    /**
60
     * Returns the entry in the data array based on the params.
61
     * Various params possible.
62
     *
63
     * @return mixed Data array entry or null if not found
64
     */
65 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...
66
    {
67
        $data = $this->getData();
68
69
        foreach (\func_get_args() as $arg) {
70
            if (isset($data[$arg])) {
71
                $data = $data[$arg];
72
            } else {
73
                return null;
74
            }
75
        }
76
77
        return $data;
78
    }
79
80
    /**
81
     * Returns the index object.
82
     *
83
     * @return BaseIndex Index object
84
     */
85
    public function getIndex(): BaseIndex
86
    {
87
        return $this->_index;
88
    }
89
90
    /**
91
     * Returns response object.
92
     *
93
     * @return Response Response object
94
     */
95
    public function getResponse(): Response
96
    {
97
        return $this->_response;
98
    }
99
100
    /**
101
     * Reloads all status data of this object.
102
     */
103
    public function refresh(): void
104
    {
105
        $this->_response = $this->getIndex()->requestEndpoint(new \Elasticsearch\Endpoints\Indices\Stats());
106
        $this->_data = $this->getResponse()->getData();
107
    }
108
}
109