Skip to content

Commit 4191ffd

Browse files
committed
Enforce type checks for better code quality
1 parent bd32dba commit 4191ffd

21 files changed

+75
-215
lines changed

src/Api/Operator.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(Client $client)
2727
*
2828
* @return XmlResponse
2929
*/
30-
public function request($request, $mode = Client::RESPONSE_SHORT)
30+
public function request($request, $mode = Client::RESPONSE_SHORT): XmlResponse
3131
{
3232
$wrapperTag = $this->wrapperTag;
3333

@@ -69,9 +69,9 @@ protected function deleteBy(string $field, $value, string $deleteMethodName = 'd
6969
* @param int|string|null $value
7070
* @param callable|null $filter
7171
*
72-
* @return mixed
72+
* @return array
7373
*/
74-
protected function getItems($structClass, $infoTag, $field = null, $value = null, callable $filter = null)
74+
protected function getItems($structClass, $infoTag, $field = null, $value = null, callable $filter = null): array
7575
{
7676
$packet = $this->client->getPacket();
7777
$getTag = $packet->addChild($this->wrapperTag)->addChild('get');

src/Api/Operator/Certificate.php

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

88
class Certificate extends \PleskX\Api\Operator
99
{
10-
/**
11-
* @param array $properties
12-
*
13-
* @return Struct\Info
14-
*/
15-
public function generate($properties)
10+
public function generate(array $properties): Struct\Info
1611
{
1712
$packet = $this->client->getPacket();
1813
$info = $packet->addChild($this->wrapperTag)->addChild('generate')->addChild('info');

src/Api/Operator/Customer.php

+4-9
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@
77

88
class Customer extends \PleskX\Api\Operator
99
{
10-
/**
11-
* @param array $properties
12-
*
13-
* @return Struct\Info
14-
*/
15-
public function create($properties)
10+
public function create(array $properties): Struct\Info
1611
{
1712
$packet = $this->client->getPacket();
1813
$info = $packet->addChild($this->wrapperTag)->addChild('add')->addChild('gen_info');
@@ -32,7 +27,7 @@ public function create($properties)
3227
*
3328
* @return bool
3429
*/
35-
public function delete($field, $value)
30+
public function delete(string $field, $value): bool
3631
{
3732
return $this->deleteBy($field, $value);
3833
}
@@ -43,7 +38,7 @@ public function delete($field, $value)
4338
*
4439
* @return Struct\GeneralInfo
4540
*/
46-
public function get($field, $value)
41+
public function get(string $field, $value): Struct\GeneralInfo
4742
{
4843
$items = $this->getItems(Struct\GeneralInfo::class, 'gen_info', $field, $value);
4944

@@ -53,7 +48,7 @@ public function get($field, $value)
5348
/**
5449
* @return Struct\GeneralInfo[]
5550
*/
56-
public function getAll()
51+
public function getAll(): array
5752
{
5853
return $this->getItems(Struct\GeneralInfo::class, 'gen_info');
5954
}

src/Api/Operator/Database.php

+13-33
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,21 @@
44
namespace PleskX\Api\Operator;
55

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

89
class Database extends \PleskX\Api\Operator
910
{
10-
/**
11-
* @param array $properties
12-
*
13-
* @return Struct\Info
14-
*/
15-
public function create($properties)
11+
public function create(array $properties): Struct\Info
1612
{
1713
return new Struct\Info($this->process('add-db', $properties));
1814
}
1915

20-
/**
21-
* @param array $properties
22-
*
23-
* @return Struct\UserInfo
24-
*/
25-
public function createUser($properties)
16+
public function createUser(array $properties): Struct\UserInfo
2617
{
2718
return new Struct\UserInfo($this->process('add-db-user', $properties));
2819
}
2920

30-
/**
31-
* @param string $command
32-
* @param array $properties
33-
*
34-
* @return \PleskX\Api\XmlResponse
35-
*/
36-
private function process($command, array $properties)
21+
private function process(string $command, array $properties): XmlResponse
3722
{
3823
$packet = $this->client->getPacket();
3924
$info = $packet->addChild($this->wrapperTag)->addChild($command);
@@ -49,12 +34,7 @@ private function process($command, array $properties)
4934
return $this->client->request($packet);
5035
}
5136

52-
/**
53-
* @param array $properties
54-
*
55-
* @return bool
56-
*/
57-
public function updateUser(array $properties)
37+
public function updateUser(array $properties): bool
5838
{
5939
$response = $this->process('set-db-user', $properties);
6040

@@ -67,7 +47,7 @@ public function updateUser(array $properties)
6747
*
6848
* @return Struct\Info
6949
*/
70-
public function get($field, $value)
50+
public function get(string $field, $value): Struct\Info
7151
{
7252
$items = $this->getAll($field, $value);
7353

@@ -80,7 +60,7 @@ public function get($field, $value)
8060
*
8161
* @return Struct\UserInfo
8262
*/
83-
public function getUser($field, $value)
63+
public function getUser(string $field, $value): Struct\UserInfo
8464
{
8565
$items = $this->getAllUsers($field, $value);
8666

@@ -93,7 +73,7 @@ public function getUser($field, $value)
9373
*
9474
* @return Struct\Info[]
9575
*/
96-
public function getAll($field, $value)
76+
public function getAll(string $field, $value): array
9777
{
9878
$response = $this->getBy('get-db', $field, $value);
9979
$items = [];
@@ -110,7 +90,7 @@ public function getAll($field, $value)
11090
*
11191
* @return Struct\UserInfo[]
11292
*/
113-
public function getAllUsers($field, $value)
93+
public function getAllUsers(string $field, $value): array
11494
{
11595
$response = $this->getBy('get-db-users', $field, $value);
11696
$items = [];
@@ -126,9 +106,9 @@ public function getAllUsers($field, $value)
126106
* @param string $field
127107
* @param int|string $value
128108
*
129-
* @return \PleskX\Api\XmlResponse
109+
* @return XmlResponse
130110
*/
131-
private function getBy(string $command, string $field, $value)
111+
private function getBy(string $command, string $field, $value): XmlResponse
132112
{
133113
$packet = $this->client->getPacket();
134114
$getTag = $packet->addChild($this->wrapperTag)->addChild($command);
@@ -145,7 +125,7 @@ private function getBy(string $command, string $field, $value)
145125
*
146126
* @return bool
147127
*/
148-
public function delete($field, $value)
128+
public function delete(string $field, $value): bool
149129
{
150130
return $this->deleteBy($field, $value, 'del-db');
151131
}
@@ -156,7 +136,7 @@ public function delete($field, $value)
156136
*
157137
* @return bool
158138
*/
159-
public function deleteUser($field, $value)
139+
public function deleteUser(string $field, $value): bool
160140
{
161141
return $this->deleteBy($field, $value, 'del-db-user');
162142
}

src/Api/Operator/DatabaseServer.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ class DatabaseServer extends \PleskX\Api\Operator
99
{
1010
protected string $wrapperTag = 'db_server';
1111

12-
/**
13-
* @return array
14-
*/
15-
public function getSupportedTypes()
12+
public function getSupportedTypes(): array
1613
{
1714
$response = $this->request('get-supported-types');
1815

@@ -25,7 +22,7 @@ public function getSupportedTypes()
2522
*
2623
* @return Struct\Info
2724
*/
28-
public function get(string $field, $value)
25+
public function get(string $field, $value): Struct\Info
2926
{
3027
$items = $this->getBy($field, $value);
3128

@@ -35,7 +32,7 @@ public function get(string $field, $value)
3532
/**
3633
* @return Struct\Info[]
3734
*/
38-
public function getAll()
35+
public function getAll(): array
3936
{
4037
return $this->getBy();
4138
}
@@ -46,7 +43,7 @@ public function getAll()
4643
*
4744
* @return Struct\Info[]
4845
*/
49-
private function getBy($field = null, $value = null)
46+
private function getBy($field = null, $value = null): array
5047
{
5148
$packet = $this->client->getPacket();
5249
$getTag = $packet->addChild($this->wrapperTag)->addChild('get');

src/Api/Operator/Dns.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@
77

88
class Dns extends \PleskX\Api\Operator
99
{
10-
/**
11-
* @param array $properties
12-
*
13-
* @return Struct\Info
14-
*/
15-
public function create($properties)
10+
public function create(array $properties): Struct\Info
1611
{
1712
$packet = $this->client->getPacket();
1813
$info = $packet->addChild($this->wrapperTag)->addChild('add_rec');
@@ -58,7 +53,7 @@ public function bulkCreate(array $records): array
5853
*
5954
* @return Struct\Info
6055
*/
61-
public function get(string $field, $value)
56+
public function get(string $field, $value): Struct\Info
6257
{
6358
$items = $this->getAll($field, $value);
6459

src/Api/Operator/DnsTemplate.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class DnsTemplate extends \PleskX\Api\Operator
1414
*
1515
* @return Struct\Info
1616
*/
17-
public function create(array $properties)
17+
public function create(array $properties): Struct\Info
1818
{
1919
$packet = $this->client->getPacket();
2020
$info = $packet->addChild($this->wrapperTag)->addChild('add_rec');
@@ -31,9 +31,9 @@ public function create(array $properties)
3131
* @param string $field
3232
* @param int|string $value
3333
*
34-
* @return Struct\Info|null
34+
* @return Struct\Info
3535
*/
36-
public function get($field, $value)
36+
public function get(string $field, $value): Struct\Info
3737
{
3838
$items = $this->getAll($field, $value);
3939

src/Api/Operator/EventLog.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class EventLog extends \PleskX\Api\Operator
1212
/**
1313
* @return Struct\Event[]
1414
*/
15-
public function get()
15+
public function get(): array
1616
{
1717
$records = [];
1818
$response = $this->request('get');
@@ -27,7 +27,7 @@ public function get()
2727
/**
2828
* @return Struct\DetailedEvent[]
2929
*/
30-
public function getDetailedLog()
30+
public function getDetailedLog(): array
3131
{
3232
$records = [];
3333
$response = $this->request('get_events');
@@ -39,10 +39,7 @@ public function getDetailedLog()
3939
return $records;
4040
}
4141

42-
/**
43-
* @return int
44-
*/
45-
public function getLastId()
42+
public function getLastId(): int
4643
{
4744
return (int) $this->request('get-last-id')->getValue('id');
4845
}

src/Api/Operator/Ip.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Ip extends \PleskX\Api\Operator
1010
/**
1111
* @return Struct\Info[]
1212
*/
13-
public function get()
13+
public function get(): array
1414
{
1515
$ips = [];
1616
$packet = $this->client->getPacket();

src/Api/Operator/Mail.php

+4-18
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,7 @@
99

1010
class Mail extends Operator
1111
{
12-
/**
13-
* @param string $name
14-
* @param int $siteId
15-
* @param bool $mailbox
16-
* @param string $password
17-
*
18-
* @return Struct\Info
19-
*/
20-
public function create($name, $siteId, $mailbox = false, $password = '')
12+
public function create(string $name, int $siteId, bool $mailbox = false, string $password = ''): Struct\Info
2113
{
2214
$packet = $this->client->getPacket();
2315
$info = $packet->addChild($this->wrapperTag)->addChild('create');
@@ -45,7 +37,7 @@ public function create($name, $siteId, $mailbox = false, $password = '')
4537
*
4638
* @return bool
4739
*/
48-
public function delete(string $field, $value, $siteId): bool
40+
public function delete(string $field, $value, int $siteId): bool
4941
{
5042
$packet = $this->client->getPacket();
5143
$filter = $packet->addChild($this->wrapperTag)->addChild('remove')->addChild('filter');
@@ -58,13 +50,7 @@ public function delete(string $field, $value, $siteId): bool
5850
return 'ok' === (string) $response->status;
5951
}
6052

61-
/**
62-
* @param string $name
63-
* @param int $siteId
64-
*
65-
* @return Struct\GeneralInfo
66-
*/
67-
public function get($name, $siteId)
53+
public function get(string $name, int $siteId): Struct\GeneralInfo
6854
{
6955
$items = $this->getAll($siteId, $name);
7056

@@ -77,7 +63,7 @@ public function get($name, $siteId)
7763
*
7864
* @return Struct\GeneralInfo[]
7965
*/
80-
public function getAll($siteId, $name = null)
66+
public function getAll(int $siteId, $name = null): array
8167
{
8268
$packet = $this->client->getPacket();
8369
$getTag = $packet->addChild($this->wrapperTag)->addChild('get_info');

0 commit comments

Comments
 (0)