Skip to content

Commit b030299

Browse files
Merge pull request #77 from plesk/analysis-BMMv97
Apply fixes from StyleCI
2 parents 38a7cd1 + ae2469b commit b030299

File tree

91 files changed

+384
-241
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+384
-241
lines changed

src/Api/Client.php

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
// Copyright 1999-2020. Plesk International GmbH.
33

44
namespace PleskX\Api;
5+
56
use SimpleXMLElement;
67

78
/**
8-
* Client for Plesk XML-RPC API
9+
* Client for Plesk XML-RPC API.
910
*/
1011
class Client
1112
{
@@ -28,7 +29,7 @@ class Client
2829
protected $_verifyResponseCallback;
2930

3031
/**
31-
* Create client
32+
* Create client.
3233
*
3334
* @param string $host
3435
* @param int $port
@@ -42,7 +43,7 @@ public function __construct($host, $port = 8443, $protocol = 'https')
4243
}
4344

4445
/**
45-
* Setup credentials for authentication
46+
* Setup credentials for authentication.
4647
*
4748
* @param string $login
4849
* @param string $password
@@ -54,7 +55,7 @@ public function setCredentials($login, $password)
5455
}
5556

5657
/**
57-
* Define secret key for alternative authentication
58+
* Define secret key for alternative authentication.
5859
*
5960
* @param string $secretKey
6061
*/
@@ -64,7 +65,7 @@ public function setSecretKey($secretKey)
6465
}
6566

6667
/**
67-
* Set default version for requests
68+
* Set default version for requests.
6869
*
6970
* @param string $version
7071
*/
@@ -74,7 +75,7 @@ public function setVersion($version)
7475
}
7576

7677
/**
77-
* Set custom function to verify response of API call according your own needs. Default verifying will be used if it is not specified
78+
* Set custom function to verify response of API call according your own needs. Default verifying will be used if it is not specified.
7879
*
7980
* @param callable|null $function
8081
*/
@@ -84,7 +85,7 @@ public function setVerifyResponse(callable $function = null)
8485
}
8586

8687
/**
87-
* Retrieve host used for communication
88+
* Retrieve host used for communication.
8889
*
8990
* @return string
9091
*/
@@ -94,7 +95,7 @@ public function getHost()
9495
}
9596

9697
/**
97-
* Retrieve port used for communication
98+
* Retrieve port used for communication.
9899
*
99100
* @return int
100101
*/
@@ -104,7 +105,7 @@ public function getPort()
104105
}
105106

106107
/**
107-
* Retrieve name of the protocol (http or https) used for communication
108+
* Retrieve name of the protocol (http or https) used for communication.
108109
*
109110
* @return string
110111
*/
@@ -114,24 +115,27 @@ public function getProtocol()
114115
}
115116

116117
/**
117-
* Retrieve XML template for packet
118+
* Retrieve XML template for packet.
118119
*
119120
* @param string|null $version
121+
*
120122
* @return SimpleXMLElement
121123
*/
122124
public function getPacket($version = null)
123125
{
124126
$protocolVersion = !is_null($version) ? $version : $this->_version;
125127
$content = "<?xml version='1.0' encoding='UTF-8' ?>";
126-
$content .= "<packet" . ("" === $protocolVersion ? "" : " version='$protocolVersion'") . "/>";
128+
$content .= '<packet'.('' === $protocolVersion ? '' : " version='$protocolVersion'").'/>';
129+
127130
return new SimpleXMLElement($content);
128131
}
129132

130133
/**
131-
* Perform API request
134+
* Perform API request.
132135
*
133136
* @param string|array|SimpleXMLElement $request
134137
* @param int $mode
138+
*
135139
* @return XmlResponse
136140
*/
137141
public function request($request, $mode = self::RESPONSE_SHORT)
@@ -143,14 +147,14 @@ public function request($request, $mode = self::RESPONSE_SHORT)
143147

144148
if (is_array($request)) {
145149
$request = $this->_arrayToXml($request, $xml)->asXML();
146-
} else if (preg_match('/^[a-z]/', $request)) {
150+
} elseif (preg_match('/^[a-z]/', $request)) {
147151
$request = $this->_expandRequestShortSyntax($request, $xml);
148152
}
149153
}
150154

