Skip to content

Commit

Permalink
Fixing return type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
JustSteveKing committed May 7, 2021
1 parent bcd4255 commit 26abacf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
32 changes: 16 additions & 16 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

use Illuminate\Support\Facades\Http;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Http\Client\RequestException;
use JustSteveKing\CompaniesHouse\DTO\Search;
use JustSteveKing\CompaniesHouse\DTO\Company;
use JustSteveKing\CompaniesHouse\DTO\Officer;
use JustSteveKing\CompaniesHouse\Concerns\HasFake;
use JustSteveKing\CompaniesHouse\Collections\SearchCollection;
use JustSteveKing\CompaniesHouse\Actions\Company\CreateCompany;
use JustSteveKing\CompaniesHouse\Actions\Officer\CreateOfficer;
use JustSteveKing\CompaniesHouse\Collections\OfficersCollection;
use JustSteveKing\CompaniesHouse\Actions\Search\CreateSearchResults;
use JustSteveKing\CompaniesHouse\DTO\Company;

class Client
{
Expand Down Expand Up @@ -94,14 +94,14 @@ public function buildRequest(): PendingRequest
*
* @throws Illuminate\Http\Client\RequestException
*
* @return Search
* @return Search|RequestException
*/
public function search(
string $query,
string $prefix = '',
null|int $perPage = null,
null|int $startIndex = null,
): Search {
): Search|RequestException {
$request = $this->buildRequest();

$response = $request->get(
Expand Down Expand Up @@ -133,13 +133,13 @@ public function search(
*
* @throws Illuminate\Http\Client\RequestException
*
* @return Search
* @return Search|RequestException
*/
public function searchCompany(
string $query,
?int $perPage = null,
?int $startIndex = null,
): Search {
): Search|RequestException {
return $this->search(
query: $query,
prefix: 'companies',
Expand All @@ -157,13 +157,13 @@ public function searchCompany(
*
* @throws Illuminate\Http\Client\RequestException
*
* @return Search
* @return Search|RequestException
*/
public function searchOfficers(
string $query,
?int $perPage = null,
?int $startIndex = null,
): Search {
): Search|RequestException {
return $this->search(
query: $query,
prefix: 'officers',
Expand All @@ -181,13 +181,13 @@ public function searchOfficers(
*
* @throws Illuminate\Http\Client\RequestException
*
* @return Search
* @return Search|RequestException
*/
public function searchDisqualifiedOfficers(
string $query,
?int $perPage = null,
?int $startIndex = null,
): Search {
): Search|RequestException {
return $this->search(
query: $query,
prefix: 'disqualified-officers',
Expand All @@ -203,11 +203,11 @@ public function searchDisqualifiedOfficers(
*
* @throws Illuminate\Http\Client\RequestException
*
* @return Company
* @return Company|RequestException
*/
public function company(
string $companyNumber,
): Company {
): Company|RequestException {
$request = $this->buildRequest();

$response = $request->get(
Expand All @@ -234,13 +234,13 @@ public function company(
*
* @throws Illuminate\Http\Client\RequestException
*
* @return OfficersCollection
* @return OfficersCollection|RequestException
*/
public function officers(
string $companyNumber,
null|int $perPage = null,
null|int $startIndex = null,
): OfficersCollection {
): OfficersCollection|RequestException {
$request = $this->buildRequest();

$response = $request->get(
Expand Down Expand Up @@ -284,12 +284,12 @@ public function officers(
*
* @throws Illuminate\Http\Client\RequestException
*
* @return Officer
* @return Officer|RequestException
*/
public function officer(
string $companyNumber,
string $appointmentId
): Officer {
): Officer|RequestException {
$request = $this->buildRequest();

$response = $request->get(
Expand Down
13 changes: 5 additions & 8 deletions src/Rules/CompanyNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Throwable;
use JustSteveKing\CompaniesHouse\Client;
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Http\Client\RequestException;

class CompanyNumber implements Rule
{
Expand All @@ -26,15 +27,11 @@ public function __construct(
*/
public function passes($attributes, $value): bool
{
try {
$response = $this->client->company(
companyNumber: $value,
);
} catch (Throwable) {
return false;
}
$response = $this->client->company(
companyNumber: $value,
);

return true;
return ! ($response instanceof RequestException);
}

/**
Expand Down

0 comments on commit 26abacf

Please # to comment.