Skip to content

Commit

Permalink
Adjust return types
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricius committed Jan 21, 2021
1 parent ce00237 commit 346076e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
.phpunit.result.cache
build
composer.lock
vendor
Expand Down
19 changes: 7 additions & 12 deletions src/BigHugeThesaurusClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public function __construct(string $key)
/**
* Sets the client to be used for querying the API endpoints
*
* @param Client $client
* @param Client|null $client
* @return $this
*/
public function setHttpClient(Client $client = null)
public function setHttpClient(Client $client = null): BigHugeThesaurusClient
{
if ($client === null) {
$client = new Client([
Expand Down Expand Up @@ -113,11 +113,10 @@ public function getBaseUri()
* @param string $word
* @return ThesaurusResponse
* @throws NotFoundException
* @throws RemoteException
* @throws GuzzleException
* @see https://words.bighugelabs.com/api.php
*/
public function lookup(string $word)
public function lookup(string $word): ThesaurusResponse
{
try {
if (!$this->getHttpClient()) {
Expand Down Expand Up @@ -149,7 +148,6 @@ public function lookup(string $word)
*
* @param string $word
* @throws NotFoundException
* @throws RemoteException
* @throws GuzzleException
* @return array
*/
Expand All @@ -165,7 +163,6 @@ public function synonymsOf(string $word): array
*
* @param string $word
* @throws NotFoundException
* @throws RemoteException
* @throws GuzzleException
* @return array
*/
Expand All @@ -181,7 +178,6 @@ public function antonymsOf(string $word): array
*
* @param string $word
* @throws NotFoundException
* @throws RemoteException
* @throws GuzzleException
* @return array
*/
Expand All @@ -197,7 +193,6 @@ public function similarTermsOf(string $word): array
*
* @param string $word
* @throws NotFoundException
* @throws RemoteException
* @throws GuzzleException
* @return array
*/
Expand All @@ -211,20 +206,20 @@ public function relatedTermsOf(string $word): array
/**
* Get the raw response
*
* @return ThesaurusResponse
* @return string
*/
public function getRawResponse()
public function getRawResponse(): string
{
return $this->rawResponse;
}

/**
* Parse the response into a ThesaurusResponse
*
* @param string $response
* @param string $response
* @return ThesaurusResponse
*/
protected function parseResponse($response)
protected function parseResponse(string $response): ThesaurusResponse
{
$parsed = json_decode($response, true);

Expand Down
2 changes: 1 addition & 1 deletion src/ThesaurusResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function toArray(): array
*
* @return string
*/
public function toJson()
public function toJson(): string
{
return json_encode($this->response);
}
Expand Down
5 changes: 4 additions & 1 deletion tests/BigHugeThesaurusClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,16 @@ public function itShouldProvideTheThesaurusResponseIfTheLookupSucceeds()
/** @test */
public function itShouldReturnTheRawResponseFromTheClient()
{
$this->mockHandler->append(new Response(200, [], file_get_contents(__DIR__ . '/fixtures/love.json')));
$response = file_get_contents(__DIR__ . '/fixtures/love.json');

$this->mockHandler->append(new Response(200, [], $response));

$apiClient = $this->createClient('123');

$apiClient->lookup('love');

$this->assertIsString($apiClient->getRawResponse());
$this->assertEquals($response, $apiClient->getRawResponse());
}

/** @test */
Expand Down

0 comments on commit 346076e

Please sign in to comment.