Completed
Push — master ( 78753a...e3712f )
by
unknown
11s
created

DnsTemplate   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 74
Duplicated Lines 56.76 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 42
loc 74
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 12 12 2
A get() 0 5 1
A getAll() 20 20 3
A delete() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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