Reseller::getAll()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 9.52
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\Reseller as Struct;
7
8
class Reseller extends \PleskX\Api\Operator
9
{
10
    /**
11
     * @param array $properties
12
     *
13
     * @return Struct\Info
14
     */
15 View Code Duplication
    public function create($properties)
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...
16
    {
17
        $packet = $this->_client->getPacket();
18
        $info = $packet->addChild($this->_wrapperTag)->addChild('add')->addChild('gen-info');
19
20
        foreach ($properties as $name => $value) {
21
            $info->addChild($name, $value);
22
        }
23
24
        $response = $this->_client->request($packet);
25
26
        return new Struct\Info($response);
27
    }
28
29
    /**
30
     * @param string $field
31
     * @param int|string $value
32
     *
33
     * @return bool
34
     */
35
    public function delete($field, $value)
36
    {
37
        return $this->_delete($field, $value);
38
    }
39
40
    /**
41
     * @param string $field
42
     * @param int|string $value
43
     *
44
     * @return Struct\GeneralInfo
45
     */
46
    public function get($field, $value)
47
    {
48
        $items = $this->getAll($field, $value);
49
50
        return reset($items);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression reset($items); of type PleskX\Api\Struct\Reseller\GeneralInfo|false adds false to the return on line 50 which is incompatible with the return type documented by PleskX\Api\Operator\Reseller::get of type PleskX\Api\Struct\Reseller\GeneralInfo. It seems like you forgot to handle an error condition.
Loading history...
51
    }
52
53
    /**
54
     * @param string $field
55
     * @param int|string $value
56
     *
57
     * @return Struct\GeneralInfo[]
58
     */
59
    public function getAll($field = null, $value = null)
60
    {
61
        $packet = $this->_client->getPacket();
62
        $getTag = $packet->addChild($this->_wrapperTag)->addChild('get');
63
64
        $filterTag = $getTag->addChild('filter');
65
        if (!is_null($field)) {
66
            $filterTag->addChild($field, $value);
67
        }
68
69
        $datasetTag = $getTag->addChild('dataset');
70
        $datasetTag->addChild('gen-info');
71
        $datasetTag->addChild('permissions');
72
73
        $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
74
75
        $items = [];
76
        foreach ($response->xpath('//result') as $xmlResult) {
77
            $item = new Struct\GeneralInfo($xmlResult->data);
78
            $item->id = (int) $xmlResult->id;
79
            $items[] = $item;
80
        }
81
82
        return $items;
83
    }
84
}
85