DnsTemplate   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 81
Duplicated Lines 39.51 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

4 Methods

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