Completed
Push — master ( a081fe...17409b )
by Alexei
8s
created

Dns   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 29.69 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 4
dl 19
loc 64
rs 10

4 Methods

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