Completed
Push — master ( 8de7c5...dccaf5 )
by Alexei
01:59
created

Customer::find()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 10
nc 2
nop 0
1
<?php
2
// Copyright 1999-2016. Parallels IP Holdings GmbH.
3
4
namespace PleskX\Api\Operator;
5
use PleskX\Api\Struct\Customer as Struct;
6
7
class Customer extends \PleskX\Api\Operator
8
{
9
10
    /**
11
     * @param array $properties
12
     * @return Struct\Info
13
     */
14
    public function create($properties)
15
    {
16
        $packet = $this->_client->getPacket();
17
        $info = $packet->addChild('customer')->addChild('add')->addChild('gen_info');
18
19
        foreach ($properties as $name => $value) {
20
            $info->addChild($name, $value);
21
        }
22
23
        $response = $this->_client->request($packet);
24
        return new Struct\Info($response);
25
    }
26
27
    /**
28
     * @param string $field
29
     * @param integer|string $value
30
     * @return bool
31
     */
32
    public function delete($field, $value)
33
    {
34
        $packet = $this->_client->getPacket();
35
        $packet->addChild('customer')->addChild('del')->addChild('filter')->addChild($field, $value);
36
        $response = $this->_client->request($packet);
37
        return 'ok' === (string)$response->status;
38
    }
39
40
    /**
41
     * @param string $field
42
     * @param integer|string $value
43
     * @return Struct\GeneralInfo
44
     */
45
    public function get($field, $value)
46
    {
47
        $packet = $this->_client->getPacket();
48
        $getTag = $packet->addChild('customer')->addChild('get');
49
        $getTag->addChild('filter')->addChild($field, $value);
50
        $getTag->addChild('dataset')->addChild('gen_info');
51
        $response = $this->_client->request($packet);
52
        return new Struct\GeneralInfo($response->data->gen_info);
53
    }
54
55
    /**
56
     * @return Struct\GeneralInfo[]
57
     */
58
    public function find()
59
    {
60
        $packet = $this->_client->getPacket();
61
        $getTag = $packet->addChild('customer')->addChild('get');
62
        $getTag->addChild('filter');
63
        $getTag->addChild('dataset')->addChild('gen_info');
64
        $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
65
66
        $customers = [];
67
        foreach ($response->xpath('//result') as $xmlResult) {
68
            $customers[] = new Struct\GeneralInfo($xmlResult->data->gen_info);
69
        }
70
71
        return $customers;
72
    }
73
74
}
75