Skip to content

Commit bdaad89

Browse files
committed
Fix issues reported by psalm
1 parent f226ce3 commit bdaad89

Some content is hidden

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

71 files changed

+165
-296
lines changed

psalm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<psalm
3-
errorLevel="7"
3+
errorLevel="3"
44
resolveFromConfigFile="true"
55
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66
xmlns="https://getpsalm.org/schema/config"

src/Api/Client.php

Lines changed: 47 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Client
2525
protected array $_operatorsCache = [];
2626

2727
/**
28-
* @var callable
28+
* @var callable|null
2929
*/
3030
protected $_verifyResponseCallback;
3131

@@ -169,7 +169,7 @@ public function request($request, $mode = self::RESPONSE_SHORT)
169169
/** @psalm-suppress UndefinedClass */
170170
$xml = \pm_ApiRpc::getService($version)->call($requestXml->children()[0]->asXml(), $this->_login);
171171
} else {
172-
$xml = $this->_performHttpRequest($request);
172+
$xml = $this->_performHttpRequest((string) $request);
173173
}
174174

175175
$this->_verifyResponseCallback
@@ -212,22 +212,19 @@ private function _performHttpRequest($request)
212212

213213
curl_close($curl);
214214

215-
$xml = new XmlResponse($result);
216-
217-
return $xml;
215+
return new XmlResponse((string) $result);
218216
}
219217

220218
/**
221219
* Perform multiple API requests using single HTTP request.
222220
*
223-
* @param $requests
221+
* @param array $requests
224222
* @param int $mode
225223
*
226-
* @throws Client\Exception
227-
*
228224
* @return array
225+
* @throws Client\Exception
229226
*/
230-
public function multiRequest($requests, $mode = self::RESPONSE_SHORT)
227+
public function multiRequest(array $requests, $mode = self::RESPONSE_SHORT): array
231228
{
232229
$requestXml = $this->getPacket();
233230

@@ -237,23 +234,32 @@ public function multiRequest($requests, $mode = self::RESPONSE_SHORT)
237234
} else {
238235
if (is_array($request)) {
239236
$request = $this->_arrayToXml($request, $requestXml)->asXML();
237+
if (!$request) {
238+
throw new Client\Exception('Failed to create an XML string for request');
239+
}
240240
} elseif (preg_match('/^[a-z]/', $request)) {
241241
$this->_expandRequestShortSyntax($request, $requestXml);
242242
}
243243
}
244-
$responses[] = $this->request($request);
245244
}
246245

247246
if ('sdk' == $this->_protocol) {
248247
throw new Client\Exception('Multi requests are not supported via SDK.');
249248
} else {
250-
$responseXml = $this->_performHttpRequest($requestXml->asXML());
249+
$xmlString = $requestXml->asXML();
250+
if (!$xmlString) {
251+
throw new Client\Exception('Failed to create an XML string for request');
252+
}
253+
$responseXml = $this->_performHttpRequest($xmlString);
251254
}
252255

