Webspace::create()   B
last analyzed

Complexity

Conditions 6
Paths 12

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.8017
c 0
b 0
f 0
cc 6
nc 12
nop 3
1
<?php
2
// Copyright 1999-2021. Plesk International GmbH.
3
4
namespace PleskX\Api\Operator;
5
6
use PleskX\Api\Struct\Webspace as Struct;
7
8
class Webspace extends \PleskX\Api\Operator
9
{
10
    public function getPermissionDescriptor()
11
    {
12
        $response = $this->request('get-permission-descriptor.filter');
13
14
        return new Struct\PermissionDescriptor($response);
15
    }
16
17
    public function getLimitDescriptor()
18
    {
19
        $response = $this->request('get-limit-descriptor.filter');
20
21
        return new Struct\LimitDescriptor($response);
22
    }
23
24
    public function getPhysicalHostingDescriptor()
25
    {
26
        $response = $this->request('get-physical-hosting-descriptor.filter');
27
28
        return new Struct\PhysicalHostingDescriptor($response);
29
    }
30
31
    /**
32
     * @param string $field
33
     * @param int|string $value
34
     *
35
     * @return Struct\PhpSettings
36
     */
37 View Code Duplication
    public function getPhpSettings($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...
38
    {
39
        $packet = $this->_client->getPacket();
40
        $getTag = $packet->addChild($this->_wrapperTag)->addChild('get');
41
42
        $getTag->addChild('filter')->addChild($field, $value);
43
        $getTag->addChild('dataset')->addChild('php-settings');
44
45
        $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
46
47
        return new Struct\PhpSettings($response);
48
    }
49
50
    /**
51
     * @param string $field
52
     * @param int|string $value
53
     *
54
     * @return Struct\Limits
55
     */
56
    public function getLimits($field, $value)
57
    {
58
        $items = $this->_getItems(Struct\Limits::class, 'limits', $field, $value);
59
60
        return reset($items);
61
    }
62
63
    /**
64
     * @param array $properties
65
     * @param array|null $hostingProperties
66
     * @param $planName
67
     *
68
     * @return Struct\Info
69
     */
70
    public function create(array $properties, array $hostingProperties = null, $planName = null)
71
    {
72
        $packet = $this->_client->getPacket();
73
        $info = $packet->addChild($this->_wrapperTag)->addChild('add');
74
75
        $infoGeneral = $info->addChild('gen_setup');
76
        foreach ($properties as $name => $value) {
77
            $infoGeneral->addChild($name, $value);
78
        }
79
80
        if ($hostingProperties) {
81
            $infoHosting = $info->addChild('hosting')->addChild('vrt_hst');
82
            foreach ($hostingProperties as $name => $value) {
83
                $property = $infoHosting->addChild('property');
84
                $property->addChild('name', $name);
85
                $property->addChild('value', $value);
86
            }
87
88
            if (isset($properties['ip_address'])) {
89
                $infoHosting->addChild('ip_address', $properties['ip_address']);
90
            }
91
        }
92
93
        if ($planName) {
94
            $info->addChild('plan-name', $planName);
95
        }
96
97
        $response = $this->_client->request($packet);
98
99
        return new Struct\Info($response, $properties['name'] ?? '');
100
    }
101
102
    /**
103
     * @param string $field
104
     * @param int|string $value
105
     *
106
     * @return bool
107
     */
108
    public function delete($field, $value)
109
    {
110
        return $this->_delete($field, $value);
111
    }
112
113
    /**
114
     * @param string $field
115
     * @param int|string $value
116
     *
117
     * @return Struct\GeneralInfo
118
     */
119
    public function get($field, $value)
120
    {
121
        $items = $this->_getItems(Struct\GeneralInfo::class, 'gen_info', $field, $value);
122
123
        return reset($items);
124
    }
125
126
    /**
127
     * @return Struct\GeneralInfo[]
128
     */
129
    public function getAll()
130
    {
131
        return $this->_getItems(Struct\GeneralInfo::class, 'gen_info');
132
    }
133
134
    /**
135
     * @param string $field
136
     * @param int|string $value
137
     *
138
     * @return Struct\DiskUsage
139
     */
140
    public function getDiskUsage($field, $value)
141
    {
142
        $items = $this->_getItems(Struct\DiskUsage::class, 'disk_usage', $field, $value);
143
144
        return reset($items);
145
    }
146
}
147