Completed
Push — master ( 1b9a66...a548ab )
by Alexei
10s
created

Subdomain::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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