Completed
Pull Request — master (#39)
by
unknown
15:42
created

DnsTemplate::getAll()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 20
Code Lines 14

Duplication

Lines 20
Ratio 100 %

Importance

Changes 0
Metric Value
dl 20
loc 20
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 14
nc 4
nop 2
1
<?php
2
// Copyright 1999-2018. Plesk International GmbH.
3
namespace PleskX\Api\Operator;
4
use PleskX\Api\Struct\Dns as Struct;
5
6
class DnsTemplate extends \PleskX\Api\Operator
7
{
8
    protected $_wrapperTag = 'dns';
9
10
    /**
11
     * @param array $properties
12
     * @return Struct\Info
13
     */
14 View Code Duplication
    public function create(array $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...
15
    {
16
        $packet = $this->_client->getPacket();
17
        $info = $packet->addChild($this->_wrapperTag)->addChild('add_rec');
18
19
        unset($properties['site-id'], $properties['site-alias-id']);
20
        foreach ($properties as $name => $value) {
21
            $info->addChild($name, $value);
22
        }
23
24
        return new Struct\Info($this->_client->request($packet));
25
    }
26
27
    /**
28
     * @param string $field
29
     * @param integer|string $value
30
     * @return Struct\Info|null
31
     */
32
    public function get($field, $value)
33
    {
34
        $items = $this->getAll($field, $value);
35
        return reset($items);
36
    }
37
38
    /**
39
     * @param string $field
40
     * @param integer|string $value
41
     * @return Struct\Info[]
42
     */
43 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...
44
    {
45
        $packet = $this->_client->getPacket();
46
        $getTag = $packet->addChild($this->_wrapperTag)->addChild('get_rec');
47
48
        $filterTag = $getTag->addChild('filter');
49
        if (!is_null($field)) {
50
            $filterTag->addChild($field, $value);
51
        }
52
        $getTag->addChild('template');
53
54
        $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
55
        $items = [];
56
        foreach ($response->xpath('//result') as $xmlResult) {
57
            $item = new Struct\Info($xmlResult->data);
58
            $item->id = (int)$xmlResult->id;
59
            $items[] = $item;
60
        }
61
        return $items;
62
    }
63
64
    /**
65
     * @param string $field
66
     * @param integer|string $value
67
     * @return bool
68
     */
69 View Code Duplication
    public function delete($field, $value)
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...
70
    {
71
        $packet = $this->_client->getPacket();
72
        $delTag = $packet->addChild($this->_wrapperTag)->addChild('del_rec');
73
        $delTag->addChild('filter')->addChild($field, $value);
74
        $delTag->addChild('template');
75
76
        $response = $this->_client->request($packet);
77
        return 'ok' === (string)$response->status;
78
    }
79
}
80