Skip to content

Commit 89cf59d

Browse files
committed
Added type hints and removed useless docs
1 parent 39d226e commit 89cf59d

File tree

6 files changed

+33
-108
lines changed

6 files changed

+33
-108
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
77
### Added
88

99
- Added Easy Coding Standard.
10+
- Added type hints and removed useless docs.
1011

1112
### Fixed
1213

src/Client.php

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -42,66 +42,39 @@ final class Client implements ClientInterface
4242
*/
4343
private $guzzleClient;
4444

45-
/**
46-
* @param string $apiUrl
47-
* @param string $apiKey
48-
* @param GuzzleClientInterface|null $guzzleClient
49-
*/
50-
public function __construct($apiUrl, $apiKey, ?GuzzleClientInterface $guzzleClient = null)
45+
public function __construct(string $apiUrl, string $apiKey, ?GuzzleClientInterface $guzzleClient = null)
5146
{
5247
$this->apiUrl = $apiUrl . '/api/3/';
5348
$this->apiKey = $apiKey;
5449
$this->guzzleClient = $guzzleClient ?: new GuzzleClient();
5550
}
5651

57-
/**
58-
* @inheritdoc
59-
*/
60-
public function get($path)
52+
public function get(string $path): Result
6153
{
6254
return $this->sendRequest('GET', $path);
6355
}
6456

65-
/**
66-
* @inheritdoc
67-
*/
68-
public function post($path, array $body)
57+
public function post(string $path, array $body): Result
6958
{
7059
return $this->sendRequest('POST', $path, $body);
7160
}
7261

73-
/**
74-
* @inheritdoc
75-
*/
76-
public function put($path, array $body)
62+
public function put(string $path, array $body): Result
7763
{
7864
return $this->sendRequest('PUT', $path, $body);
7965
}
8066

81-
/**
82-
* @inheritdoc
83-
*/
84-
public function delete($path)
67+
public function delete(string $path): Result
8568
{
8669
return $this->sendRequest('DELETE', $path);
8770
}
8871

89-
/**
90-
* @inheritdoc
91-
*/
92-
public function testCredentials()
72+
public function testCredentials(): bool
9373
{
9474
return $this->sendRequest('GET', 'users/me')->isSuccessful();
9575
}
9676

