ServicePlan::getAll()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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