ProtectedDirectory::getAll()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 9
Ratio 90 %

Importance

Changes 0
Metric Value
dl 9
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
// Copyright 1999-2021. Plesk International GmbH.
3
4
namespace PleskX\Api\Operator;
5
6
use PleskX\Api\Struct\ProtectedDirectory as Struct;
7
8
class ProtectedDirectory extends \PleskX\Api\Operator
9
{
10
    protected $_wrapperTag = 'protected-dir';
11
12
    /**
13
     * @param string $name
14
     * @param int $siteId
15
     * @param string $header
16
     *
17
     * @return Struct\Info
18
     */
19 View Code Duplication
    public function add($name, $siteId, $header = '')
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...
20
    {
21
        $packet = $this->_client->getPacket();
22
        $info = $packet->addChild($this->_wrapperTag)->addChild('add');
23
24
        $info->addChild('site-id', $siteId);
25
        $info->addChild('name', $name);
26
        $info->addChild('header', $header);
27
28
        return new Struct\Info($this->_client->request($packet));
29
    }
30
31
    /**
32
     * @param string $field
33
     * @param int|string $value
34
     *
35
     * @return bool
36
     */
37
    public function delete($field, $value)
38
    {
39
        return $this->_delete($field, $value, 'delete');
40
    }
41
42
    /**
43
     * @param string $field
44
     * @param int|string $value
45
     *
46
     * @return Struct\DataInfo|false
47
     */
48
    public function get($field, $value)
49
    {
50
        $items = $this->getAll($field, $value);
51
52
        return reset($items);
53
    }
54
55
    /**
56
     * @param string $field
57
     * @param int|string $value
58
     *
59
     * @return Struct\DataInfo[]
60
     */
61 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...
62
    {
63
        $response = $this->_get('get', $field, $value);
64
        $items = [];
65
        foreach ($response->xpath('//result/data') as $xmlResult) {
66
            $items[] = new Struct\DataInfo($xmlResult);
67
        }
68
69
        return $items;
70
    }
71
72
    /**
73
     * @param Struct\Info $protectedDirectory
74
     * @param string $login
75
     * @param string $password
76
     *
77
     * @return Struct\UserInfo
78
     */
79 View Code Duplication
    public function addUser($protectedDirectory, $login, $password)
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...
80
    {
81
        $packet = $this->_client->getPacket();
82
        $info = $packet->addChild($this->_wrapperTag)->addChild('add-user');
83
84
        $info->addChild('pd-id', $protectedDirectory->id);
85
        $info->addChild('login', $login);
86
        $info->addChild('password', $password);
87
88
        return new Struct\UserInfo($this->_client->request($packet));
89
    }
90
91
    /**
92
     * @param string $field
93
     * @param int|string $value
94
     *
95
     * @return bool
96
     */
97
    public function deleteUser($field, $value)
98
    {
99
        return $this->_delete($field, $value, 'delete-user');
100
    }
101
102
    /**
103
     * @param $command
104
     * @param $field
105
     * @param $value
106
     *
107
     * @return \PleskX\Api\XmlResponse
108
     */
109 View Code Duplication
    private function _get($command, $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...
110
    {
111
        $packet = $this->_client->getPacket();
112
        $getTag = $packet->addChild($this->_wrapperTag)->addChild($command);
113
114
        $filterTag = $getTag->addChild('filter');
115
        if (!is_null($field)) {
116
            $filterTag->addChild($field, $value);
117
        }
118
119
        $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
120
121
        return $response;
122
    }
123
}
124