151155
if ('sdk' == $this->_protocol) {
152156
$version = ('' == $this->_version) ? null : $this->_version;
153-
$requestXml = new SimpleXMLElement((string)$request);
157+
$requestXml = new SimpleXMLElement((string) $request);
154158
$xml = \pm_ApiRpc::getService($version)->call($requestXml->children()[0]->asXml(), $this->_login);
155159
} else {
156160
$xml = $this->_performHttpRequest($request);
@@ -164,11 +168,13 @@ public function request($request, $mode = self::RESPONSE_SHORT)
164168
}
165169

166170
/**
167-
* Perform HTTP request to end-point
171+
* Perform HTTP request to end-point.
168172
*
169173
* @param string $request
170-
* @return XmlResponse
174+
*
171175
* @throws Client\Exception
176+
*
177+
* @return XmlResponse
172178
*/
173179
private function _performHttpRequest($request)
174180
{
@@ -191,20 +197,22 @@ private function _performHttpRequest($request)
191197
curl_close($curl);
192198

193199
$xml = new XmlResponse($result);
200+
194201
return $xml;
195202
}
196203

197204
/**
198-
* Perform multiple API requests using single HTTP request
205+
* Perform multiple API requests using single HTTP request.
199206
*
200207
* @param $requests
201208
* @param int $mode
202-
* @return array
209+
*
203210
* @throws Client\Exception
211+
*
212+
* @return array
204213
*/
205214
public function multiRequest($requests, $mode = self::RESPONSE_SHORT)
206215
{
207-
208216
$requestXml = $this->getPacket();
209217

210218
foreach ($requests as $request) {
@@ -213,7 +221,7 @@ public function multiRequest($requests, $mode = self::RESPONSE_SHORT)
213221
} else {
214222
if (is_array($request)) {
215223
$request = $this->_arrayToXml($request, $requestXml)->asXML();
216-
} else if (preg_match('/^[a-z]/', $request)) {
224+
} elseif (preg_match('/^[a-z]/', $request)) {
217225
$this->_expandRequestShortSyntax($request, $requestXml);
218226
}
219227
}
@@ -243,16 +251,16 @@ public function multiRequest($requests, $mode = self::RESPONSE_SHORT)
243251
}
244252

