Completed
Push — master ( b4a464...107c9c )
by Alexei
01:52
created

ServicePlan::_get()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 19
Code Lines 11

Duplication

Lines 19
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 19
loc 19
rs 9.4285
cc 3
eloc 11
nc 4
nop 2
1
<?php
2
// Copyright 1999-2016. Parallels IP Holdings GmbH.
3
4
namespace PleskX\Api\Operator;
5
use PleskX\Api\Struct\ServicePlan as Struct;
6
7
8
class ServicePlan extends \PleskX\Api\Operator
9
{
10
11
    /**
12
     * @param string $field
13
     * @param integer|string $value
14
     * @return Struct\Info
15
     */
16
    public function get($field, $value)
17
    {
18
        $customers = $this->_get($field, $value);
19
        return reset($customers);
20
    }
21
22
    /**
23
     * @return Struct\Info[]
24
     */
25
    public function getAll()
26
    {
27
        return $this->_get();
28
    }
29
30
    /**
31
     * @param string|null $field
32
     * @param integer|string|null $value
33
     * @return Struct\Info|Struct\Info[]
34
     */
35 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...
36
    {
37
        $packet = $this->_client->getPacket();
38
        $getTag = $packet->addChild('service-plan')->addChild('get');
39
40
        $filterTag = $getTag->addChild('filter');
41
        if (!is_null($field)) {
42
            $filterTag->addChild($field, $value);
43
        }
44
45
        $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
46
47
        $items = [];
48
        foreach ($response->xpath('//result') as $xmlResult) {
49
            $items[] = new Struct\Info($xmlResult);
50
        }
51
52
        return $items;
53
    }
54
55
}
56