Skip to content

Commit 8ad7345

Browse files
committed
Use type hints instead of doc blocks
1 parent 0fdd640 commit 8ad7345

Some content is hidden

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

67 files changed

+579
-815
lines changed

Diff for: psalm.xml

+5
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,9 @@
1212
<directory name="vendor" />
1313
</ignoreFiles>
1414
</projectFiles>
15+
16+
<issueHandlers>
17+
<PropertyNotSetInConstructor errorLevel="suppress" />
18+
<UndefinedPropertyFetch errorLevel="suppress" />
19+
</issueHandlers>
1520
</psalm>

Diff for: src/Api/Client.php

+21-21
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ class Client
1313
const RESPONSE_SHORT = 1;
1414
const RESPONSE_FULL = 2;
1515

16-
protected $_host;
17-
protected $_port;
18-
protected $_protocol;
19-
protected $_login;
20-
protected $_password;
21-
protected $_proxy = '';
22-
protected $_secretKey;
23-
protected $_version = '';
16+
protected string $_host;
17+
protected int $_port;
18+
protected string $_protocol;
19+
protected string $_login = '';
20+
protected string $_password = '';
21+
protected string $_proxy = '';
22+
protected string $_secretKey = '';
23+
protected string $_version = '';
2424

25-
protected $_operatorsCache = [];
25+
protected array $_operatorsCache = [];
2626