245253
/**
246-
* Retrieve list of headers needed for request
254+
* Retrieve list of headers needed for request.
247255
*
248256
* @return array
249257
*/
250258
protected function _getHeaders()
251259
{
252-
$headers = array(
253-
"Content-Type: text/xml",
254-
"HTTP_PRETTY_PRINT: TRUE",
255-
);
260+
$headers = [
261+
'Content-Type: text/xml',
262+
'HTTP_PRETTY_PRINT: TRUE',
263+
];
256264

257265
if ($this->_secretKey) {
258266
$headers[] = "KEY: $this->_secretKey";
@@ -265,29 +273,32 @@ protected function _getHeaders()
265273
}
266274

267275
/**
268-
* Verify that response does not contain errors
276+
* Verify that response does not contain errors.
269277
*
270278
* @param XmlResponse $xml
279+
*
271280
* @throws Exception
272281
*/
273282
protected function _verifyResponse($xml)
274283
{
275-
if ($xml->system && $xml->system->status && 'error' == (string)$xml->system->status) {
276-
throw new Exception((string)$xml->system->errtext, (int)$xml->system->errcode);
284+
if ($xml->system && $xml->system->status && 'error' == (string) $xml->system->status) {
285+
throw new Exception((string) $xml->system->errtext, (int) $xml->system->errcode);
277286
}
278287

279288
if ($xml->xpath('//status[text()="error"]') && $xml->xpath('//errcode') && $xml->xpath('//errtext')) {
280-
$errorCode = (int)$xml->xpath('//errcode')[0];
281-
$errorMessage = (string)$xml->xpath('//errtext')[0];
289+
$errorCode = (int) $xml->xpath('//errcode')[0];
290+
$errorMessage = (string) $xml->xpath('//errtext')[0];
291+
282292
throw new Exception($errorMessage, $errorCode);
283293
}
284294
}
285295

286296
/**
287-
* Expand short syntax (some.method.call) into full XML representation
297+
* Expand short syntax (some.method.call) into full XML representation.
288298
*
289299
* @param string $request
290300
* @param SimpleXMLElement $xml
301+
*
291302
* @return string
292303
*/
293304
protected function _expandRequestShortSyntax($request, SimpleXMLElement $xml)
@@ -304,11 +315,12 @@ protected function _expandRequestShortSyntax($request, SimpleXMLElement $xml)
304315
}
305316

306317
/**
307-
* Convert array to XML representation
318+
* Convert array to XML representation.
308319
*
309320
* @param array $array
310321
* @param SimpleXMLElement $xml
311322
* @param string $parentEl
323+
*
312324
* @return SimpleXMLElement
313325
*/
314326
protected function _arrayToXml(array $array, SimpleXMLElement $xml, $parentEl = null)
@@ -327,6 +339,7 @@ protected function _arrayToXml(array $array, SimpleXMLElement $xml, $parentEl =
327339

328340
/**
329341
* @param array $array
342+
*
330343
* @return bool
331344
*/
332345
protected function _isAssocArray(array $array)
@@ -336,12 +349,13 @@ protected function _isAssocArray(array $array)
336349

337350
/**
338351
* @param string $name
352+
*
339353
* @return \PleskX\Api\Operator
340354
*/
341355
protected function _getOperator($name)
342356
{
343357
if (!isset($this->_operatorsCache[$name])) {
344-
$className = '\\PleskX\\Api\\Operator\\' . $name;
358+
$className = '\\PleskX\\Api\\Operator\\'.$name;
345359
$this->_operatorsCache[$name] = new $className($this);
346360
}
347361

src/Api/Client/Exception.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace PleskX\Api\Client;
55

66
/**
7-
* Transport layer exception
7+
* Transport layer exception.
88
*/
99
class Exception extends \Exception
1010
{

src/Api/Exception.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace PleskX\Api;
55

66
/**
7-
* Exceptions for XML-RPC API client
7+
* Exceptions for XML-RPC API client.
88
*/
99
class Exception extends \Exception
1010
{

src/Api/InternalClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace PleskX\Api;
55

66
/**
7-
* Internal client for Plesk XML-RPC API (via SDK)
7+
* Internal client for Plesk XML-RPC API (via SDK).
88
*/
99
class InternalClient extends Client
1010
{
@@ -14,7 +14,7 @@ public function __construct()
1414
}
1515

1616
/**
17-
* Setup login to execute requests under certain user
17+
* Setup login to execute requests under certain user.
1818
*
1919
* @param $login
2020
*/

src/Api/Operator.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
class Operator
77
{
8-
98
/** @var string|null */
109
protected $_wrapperTag = null;
1110

@@ -24,10 +23,11 @@ public function __construct($client)
2423
}
2524

2625
/**
27-
* Perform plain API request
26+
* Perform plain API request.
2827
*
2928
* @param string|array $request
3029
* @param int $mode
30+
*
3131
* @return XmlResponse
3232
*/
3333
public function request($request, $mode = Client::RESPONSE_SHORT)
@@ -36,7 +36,7 @@ public function request($request, $mode = Client::RESPONSE_SHORT)
3636

3737
if (is_array($request)) {
3838
$request = [$wrapperTag => $request];
39-
} else if (preg_match('/^[a-z]/', $request)) {
39+
} elseif (preg_match('/^[a-z]/', $request)) {
4040
$request = "$wrapperTag.$request";
4141
} else {
4242
$request = "<$wrapperTag>$request</$wrapperTag>";
@@ -47,22 +47,25 @@ public function request($request, $mode = Client::RESPONSE_SHORT)
4747

4848
/**
4949
* @param string $field
50-
* @param integer|string $value
50+
* @param int|string $value
5151
* @param string $deleteMethodName
52+
*
5253
* @return bool
5354
*/
5455
protected function _delete($field, $value, $deleteMethodName = 'del')
5556
{
5657
$response = $this->request("$deleteMethodName.filter.$field=$value");
57-
return 'ok' === (string)$response->status;
58+
59+
return 'ok' === (string) $response->status;
5860
}
5961

6062
/**
6163
* @param string $structClass
6264
* @param string $infoTag
6365
* @param string|null $field
64-
* @param integer|string|null $value
66+
* @param int|string|null $value
6567
* @param callable|null $filter
68+
*
6669
* @return mixed
6770
*/
6871
protected function _getItems($structClass, $infoTag, $field = null, $value = null, callable $filter = null)
@@ -89,5 +92,4 @@ protected function _getItems($structClass, $infoTag, $field = null, $value = nul
8992

9093
return $items;
9194
}
92-
9395
}

src/Api/Operator/Aps.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@
55

66
class Aps extends \PleskX\Api\Operator
77
{
8-
98
}

0 commit comments

Comments
 (0)