97-
/**
98-
* @param string $method
99-
* @param string $path
100-
* @param array $data
101-
* @return Result
102-
* @throws GuzzleException
103-
*/
104-
private function sendRequest($method, $path, ?array $data = null)
77+
private function sendRequest(string $method, string $path, ?array $data = null): Result
10578
{
10679
$uri = $this->apiUrl . $path;
10780

src/ClientInterface.php

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,13 @@
1818
*/
1919
interface ClientInterface
2020
{
21-
/**
22-
* @param string $path
23-
* @return Result
24-
*/
25-
public function get($path);
21+
public function get(string $path): Result;
2622

27-
/**
28-
* @param string $path
29-
* @param array $body
30-
* @return Result
31-
*/
32-
public function post($path, array $body);
23+
public function post(string $path, array $body): Result;
3324

34-
/**
35-
* @param string $path
36-
* @param array $body
37-
* @return Result
38-
*/
39-
public function put($path, array $body);
25+
public function put(string $path, array $body): Result;
4026

41-
/**
42-
* @param string $path
43-
* @return Result
44-
*/
45-
public function delete($path);
27+
public function delete(string $path): Result;
4628

47-
/**
48-
* @return bool
49-
*/
50-
public function testCredentials();
29+
public function testCredentials(): bool;
5130
}

src/Result.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
namespace MetaLine\ActiveCampaign;
1313

14-
/**
15-
* Result
16-
*/
1714
final class Result
1815
{
1916
/**
@@ -31,12 +28,7 @@ final class Result
3128
*/
3229
private $errors = [];
3330

34-
/**
35-
* @param bool $successful
36-
* @param array $result
37-
* @param array $errors
38-
*/
39-
public function __construct($successful = true, array $result = [], array $errors = [])
31+
public function __construct(bool $successful = true, array $result = [], array $errors = [])
4032
{
4133
$this->successful = $successful;
4234

@@ -49,10 +41,8 @@ public function __construct($successful = true, array $result = [], array $error
4941

5042
/**
5143
* Returns true if the client response is successful, false otherwise.
52-
*
53-
* @return bool
5444
*/
55-
public function isSuccessful()
45+
public function isSuccessful(): bool
5646
{
5747
return $this->successful;
5848
}
@@ -61,10 +51,8 @@ public function isSuccessful()
6151
* Returns the data returned from the client call.
6252
*
6353
* If the result is failed, this method returns an empty array.
64-
*
65-
* @return array
6654
*/
67-
public function getData()
55+
public function getData(): array
6856
{
6957
return $this->data;
7058
}
@@ -73,10 +61,8 @@ public function getData()
7361
* Returns the errors returned from the client call.
7462
*
7563
* If the result is successful, this method returns an empty array.
76-
*
77-
* @return array
7864
*/
79-
public function getErrors()
65+
public function getErrors(): array
8066
{
8167
return $this->errors;
8268
}

tests/ClientTest.php

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class ClientTest extends TestCase
3535
/**
3636
* Tests a API call with GET method.
3737
*/
38-
public function testGet()
38+
public function testGet(): void
3939
{
4040
$client = $this->createClient(new Response(200, [], '{"foo":"baz"}'));
4141
$result = $client->get('test');
@@ -49,7 +49,7 @@ public function testGet()
4949
/**
5050
* Tests a API call with POST method.
5151
*/
52-
public function testPost()
52+
public function testPost(): void
5353
{
5454
$client = $this->createClient(new Response(200, [], '{"foo":"baz"}'));
5555
$result = $client->post('test', ['key' => 'value']);
@@ -68,7 +68,7 @@ public function testPost()
6868
/**
6969
* Tests a API call with PUT method.
7070
*/
71-
public function testPut()
71+
public function testPut(): void
7272
{
7373
$client = $this->createClient(new Response(200, [], '{"foo":"baz"}'));
7474
$result = $client->put('test', ['key' => 'value']);
@@ -82,7 +82,7 @@ public function testPut()
8282
/**
8383
* Tests a API call with DELETE method.
8484
*/
85-
public function testDelete()
85+
public function testDelete(): void
8686
{
8787
$client = $this->createClient(new Response(200, [], '{"foo":"baz"}'));
8888
$result = $client->delete('test');
@@ -96,7 +96,7 @@ public function testDelete()
9696
/**
9797
* Tests API calls that returns errors.
9898
*/
99-
public function testGenericErrors()
99+
public function testGenericErrors(): void
100100
{
101101
$client = $this->createClient(new Response(400));
102102
$result = $client->get('test');
@@ -106,7 +106,7 @@ public function testGenericErrors()
106106
$this->assertEquals([], $result->getErrors());
107107
}
108108

109-
public function testMessageError()
109+
public function testMessageError(): void
110110
{
111111
$client = $this->createClient(
112112
new Response(404, [], '{"message":"No Result found for Subscriber with id 18"}'),
@@ -132,7 +132,7 @@ public function testMessageError()
132132
*
133133
* @link https://developers.activecampaign.com/reference#errors
134134
*/
135-
public function testExplainedErrors()
135+
public function testExplainedErrors(): void
136136
{
137137
$client = $this->createClient(new Response(
138138
400,
@@ -164,7 +164,7 @@ public function testExplainedErrors()
164164
$this->assertEquals($errors, $result->getErrors());
165165
}
166166

167-
public function testGenericGuzzleException()
167+
public function testGenericGuzzleException(): void
168168
{
169169
$client = $this->createClient(new GenericGuzzleException('The exception message'));
170170
$result = $client->get('test');
@@ -182,23 +182,19 @@ public function testGenericGuzzleException()
182182
$this->assertEquals($errors, $result->getErrors());
183183
}
184184

185-
public function testCorrectCredentials()
185+
public function testCorrectCredentials(): void
186186
{
187187
$client = $this->createClient(new Response(200, [], '{"user":{}}'));
188188
$this->assertTrue($client->testCredentials());
189189
}
190190

191-
public function testWrongCredentials()
191+
public function testWrongCredentials(): void
192192
{
193193
$client = $this->createClient(new Response(403));
194194
$this->assertFalse($client->testCredentials());
195195
}
196196

197-
/**
198-
* @param mixed $expectedResponse
199-
* @return GuzzleClient
200-
*/
201-
private function createGuzzleClient($expectedResponse)
197+
private function createGuzzleClient($expectedResponse): GuzzleClient
202198
{
203199
$mock = new MockHandler([
204200
$expectedResponse,
@@ -212,11 +208,7 @@ private function createGuzzleClient($expectedResponse)
212208
return new GuzzleClient(['handler' => $handler]);
213209
}
214210

215-
/**
216-
* @param mixed $expectedResponse
217-
* @return Client
218-
*/
219-
private function createClient($expectedResponse)
211+
private function createClient($expectedResponse): Client
220212
{
221213
return new Client(
222214
'http://example.com',
@@ -225,13 +217,7 @@ private function createClient($expectedResponse)
225217
);
226218
}
227219

228-
/**
229-
* @param RequestInterface $request
230-
* @param string $method
231-
* @param string $uri
232-
* @param string $body
233-
*/
234-
private function assertRequest(RequestInterface $request, $method, $uri, $body = null)
220+
private function assertRequest(RequestInterface $request, string $method, string $uri, string $body = null): void
235221
{
236222
$this->assertEquals($method, $request->getMethod());
237223
$this->assertEquals($uri, $request->getUri()->__toString());

tests/ResultTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
final class ResultTest extends TestCase
2121
{
22-
public function testDefault()
22+
public function testDefault(): void
2323
{
2424
$result = new Result();
2525

@@ -28,7 +28,7 @@ public function testDefault()
2828
$this->assertEquals([], $result->getErrors());
2929
}
3030

31-
public function testWithData()
31+
public function testWithData(): void
3232
{
3333
$data = ['foo' => 'bar'];
3434
$result = new Result(true, $data);
@@ -38,7 +38,7 @@ public function testWithData()
3838
$this->assertEquals([], $result->getErrors());
3939
}
4040

41-
public function testWithErrors()
41+
public function testWithErrors(): void
4242
{
4343
$data = ['foo' => 'bar'];
4444
$result = new Result(false, [], $data);

0 commit comments

Comments
 (0)