DatabaseServer::_get()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
cc 3
nc 4
nop 2
1
<?php
2
// Copyright 1999-2021. Plesk International GmbH.
3
4
namespace PleskX\Api\Operator;
5
6
use PleskX\Api\Struct\DatabaseServer as Struct;
7
8
class DatabaseServer extends \PleskX\Api\Operator
9
{
10
    protected $_wrapperTag = 'db_server';
11
12
    /**
13
     * @return array
14
     */
15
    public function getSupportedTypes()
16
    {
17
        $response = $this->request('get-supported-types');
18
19
        return (array) $response->type;
20
    }
21
22
    /**
23
     * @param string $field
24
     * @param int|string $value
25
     *
26
     * @return Struct\Info
27
     */
28
    public function get($field, $value)
29
    {
30
        $items = $this->_get($field, $value);
31
32
        return reset($items);
33
    }
34
35
    /**
36
     * @return Struct\Info[]
37
     */
38
    public function getAll()
39
    {
40
        return $this->_get();
41
    }
42
43
    /**
44
     * @param string|null $field
45
     * @param int|string|null $value
46
     *
47
     * @return Struct\Info|Struct\Info[]
48
     */
49
    private function _get($field = null, $value = null)
50
    {
51
        $packet = $this->_client->getPacket();
52
        $getTag = $packet->addChild($this->_wrapperTag)->addChild('get');
53
54
        $filterTag = $getTag->addChild('filter');
55
        if (!is_null($field)) {
56
            $filterTag->addChild($field, $value);
57
        }
58
59
        $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
60
61
        $items = [];
62
        foreach ($response->xpath('//result') as $xmlResult) {
63
            $item = new Struct\Info($xmlResult->data);
64
            $item->id = (int) $xmlResult->id;
65
            $items[] = $item;
66
        }
67
68
        return $items;
69
    }
70
}
71