Completed
Pull Request — master (#74)
by
unknown
01:37
created

ServicePlan   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 39.44 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 5 1
A getAll() 0 4 1
A _get() 19 19 3
A create() 9 9 1
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-2019. Plesk International GmbH.
3
4
namespace PleskX\Api\Operator;
5
use PleskX\Api\Struct\ServicePlan as Struct;
6
7
8
class ServicePlan extends \PleskX\Api\Operator
9
{
10
11
    /**
12
     * @param string $field
13
     * @param integer|string $value
14
     * @return Struct\Info
15
     */
16
    public function get($field, $value)
17
    {
18
        $items = $this->_get($field, $value);
19
        return reset($items);
20
    }
21
22
    /**
23
     * @return Struct\Info[]
24
     */
25
    public function getAll()
26
    {
27
        return $this->_get();
28
    }
29
30
    /**
31
     * @param string|null $field
32
     * @param integer|string|null $value
33
     * @return Struct\Info|Struct\Info[]
34
     */
35 View Code Duplication
    private function _get($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...
36
    {
37
        $packet = $this->_client->getPacket();
38
        $getTag = $packet->addChild($this->_wrapperTag)->addChild('get');
39
40
        $filterTag = $getTag->addChild('filter');
41
        if (!is_null($field)) {
42
            $filterTag->addChild($field, $value);
43
        }
44
45
        $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
46
47
        $items = [];
48
        foreach ($response->xpath('//result') as $xmlResult) {
49
            $items[] = new Struct\Info($xmlResult);
50
        }
51
52
        return $items;
53
    }
54
55
    /**
56
     * @param string $planName
57
     * @return Struct\Info
58
     */
59 View Code Duplication
    public function create($planName)
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...
60
    {
61
        $packet = $this->_client->getPacket();
62
        $info = $packet->addChild($this->_wrapperTag)->addChild('add');
63
        $info->addChild('name', $planName);
64
65
        $response = $this->_client->request($packet);
66
        return new Struct\Info($response);
67
    }
68
69
    /**
70
     * @param string $field
71
     * @param integer|string $value
72
     * @return bool
73
     */
74
    public function delete($field, $value)
75
    {
76
        return $this->_delete($field, $value);
77
    }
78
}
79