253256
$responses = [];
254257
foreach ($responseXml->children() as $childNode) {
255258
$xml = $this->getPacket();
256259
$dom = dom_import_simplexml($xml)->ownerDocument;
260+
if (!$dom) {
261+
continue;
262+
}
257263

258264
$childDomNode = dom_import_simplexml($childNode);
259265
$childDomNode = $dom->importNode($childDomNode, true);
@@ -371,230 +377,150 @@ protected function _isAssocArray(array $array)
371377
/**
372378
* @param string $name
373379
*
374-
* @return \PleskX\Api\Operator
380+
* @return mixed
375381
*/
376-
protected function _getOperator($name)
382+
protected function _getOperator(string $name)
377383
{
378384
if (!isset($this->_operatorsCache[$name])) {
379385
$className = '\\PleskX\\Api\\Operator\\'.$name;
386+
/** @psalm-suppress InvalidStringClass */
380387
$this->_operatorsCache[$name] = new $className($this);
381388
}
382389

383390
return $this->_operatorsCache[$name];
384391
}
385392

386-
/**
387-
* @return Operator\Server
388-
*/
389-
public function server()
393+
public function server(): Operator\Server
390394
{
391395
return $this->_getOperator('Server');
392396
}
393397

394-
/**
395-
* @return Operator\Customer
396-
*/
397-
public function customer()
398+
public function customer(): Operator\Customer
398399
{
399400
return $this->_getOperator('Customer');
400401
}
401402

402-
/**
403-
* @return Operator\Webspace
404-
*/
405-
public function webspace()
403+
public function webspace(): Operator\Webspace
406404
{
407405
return $this->_getOperator('Webspace');
408406
}
409407

410-
/**
411-
* @return Operator\Subdomain
412-
*/
413-
public function subdomain()
408+
public function subdomain(): Operator\Subdomain
414409
{
415410
return $this->_getOperator('Subdomain');
416411
}
417412

418-
/**
419-
* @return Operator\Dns
420-
*/
421-
public function dns()
413+
public function dns(): Operator\Dns
422414
{
423415
return $this->_getOperator('Dns');
424416
}
425417

426-
/**
427-
* @return Operator\DnsTemplate
428-
*/
429-
public function dnsTemplate()
418+
public function dnsTemplate(): Operator\DnsTemplate
430419
{
431420
return $this->_getOperator('DnsTemplate');
432421
}
433422

434-
/**
435-
* @return Operator\DatabaseServer
436-
*/
437-
public function databaseServer()
423+
public function databaseServer(): Operator\DatabaseServer
438424
{
439425
return $this->_getOperator('DatabaseServer');
440426
}
441427

442-
/**
443-
* @return Operator\Mail
444-
*/
445-
public function mail()
428+
public function mail(): Operator\Mail
446429
{
447430
return $this->_getOperator('Mail');
448431
}
449432

450-
/**
451-
* @return Operator\Certificate
452-
*/
453-
public function certificate()
433+
public function certificate(): Operator\Certificate
454434
{
455435
return $this->_getOperator('Certificate');
456436
}
457437

458-
/**
459-
* @return Operator\SiteAlias
460-
*/
461-
public function siteAlias()
438+
public function siteAlias(): Operator\SiteAlias
462439
{
463440
return $this->_getOperator('SiteAlias');
464441
}
465442

466-
/**
467-
* @return Operator\Ip
468-
*/
469-
public function ip()
443+
public function ip(): Operator\Ip
470444
{
471445
return $this->_getOperator('Ip');
472446
}
473447

474-
/**
475-
* @return Operator\EventLog
476-
*/
477-
public function eventLog()
448+
public function eventLog(): Operator\EventLog
478449
{
479450
return $this->_getOperator('EventLog');
480451
}
481452

482-
/**
483-
* @return Operator\SecretKey
484-
*/
485-
public function secretKey()
453+
public function secretKey(): Operator\SecretKey
486454
{
487455
return $this->_getOperator('SecretKey');
488456
}
489457

490-
/**
491-
* @return Operator\Ui
492-
*/
493-
public function ui()
458+
public function ui(): Operator\Ui
494459
{
495460
return $this->_getOperator('Ui');
496461
}
497462

498-
/**
499-
* @return Operator\ServicePlan
500-
*/
501-
public function servicePlan()
463+
public function servicePlan(): Operator\ServicePlan
502464
{
503465
return $this->_getOperator('ServicePlan');
504466
}
505467

506-
/**
507-
* @return Operator\VirtualDirectory
508-
*/
509-
public function virtualDirectory()
468+
public function virtualDirectory(): Operator\VirtualDirectory
510469
{
511470
return $this->_getOperator('VirtualDirectory');
512471
}
513472

514-
/**
515-
* @return Operator\Database
516-
*/
517-
public function database()
473+
public function database(): Operator\Database
518474
{
519475
return $this->_getOperator('Database');
520476
}
521477

522-
/**
523-
* @return Operator\Session
524-
*/
525-
public function session()
478+
public function session(): Operator\Session
526479
{
527480
return $this->_getOperator('Session');
528481
}
529482

530-
/**
531-
* @return Operator\Locale
532-
*/
533-
public function locale()
483+
public function locale(): Operator\Locale
534484
{
535485
return $this->_getOperator('Locale');
536486
}
537487

538-
/**
539-
* @return Operator\LogRotation
540-
*/
541-
public function logRotation()
488+
public function logRotation(): Operator\LogRotation
542489
{
543490
return $this->_getOperator('LogRotation');
544491
}
545492

546-
/**
547-
* @return Operator\ProtectedDirectory
548-
*/
549-
public function protectedDirectory()
493+
public function protectedDirectory(): Operator\ProtectedDirectory
550494
{
551495
return $this->_getOperator('ProtectedDirectory');
552496
}
553497

554-
/**
555-
* @return Operator\Reseller
556-
*/
557-
public function reseller()
498+
public function reseller(): Operator\Reseller
558499
{
559500
return $this->_getOperator('Reseller');
560501
}
561502

562-
/**
563-
* @return Operator\ResellerPlan
564-
*/
565-
public function resellerPlan()
503+
public function resellerPlan(): Operator\ResellerPlan
566504
{
567505
return $this->_getOperator('ResellerPlan');
568506
}
569507

570-
/**
571-
* @return Operator\Aps
572-
*/
573-
public function aps()
508+
public function aps(): Operator\Aps
574509
{
575510
return $this->_getOperator('Aps');
576511
}
577512

578-
/**
579-
* @return Operator\ServicePlanAddon
580-
*/
581-
public function servicePlanAddon()
513+
public function servicePlanAddon(): Operator\ServicePlanAddon
582514
{
583515
return $this->_getOperator('ServicePlanAddon');
584516
}
585517

586-
/**
587-
* @return Operator\Site
588-
*/
589-
public function site()
518+
public function site(): Operator\Site
590519
{
591520
return $this->_getOperator('Site');
592521
}
593522

594-
/**
595-
* @return Operator\PhpHandler
596-
*/
597-
public function phpHandler()
523+
public function phpHandler(): Operator\PhpHandler
598524
{
599525
return $this->_getOperator('PhpHandler');
600526
}

src/Api/Operator.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Operator
88
protected string $_wrapperTag = '';
99
protected Client $_client;
1010

11-
public function __construct($client)
11+
public function __construct(Client $client)
1212
{
1313
$this->_client = $client;
1414

@@ -78,7 +78,7 @@ protected function _getItems($structClass, $infoTag, $field = null, $value = nul
7878

7979
$filterTag = $getTag->addChild('filter');
8080
if (!is_null($field)) {
81-
$filterTag->{$field} = $value;
81+
$filterTag->{$field} = (string) $value;
8282
}
8383

8484
$getTag->addChild('dataset')->addChild($infoTag);
@@ -93,6 +93,7 @@ protected function _getItems($structClass, $infoTag, $field = null, $value = nul
9393
if (!isset($xmlResult->data) || !isset($xmlResult->data->$infoTag)) {
9494
continue;
9595
}
96+
/** @psalm-suppress InvalidStringClass */
9697
$item = new $structClass($xmlResult->data->$infoTag);
9798
if (isset($xmlResult->id) && property_exists($item, 'id')) {
9899
$item->id = (int) $xmlResult->id;

src/Api/Operator/Database.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,15 @@ public function getAllUsers($field, $value)
128128
*
129129
* @return \PleskX\Api\XmlResponse
130130
*/
131-
private function _get($command, $field, $value)
131+
private function _get(string $command, string $field, $value)
132132
{
133133
$packet = $this->_client->getPacket();
134134
$getTag = $packet->addChild($this->_wrapperTag)->addChild($command);
135135

136136
$filterTag = $getTag->addChild('filter');
137-
if (!is_null($field)) {
138-
$filterTag->{$field} = $value;
139-
}
140-
141-
$response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
137+
$filterTag->{$field} = (string) $value;
142138

143-
return $response;
139+
return $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
144140
}
145141

146142
/**

0 commit comments

Comments
 (0)