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

Customer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 68
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 12 2
A delete() 0 7 1
A get() 0 9 1
A find() 0 15 2
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