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\Node; |
||
4 | |||
5 | use Elastica\Node as BaseNode; |
||
6 | |||
7 | /** |
||
8 | * Elastica cluster node object. |
||
9 | * |
||
10 | * @author Nicolas Ruflin <[email protected]> |
||
11 | * |
||
12 | * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-status.html |
||
13 | */ |
||
14 | class Stats |
||
15 | { |
||
16 | /** |
||
17 | * Response. |
||
18 | * |
||
19 | * @var \Elastica\Response Response object |
||
20 | */ |
||
21 | protected $_response; |
||
22 | |||
23 | /** |
||
24 | * Stats data. |
||
25 | * |
||
26 | * @var array stats data |
||
27 | */ |
||
28 | protected $_data = []; |
||
29 | |||
30 | /** |
||
31 | * Node. |
||
32 | * |
||
33 | * @var \Elastica\Node Node object |
||
34 | */ |
||
35 | protected $_node; |
||
36 | |||
37 | /** |
||
38 | * Create new stats for node. |
||
39 | * |
||
40 | * @param \Elastica\Node $node Elastica node object |
||
41 | */ |
||
42 | public function __construct(BaseNode $node) |
||
43 | { |
||
44 | $this->_node = $node; |
||
45 | $this->refresh(); |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Returns all node stats as array based on the arguments. |
||
50 | * |
||
51 | * Several arguments can be use |
||
52 | * get('index', 'test', 'example') |
||
53 | * |
||
54 | * @return array Node stats for the given field or null if not found |
||
55 | */ |
||
56 | View Code Duplication | public function get() |
|
0 ignored issues
–
show
|
|||
57 | { |
||
58 | $data = $this->getData(); |
||
59 | |||
60 | foreach (func_get_args() as $arg) { |
||
61 | if (isset($data[$arg])) { |
||
62 | $data = $data[$arg]; |
||
63 | } else { |
||
64 | return; |
||
65 | } |
||
66 | } |
||
67 | |||
68 | return $data; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Returns all stats data. |
||
73 | * |
||
74 | * @return array Data array |
||
75 | */ |
||
76 | public function getData() |
||
77 | { |
||
78 | return $this->_data; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Returns node object. |
||
83 | * |
||
84 | * @return \Elastica\Node Node object |
||
85 | */ |
||
86 | public function getNode() |
||
87 | { |
||
88 | return $this->_node; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Returns response object. |
||
93 | * |
||
94 | * @return \Elastica\Response Response object |
||
95 | */ |
||
96 | public function getResponse() |
||
97 | { |
||
98 | return $this->_response; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Reloads all nodes information. Has to be called if informations changed. |
||
103 | * |
||
104 | * @return \Elastica\Response Response object |
||
105 | */ |
||
106 | public function refresh() |
||
107 | { |
||
108 | $endpoint = new \Elasticsearch\Endpoints\Cluster\Nodes\Stats(); |
||
109 | $endpoint->setNodeID($this->getNode()->getName()); |
||
110 | |||
111 | $this->_response = $this->getNode()->getClient()->requestEndpoint($endpoint); |
||
112 | $data = $this->getResponse()->getData(); |
||
113 | $this->_data = reset($data['nodes']); |
||
0 ignored issues
–
show
It seems like
reset($data['nodes']) of type * is incompatible with the declared type array of property $_data .
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..
Loading history...
|
|||
114 | } |
||
115 | } |
||
116 |
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.