2727
/**
2828
* @var callable
@@ -36,7 +36,7 @@ class Client
3636
* @param int $port
3737
* @param string $protocol
3838
*/
39-
public function __construct($host, $port = 8443, $protocol = 'https')
39+
public function __construct(string $host, int $port = 8443, string $protocol = 'https')
4040
{
4141
$this->_host = $host;
4242
$this->_port = $port;
@@ -49,7 +49,7 @@ public function __construct($host, $port = 8443, $protocol = 'https')
4949
* @param string $login
5050
* @param string $password
5151
*/
52-
public function setCredentials($login, $password)
52+
public function setCredentials(string $login, string $password): void
5353
{
5454
$this->_login = $login;
5555
$this->_password = $password;
@@ -60,7 +60,7 @@ public function setCredentials($login, $password)
6060
*
6161
* @param string $secretKey
6262
*/
63-
public function setSecretKey($secretKey)
63+
public function setSecretKey(string $secretKey): void
6464
{
6565
$this->_secretKey = $secretKey;
6666
}
@@ -70,7 +70,7 @@ public function setSecretKey($secretKey)
7070
*
7171
* @param string $proxy
7272
*/
73-
public function setProxy($proxy)
73+
public function setProxy(string $proxy): void
7474
{
7575
$this->_proxy = $proxy;
7676
}
@@ -80,7 +80,7 @@ public function setProxy($proxy)
8080
*
8181
* @param string $version
8282
*/
83-
public function setVersion($version)
83+
public function setVersion(string $version): void
8484
{
8585
$this->_version = $version;
8686
}
@@ -90,7 +90,7 @@ public function setVersion($version)
9090
*
9191
* @param callable|null $function
9292
*/
93-
public function setVerifyResponse(callable $function = null)
93+
public function setVerifyResponse(callable $function = null): void
9494
{
9595
$this->_verifyResponseCallback = $function;
9696
}
@@ -100,7 +100,7 @@ public function setVerifyResponse(callable $function = null)
100100
*
101101
* @return string
102102
*/
103-
public function getHost()
103+
public function getHost(): string
104104
{
105105
return $this->_host;
106106
}
@@ -110,7 +110,7 @@ public function getHost()
110110
*
111111
* @return int
112112
*/
113-
public function getPort()
113+
public function getPort(): int
114114
{
115115
return $this->_port;
116116
}
@@ -120,7 +120,7 @@ public function getPort()
120120
*
121121
* @return string
122122
*/
123-
public function getProtocol()
123+
public function getProtocol(): string
124124
{
125125
return $this->_protocol;
126126
}
@@ -132,7 +132,7 @@ public function getProtocol()
132132
*
133133
* @return SimpleXMLElement
134134
*/
135-
public function getPacket($version = null)
135+
public function getPacket($version = null): SimpleXMLElement
136136
{
137137
$protocolVersion = !is_null($version) ? $version : $this->_version;
138138
$content = "<?xml version='1.0' encoding='UTF-8' ?>";
@@ -295,7 +295,7 @@ protected function _getHeaders()
295295
*
296296
* @throws Exception
297297
*/
298-
protected function _verifyResponse($xml)
298+
protected function _verifyResponse($xml): void
299299
{
300300
if ($xml->system && $xml->system->status && 'error' == (string) $xml->system->status) {
301301
throw new Exception((string) $xml->system->errtext, (int) $xml->system->errcode);
@@ -315,7 +315,7 @@ protected function _verifyResponse($xml)
315315
* @param string $request
316316
* @param SimpleXMLElement $xml
317317
*
318-
* @return string
318+
* @return false|string
319319
*/
320320
protected function _expandRequestShortSyntax($request, SimpleXMLElement $xml)
321321
{

Diff for: src/Api/InternalClient.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public function __construct()
1616
/**
1717
* Setup login to execute requests under certain user.
1818
*
19-
* @param $login
19+
* @param string $login
2020
*/
21-
public function setLogin($login)
21+
public function setLogin(string $login): void
2222
{
2323
$this->_login = $login;
2424
}

Diff for: src/Api/Operator.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,14 @@
55

66
class Operator
77
{
8-
/** @var string|null */
9-
protected $_wrapperTag = null;
10-
11-
/** @var \PleskX\Api\Client */
12-
protected $_client;
8+
protected string $_wrapperTag = '';
9+
protected Client $_client;
1310

1411
public function __construct($client)
1512
{
1613
$this->_client = $client;
1714

18-
if (is_null($this->_wrapperTag)) {
15+
if ('' === $this->_wrapperTag) {
1916
$classNameParts = explode('\\', get_class($this));
2017
$this->_wrapperTag = end($classNameParts);
2118
$this->_wrapperTag = strtolower(preg_replace('/([a-z])([A-Z])/', '\1-\2', $this->_wrapperTag));

Diff for: src/Api/Operator/DatabaseServer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class DatabaseServer extends \PleskX\Api\Operator
99
{
10-
protected $_wrapperTag = 'db_server';
10+
protected string $_wrapperTag = 'db_server';
1111

1212
/**
1313
* @return array

Diff for: src/Api/Operator/DnsTemplate.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class DnsTemplate extends \PleskX\Api\Operator
99
{
10-
protected $_wrapperTag = 'dns';
10+
protected string $_wrapperTag = 'dns';
1111

1212
/**
1313
* @param array $properties

Diff for: src/Api/Operator/EventLog.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class EventLog extends \PleskX\Api\Operator
99
{
10-
protected $_wrapperTag = 'event_log';
10+
protected string $_wrapperTag = 'event_log';
1111

1212
/**
1313
* @return Struct\Event[]

Diff for: src/Api/Operator/ProtectedDirectory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class ProtectedDirectory extends \PleskX\Api\Operator
99
{
10-
protected $_wrapperTag = 'protected-dir';
10+
protected string $_wrapperTag = 'protected-dir';
1111

1212
/**
1313
* @param string $name

Diff for: src/Api/Operator/SecretKey.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class SecretKey extends \PleskX\Api\Operator
99
{
10-
protected $_wrapperTag = 'secret_key';
10+
protected string $_wrapperTag = 'secret_key';
1111

1212
/**
1313
* @param string $ipAddress

Diff for: src/Api/Operator/Server.php

+16-41
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
namespace PleskX\Api\Operator;
55

66
use PleskX\Api\Struct\Server as Struct;
7+
use PleskX\Api\XmlResponse;
78

89
class Server extends \PleskX\Api\Operator
910
{
10-
/**
11-
* @return array
12-
*/
13-
public function getProtos()
11+
public function getProtos(): array
1412
{
1513
$packet = $this->_client->getPacket();
1614
$packet->addChild($this->_wrapperTag)->addChild('get_protos');
@@ -19,25 +17,22 @@ public function getProtos()
1917
return (array) $response->protos->proto;
2018
}
2119

22-
public function getGeneralInfo()
20+
public function getGeneralInfo(): Struct\GeneralInfo
2321
{
2422
return new Struct\GeneralInfo($this->_getInfo('gen_info'));
2523
}
2624

27-
public function getPreferences()
25+
public function getPreferences(): Struct\Preferences
2826
{
2927
return new Struct\Preferences($this->_getInfo('prefs'));
3028
}
3129

32-
public function getAdmin()
30+
public function getAdmin(): Struct\Admin
3331
{
3432
return new Struct\Admin($this->_getInfo('admin'));
3533
}
3634

37-
/**
38-
* @return array
39-
*/
40-
public function getKeyInfo()
35+
public function getKeyInfo(): array
4136
{
4237
$keyInfo = [];
4338
$keyInfoXml = $this->_getInfo('key');
@@ -49,10 +44,7 @@ public function getKeyInfo()
4944
return $keyInfo;
5045
}
5146

52-
/**
53-
* @return array
54-
*/
55-
public function getComponents()
47+
public function getComponents(): array
5648
{
5749
$components = [];
5850
$componentsXml = $this->_getInfo('components');
@@ -64,10 +56,7 @@ public function getComponents()
6456
return $components;
6557
}
6658

67-
/**
68-
* @return array
69-
*/
70-
public function getServiceStates()
59+
public function getServiceStates(): array
7160
{
7261
$states = [];
7362
$statesXml = $this->_getInfo('services_state');
@@ -83,15 +72,12 @@ public function getServiceStates()
8372
return $states;
8473
}
8574

86-
public function getSessionPreferences()
75+
public function getSessionPreferences(): Struct\SessionPreferences
8776
{
8877
return new Struct\SessionPreferences($this->_getInfo('session_setup'));
8978
}
9079

91-
/**
92-
* @return array
93-
*/
94-
public function getShells()
80+
public function getShells(): array
9581
{
9682
$shells = [];
9783
$shellsXml = $this->_getInfo('shells');
@@ -103,25 +89,19 @@ public function getShells()
10389
return $shells;
10490
}
10591

106-
/**
107-
* @return array
108-
*/
109-
public function getNetworkInterfaces()
92+
public function getNetworkInterfaces(): array
11093
{
11194
$interfacesXml = $this->_getInfo('interfaces');
11295

11396
return (array) $interfacesXml->interface;
11497
}
11598

116-
public function getStatistics()
99+
public function getStatistics(): Struct\Statistics
117100
{
118101
return new Struct\Statistics($this->_getInfo('stat'));
119102
}
120103

121-
/**
122-
* @return array
123-
*/
124-
public function getSiteIsolationConfig()
104+
public function getSiteIsolationConfig(): array
125105
{
126106
$config = [];
127107
$configXml = $this->_getInfo('site-isolation-config');
@@ -133,7 +113,7 @@ public function getSiteIsolationConfig()
133113
return $config;
134114
}
135115

136-
public function getUpdatesInfo()
116+
public function getUpdatesInfo(): Struct\UpdatesInfo
137117
{
138118
return new Struct\UpdatesInfo($this->_getInfo('updates'));
139119
}
@@ -144,7 +124,7 @@ public function getUpdatesInfo()
144124
*
145125
* @return string
146126
*/
147-
public function createSession($login, $clientIp)
127+
public function createSession(string $login, string $clientIp): string
148128
{
149129
$packet = $this->_client->getPacket();
150130
$sessionNode = $packet->addChild($this->_wrapperTag)->addChild('create_session');
@@ -157,12 +137,7 @@ public function createSession($login, $clientIp)
157137
return (string) $response->id;
158138
}
159139

160-
/**
161-
* @param string $operation
162-
*
163-
* @return \SimpleXMLElement
164-
*/
165-
private function _getInfo($operation)
140+
private function _getInfo(string $operation): XmlResponse
166141
{
167142
$packet = $this->_client->getPacket();
168143
$packet->addChild($this->_wrapperTag)->addChild('get')->addChild($operation);

Diff for: src/Api/Operator/VirtualDirectory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
class VirtualDirectory extends \PleskX\Api\Operator
77
{
8-
protected $_wrapperTag = 'virtdir';
8+
protected string $_wrapperTag = 'virtdir';
99
}

0 commit comments

Comments
 (0)