diff --git a/composer.json b/composer.json index 3b7f9a3..3a17bf4 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ ], "lint": [ "vendor/bin/parallel-lint --no-colors --exclude vendor .", - "vendor/bin/phpcs --ignore=data,vendor --standard=PSR2 ." + "vendor/bin/phpcs --ignore=data,vendor --standard=PSR12 ." ], "phpstan": [ "vendor/bin/phpstan analyse --memory-limit=2G src" diff --git a/data/iterator/max_page_length.php b/data/iterator/max_page_length.php new file mode 100644 index 0000000..db52421 --- /dev/null +++ b/data/iterator/max_page_length.php @@ -0,0 +1,29 @@ + json_encode(['token' => 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIyMTQ4MzAxZC04Y2MzLTQyNjgtODY5MC00MmI4M2MzNzU4NGUiLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwiaXNzIjoiaHR0cHM6Ly9jb2duaXRvLWlkcC5ldS13ZXN0LTEuYW1hem9uYXdzLmNvbS8iLCJjb2duaXRvOnVzZXJuYW1lIjoiZXhhbXBsZUBleGFtcGxlLm9yZyIsImN1c3RvbTpjc1VzZXJJZCI6IjEyMzQ1NiIsImF1ZCI6IjEyMzQ1NiIsImN1c3RvbTpjc1VzZXJDb3VudHJ5Q29kZSI6IlVLIiwiZXZlbnRfaWQiOiIyMTQ4MzAxZC04Y2MzLTQyNjgtODY5MC00MmI4M2MzNzU4NGYiLCJ0b2tlbl91c2UiOiJpZCIsImF1dGhfdGltZSI6MTU0NDQzNjE4MiwiZXhwIjoxNTQ0NDM5OTU4LCJpYXQiOjE1NDQ0MzYxODIsImVtYWlsIjoiZXhhbXBsZUBleGFtcGxlLm9yZyIsImp0aSI6ImY1NTBhN2I4LTA2OTItNDk1Ny04ZGFiLTFhMjUzN2M3ZDU3MyJ9.xZ_aCeEEq9zweOzm8FqCIhddQ0dWi_c7XyfxOWchSPg']), + ], + [ + 'body' => json_encode([ + 'totalSize' => 32000, + 'companies' => [ + [], + [], + ], + ]), + 'code' => 200, + ], + [ + 'body' => json_encode([ + 'totalSize' => 32000, + 'companies' => [ + [], + [], + ], + ]), + 'code' => 200, + ], + ], +]; diff --git a/src/Client.php b/src/Client.php index 6311e95..7a8bee3 100644 --- a/src/Client.php +++ b/src/Client.php @@ -4,14 +4,12 @@ use Lcobucci\JWT\Parser; use Lcobucci\JWT\Token; -use GuzzleHttp\Psr7; /** - * Client Class used to store data relating to the client created + * Client Class used to store data relating to the client created. */ class Client { - protected $http_client; /** @@ -40,7 +38,8 @@ class Client protected $monitor; /** - * construct function that builds the client class + * construct function that builds the client class. + * * @param array $config creditsafe configuration */ public function __construct(array $config = []) @@ -58,18 +57,18 @@ public function __construct(array $config = []) } /** - * This function is used to authenticate a username and password - * @return void + * This function is used to authenticate a username and password. + * * @throws Exception\Unauthorized if the provided authentication details are not valid */ - public function authenticate() : void + public function authenticate(): void { try { $authenticate = $this->http_client->request('POST', 'authenticate', [ - 'json'=> [ - 'username'=> $this->config['username'], - 'password' => $this->config['password'] - ] + 'json' => [ + 'username' => $this->config['username'], + 'password' => $this->config['password'], + ], ]); } catch (\GuzzleHttp\Exception\ClientException $e) { $message = 'There was a problem authenticating with the Creditsafe API'; @@ -87,31 +86,27 @@ public function authenticate() : void } /** - * set token + * set token. + * * @param string $token Token must be set to have access - * to the api and is only valid for an hour - * @return void + * to the api and is only valid for an hour */ - public function setToken(string $token) : void + public function setToken(string $token): void { $this->token = (new Parser())->parse($token); } - /** - * @return Token - */ - public function getToken() : Token + public function getToken(): Token { return $this->token; } /** - * Checks if token is valid - * @return void + * Checks if token is valid. */ - public function checkToken() : void + public function checkToken(): void { - /** + /* * argument required as of lcobucci/jwt 3.4+ * https://github.com/lcobucci/jwt/commit/2cfa548b3f26176ab3e56a1ff3503b4d0db7ae7c * https://github.com/lcobucci/jwt/issues/550#issuecomment-733557709 @@ -122,20 +117,21 @@ public function checkToken() : void } /** - * This request function handles all requests for the api - * @param string $type Sets the type of HTTP Request e.g GET ,POST - * @param string $endpoint Sets the endpoint - * @param array $params Sets params for a endpoint - * @return array Returns the results of the endpoint + * This request function handles all requests for the api. + * + * @param string $type Sets the type of HTTP Request e.g GET ,POST + * @param string $endpoint Sets the endpoint + * @param array $params Sets params for a endpoint + * + * @return array Returns the results of the endpoint */ - public function request(string $type, string $endpoint, array $params = []) : array + public function request(string $type, string $endpoint, array $params = []): array { - $this->checkToken(); - $guzzleArgs = [ + $guzzleArgs = [ 'headers' => [ - 'Authorization' => (string) $this->token + 'Authorization' => (string) $this->token, ], ]; @@ -179,62 +175,67 @@ public function request(string $type, string $endpoint, array $params = []) : ar throw $exception; } - $res = (array)json_decode((string) $res->getBody(), true); + $res = (array) json_decode((string) $res->getBody(), true); return $res; } /** - * A function that handles the creation of a GET Request - * @param string $endpoint An endpoint used to create an request - * @param array $params Sets params for a endpoint - * @return array Returns the results of the endpoint + * A function that handles the creation of a GET Request. + * + * @param string $endpoint An endpoint used to create an request + * @param array $params Sets params for a endpoint + * + * @return array Returns the results of the endpoint */ - public function get(string $endpoint, array $params = []) : array + public function get(string $endpoint, array $params = []): array { return $this->request('GET', $endpoint, $params); } /** - * Get Company Events + * Get Company Events. + * * @return Service\CompanyEventService Returns Company Events */ - public function monitoring() : Service\CompanyEventService + public function monitoring(): Service\CompanyEventService { if (!isset($this->monitor)) { $this->monitor = new Service\CompanyEventService($this); } + return $this->monitor; } /** - * Get company services + * Get company services. + * * @return Service\CompanyService Returns Company Services */ - public function companies() : Service\CompanyService + public function companies(): Service\CompanyService { if (!isset($this->company)) { $this->company = new Service\CompanyService($this); } + return $this->company; } /** - * Get Countries - * @return Service\CountryService Returns the Countries + * Get Countries. + * + * @return Service\CountryService Returns the Countries */ - public function countries() : Service\CountryService + public function countries(): Service\CountryService { if (!isset($this->countries)) { $this->countries = new Service\CountryService($this); } + return $this->countries; } - /** - * @return array - */ - public function getDefaultConfig() : array + public function getDefaultConfig(): array { return [ 'apiURI' => 'https://connect.creditsafe.com/', @@ -242,28 +243,31 @@ public function getDefaultConfig() : array } /** - * Function gets the base url for the api by concatenating the API URL and the API version + * Function gets the base url for the api by concatenating the API URL and the API version. + * * @return string Returns a string containing the base url */ - public function getBaseURL() : string + public function getBaseURL(): string { - return $this->getApiURL().$this->getApiVersion().'/'; + return $this->getApiURL() . $this->getApiVersion() . '/'; } /** - * Function gets the Api url + * Function gets the Api url. + * * @return string Returns a string containing the api url */ - protected function getApiURL() : string + protected function getApiURL(): string { return $this->config['apiURI']; } /** - * Function gets the Api Version + * Function gets the Api Version. + * * @return string Returns a string containing the Api Version */ - protected function getApiVersion() : string + protected function getApiVersion(): string { return 'v1'; } diff --git a/src/Exception/APIException.php b/src/Exception/APIException.php index 632120e..8562c4c 100644 --- a/src/Exception/APIException.php +++ b/src/Exception/APIException.php @@ -3,26 +3,28 @@ namespace SynergiTech\Creditsafe\Exception; /** - * This class is used to handle API Expections + * This class is used to handle API Expections. */ class APIException extends \RuntimeException { protected $correlationID = null; /** - * Sets the CorrelationID + * Sets the CorrelationID. + * * @param string $correlationID Contains the CorrelationID */ - public function setCorrelationID(string $correlationID) : void + public function setCorrelationID(string $correlationID): void { $this->correlationID = $correlationID; } /** - * Get CorrelationID + * Get CorrelationID. + * * @return ?string Contains the CorrelationID */ - public function getCorrelationID() : ?string + public function getCorrelationID(): ?string { return $this->correlationID; } diff --git a/src/ListResult.php b/src/ListResult.php index ffd6d03..df7437f 100644 --- a/src/ListResult.php +++ b/src/ListResult.php @@ -17,55 +17,65 @@ class ListResult implements \Iterator protected $currentRecordSet = []; protected $maxPageRecord; protected $minPageRecord; + protected $maxAllowedPage = 13; + protected $resultKey; /** - * This constructor is used to build the ListResult - * @param Client $client Used to set the client in the ListResult Class - * @param string $targetClass Used to set a dynamic class in the LisrResult Class - * allowing for ListResult to be used on different classes + * This constructor is used to build the ListResult. + * + * @param Client $client Used to set the client in the ListResult Class + * @param string $targetClass Used to set a dynamic class in the ListResult Class + * allowing for ListResult to be used on different classes * @param string $endpoint Used to set the endpoint for which the ListResult Class is using - * @param array $params Used tp set the params for which the ListResult Class is using + * @param array $params Used to set the params for which the ListResult Class is using + * @param string $resultKey The key in the response to iterate through */ - public function __construct(Client $client, string $targetClass, string $endpoint, array $params) + public function __construct(Client $client, string $targetClass, string $endpoint, array $params, string $resultKey) { $this->client = $client; $this->targetClass = $targetClass; $this->endpoint = $endpoint; $this->params = $params; + $this->resultKey = $resultKey; $this->page(1); } /** - * Set PageSize - * @param int $size Stores the PageSize - * @return self + * Set PageSize. + * + * @param int $size Stores the PageSize */ - public function setPageSize(int $size) : self + public function setPageSize(int $size): self { $this->pageSize = $size; $this->rewind(); + return $this; } /** - * Get Params + * Get Params. + * * @return array Return Params */ - private function getParams() : array + private function getParams(): array { $pageParams = ['page' => $this->currentPagePos]; if ($this->pageSize !== null) { $pageParams['pageSize'] = $this->pageSize; } + return array_merge($this->params, $pageParams); } /** - * Get Page - * @param int $num Passes the page number - * @return array Returns the current Record Set + * Get Page. + * + * @param int $num Passes the page number + * + * @return array Returns the current Record Set */ - public function page(int $num) : array + public function page(int $num): array { if ($num === $this->currentPagePos) { return $this->currentRecordSet; @@ -81,31 +91,33 @@ public function page(int $num) : array } /** - * fetch Page + * Fetch the current page. + * * @return array Returns the results for a page */ - private function fetchPage() : array + private function fetchPage(): array { $results = []; $resultSet = $this->client->get($this->endpoint, $this->getParams()); - foreach ($resultSet['companies'] as $company) { - $results[] = new $this->targetClass($this->client, $company); + + foreach ($resultSet[$this->resultKey] as $result) { + $results[] = new $this->targetClass($this->client, $result); } return $results; } /** - * Rewind to the first page - * @return void + * Rewind to the first page. */ - public function rewind() : void + public function rewind(): void { $this->page(1); } /** - * Get the current page + * Get the current page. + * * @return array */ public function current() @@ -114,32 +126,33 @@ public function current() } /** - * Get the next page - * @return void + * Get the next page. */ - public function next() : void + public function next(): void { - $this->currentRecordPos++; - if ($this->currentRecordPos > $this->maxPageRecord) { - $this->page($this->currentPagePos+1); + ++$this->currentRecordPos; + if ( + $this->currentRecordPos > $this->maxPageRecord + && $this->currentPagePos < $this->maxAllowedPage + ) { + $this->page($this->currentPagePos + 1); } } /** - * Get the key of a position - * @return int + * Get the key of a position. */ - public function key() : int + public function key(): int { - return $this->currentRecordPos - ($this->pageSize * ($this->currentPagePos-1)); + return $this->currentRecordPos - ($this->pageSize * ($this->currentPagePos - 1)); } /** - * Check if a position is valid - * @return bool + * Check if a position is valid. */ - public function valid() : bool + public function valid(): bool { - return !($this->key() >= count($this->currentRecordSet) && count($this->currentRecordSet) != $this->pageSize); + return $this->key() < count($this->currentRecordSet) + && $this->currentPagePos <= $this->maxAllowedPage; } } diff --git a/src/Models/Company.php b/src/Models/Company.php index 36f3833..765d0ac 100644 --- a/src/Models/Company.php +++ b/src/Models/Company.php @@ -5,11 +5,10 @@ use SynergiTech\Creditsafe\Models\Company\CreditScore; /** - * This class contains all data relating to the company + * This class contains all data relating to the company. */ class Company { - protected $client; protected $companyID; protected $businessName; @@ -34,9 +33,10 @@ class Company protected $financialStatements; /** - * Function constructs the Company Class + * Function constructs the Company Class. + * * @param array $client Used to store the client in the Company Class - * @param array $companyDetails Company Data that needs to be stored in the Company Class + * @param array $companyDetails Company Data that needs to be stored in the Company Class */ public function __construct($client, array $companyDetails) { @@ -72,6 +72,7 @@ public function __construct($client, array $companyDetails) $this->history = array_map(function ($history) { $history['date'] = new \DateTime($history['date']); + return $history; }, $companyDetails['report']['additionalInformation']['companyHistory'] ?? []); @@ -91,190 +92,171 @@ public function __construct($client, array $companyDetails) } /** - * * @return string Return Company ID */ - public function getCompanyID() : string + public function getCompanyID(): string { return $this->companyID; } /** - * * @return string Return Business Name */ - public function getBusinessName() : string + public function getBusinessName(): string { return $this->businessName ?? ''; } /** - * * @return string Return Registered Company Name */ - public function getRegisteredCompanyName() : string + public function getRegisteredCompanyName(): string { return $this->registeredCompanyName ?? ''; } /** - * - * @return string Return Company Registeration Number + * @return string Return Company Registeration Number */ - public function getCompanyRegistrationNumber() : string + public function getCompanyRegistrationNumber(): string { return $this->companyRegistrationNumber ?? ''; } /** - * - * @return string Return Country + * @return string Return Country */ - public function getCountry() : string + public function getCountry(): string { return $this->country ?? ''; } /** - * * @return \DateTime Return Company Registration Date */ - public function getCompanyRegistrationDate() : ?\DateTime + public function getCompanyRegistrationDate(): ?\DateTime { return $this->companyRegistrationDate ? new \DateTime($this->companyRegistrationDate) : null; } /** - * * @return array Return Main Address */ - public function getMainAddress() : array + public function getMainAddress(): array { return $this->mainAddress ?? []; } /** - * * @return array Return otherAddresses */ - public function getOtherAddresses() : array + public function getOtherAddresses(): array { return $this->otherAddresses ?? []; } /** - * * @return array | null Return an array of current directors */ - public function getCurrentDirectors() : ?array + public function getCurrentDirectors(): ?array { return $this->currentDirectors; } /** - * * @return array Return an array of previous directors */ - public function getPreviousDirectors() : array + public function getPreviousDirectors(): array { return $this->previousDirectors ?? []; } /** - * * @return array Return an array of the whole company request */ - public function getRawDetails() : array + public function getRawDetails(): array { return $this->rawDetails ?? []; } /** - * * @return CreditScore Returns the CreditScore of the company */ - public function getCreditScore() : CreditScore + public function getCreditScore(): CreditScore { return $this->creditScore; } /** - * * @return array Returns a array of Shareholders for the company */ - public function getShareHolders() : array + public function getShareHolders(): array { return $this->shareholders ?? []; } /** - * * @return array Returns the commentaries of the company */ - public function getCommentaries() : array + public function getCommentaries(): array { return $this->commentaries ?? []; } /** - * * @return array Return the history of the company */ - public function getHistory() : array + public function getHistory(): array { return $this->history ?? []; } /** - * * @return array Return the mortgages summary */ - public function getMortgageSummary() : array + public function getMortgageSummary(): array { return $this->mortgageSummary ?? []; } /** - * * @return array Return all company mortgages */ - public function getMortgages() : ?array + public function getMortgages(): ?array { return $this->mortgages; } /** - * * @return array | null Get Negative Information */ - public function getNegativeInformation() : array + public function getNegativeInformation(): array { return $this->negativeInfo ?? []; } /** - * Gets financialStatements + * Gets financialStatements. + * * @return array Returns an array of financial statements */ - public function getFinancialStatements() : array + public function getFinancialStatements(): array { return $this->financialStatements ?? []; } /** - * * @return array Returns an array which ocontains the currency and value of shares */ - public function getIssuedShareCapital() : array + public function getIssuedShareCapital(): array { return $this->issuedShareCapital ?? []; } /** - * - * @return string Returns the number of shares issued + * @return string Returns the number of shares issued */ - public function getNumberOfSharesIssued() : ?int + public function getNumberOfSharesIssued(): ?int { return $this->numberOfSharesIssued; } diff --git a/src/Models/Company/CreditScore.php b/src/Models/Company/CreditScore.php index 47046de..f60faaa 100644 --- a/src/Models/Company/CreditScore.php +++ b/src/Models/Company/CreditScore.php @@ -5,7 +5,7 @@ use SynergiTech\Creditsafe\Models\Company; /** - * This class contains all data relating to the CreditScore and Company + * This class contains all data relating to the CreditScore and Company. */ class CreditScore { @@ -16,9 +16,10 @@ class CreditScore protected $latestRatingChangeDate; /** - * Function constructs the CreditScore Class + * Function constructs the CreditScore Class. + * * @param Company $company Used to store a company data in the creditScore Class - * @param array $creditScore CreditScore Data that needs to be stored in the creditScore Class + * @param array $creditScore CreditScore Data that needs to be stored in the creditScore Class */ public function __construct(Company $company, array $creditScore) { @@ -33,38 +34,34 @@ public function __construct(Company $company, array $creditScore) } /** - * * @return array | null Returns the currentCreditRating data as an array */ - public function getCurrentCreditRating() : ?array + public function getCurrentCreditRating(): ?array { return $this->currentCreditRating; } /** - * * @return array | null Returns the currentContractLimit data as an array */ - public function getCurrentContractLimit() : ?array + public function getCurrentContractLimit(): ?array { return $this->currentContractLimit; } /** - * * @return array | null Returns the previousCreditRating data as an array */ - public function getPreviousCreditRating() : ?array + public function getPreviousCreditRating(): ?array { return $this->previousCreditRating; } /** - * - * @return \DateTime | null Returns the LastestRatingChangeDate in DateTime + * @return \DateTime | null Returns the LastestRatingChangeDate in DateTime */ - public function getLatestRatingChangeDate() : ?\DateTime + public function getLatestRatingChangeDate(): ?\DateTime { - return $this->latestRatingChangeDate; + return $this->latestRatingChangeDate; } } diff --git a/src/Models/Company/Director.php b/src/Models/Company/Director.php index c3c4eef..6609d97 100644 --- a/src/Models/Company/Director.php +++ b/src/Models/Company/Director.php @@ -5,7 +5,7 @@ use SynergiTech\Creditsafe\Models\Company; /** - * This class contains all data relating to the Director and Company + * This class contains all data relating to the Director and Company. */ class Director { @@ -14,71 +14,72 @@ class Director protected $current; /** - * Function constructs the Director Class + * Function constructs the Director Class. + * * @param Company $company Used to store a company data in the Director Class - * @param array $directorDetails Directors Data that needs to be stored in the Director Class - * @param bool $current Boolean used to indicate if the director is a current or previous director + * @param array $directorDetails Directors Data that needs to be stored in the Director Class + * @param bool $current Boolean used to indicate if the director is a current or previous director */ public function __construct(Company $company, array $directorDetails, bool $current) { $this->company = $company; $this->directorDetails = $directorDetails; if (isset($this->directorDetails['dateOfBirth'])) { - $this->directorDetails['dateOfBirth'] = new \DateTime($this->directorDetails['dateOfBirth']); + $this->directorDetails['dateOfBirth'] = new \DateTime($this->directorDetails['dateOfBirth']); } $this->directorDetails['positions'] = array_map(function ($position) { //Add if statement to check if position exists if (isset($position['dateAppointed'])) { - //Can't assign datetime due to previousDirectors not having dateAppointed + //Can't assign datetime due to previousDirectors not having dateAppointed $position['dateAppointed'] = new \DateTime($position['dateAppointed']); } + return $position; }, $this->directorDetails['positions']); $this->current = $current; } /** - * Checks if the director is a current director - * @return boolean Returns if the current variable is true + * Checks if the director is a current director. + * + * @return bool Returns if the current variable is true */ - public function isCurrent() : bool + public function isCurrent(): bool { return $this->current === true; } /** - * Checks if the director is a previous director - * @return boolean Return if the previous variable is not true + * Checks if the director is a previous director. + * + * @return bool Return if the previous variable is not true */ - public function isPrevious() : bool + public function isPrevious(): bool { return $this->current !== true; } /** - * * @return string Returns the Directors ID */ - public function getID() : string + public function getID(): string { return $this->directorDetails['id'] ?? ''; } /** - * * @return string Returns the gender of the Director */ - public function getGender() : string + public function getGender(): string { return $this->directorDetails['gender'] ?? ''; } /** - * * @return DateTime | null Returns the Date Of Birth of the Director */ - public function getDateOfBirth() : ?\DateTime + public function getDateOfBirth(): ?\DateTime { if (isset($this->directorDetails['dateOfBirth'])) { return $this->directorDetails['dateOfBirth']; @@ -88,28 +89,25 @@ public function getDateOfBirth() : ?\DateTime } /** - * * @return array Returns an array containing the position and the date appointed */ - public function getPositions() : array + public function getPositions(): array { return $this->directorDetails['positions'] ?? []; } /** - * * @return string Returns the directors name */ - public function getName() : string + public function getName(): string { return $this->directorDetails['name'] ?? ''; } /** - * * @return array Returns the directors address in an array */ - public function getAddress() : array + public function getAddress(): array { return $this->directorDetails['address'] ?? []; } diff --git a/src/Models/Company/FinancialStatement.php b/src/Models/Company/FinancialStatement.php index 272759d..841aa57 100644 --- a/src/Models/Company/FinancialStatement.php +++ b/src/Models/Company/FinancialStatement.php @@ -5,18 +5,18 @@ use SynergiTech\Creditsafe\Models\Company; /** - * This class contains all data relating to the FinancialStatement and Company + * This class contains all data relating to the FinancialStatement and Company. */ class FinancialStatement { - protected $company; protected $statementDetails; /** - * Function constructs the FinancialStatement Class + * Function constructs the FinancialStatement Class. + * * @param Company $company Used to store a company data in the Director Class - * @param array $statementDetails Financial Statement Data that needs to be stored in the FinancialStatement Class + * @param array $statementDetails Financial Statement Data that needs to be stored in the FinancialStatement Class */ public function __construct(Company $company, $statementDetails) { @@ -26,19 +26,17 @@ public function __construct(Company $company, $statementDetails) } /** - * * @return array Returns an array of profile and loss variables */ - public function getProfitAndLoss() : array + public function getProfitAndLoss(): array { return $this->statementDetails['profitAndLoss'] ?? []; } /** - * * @return array Returns an array of variables relating to a balanceSheet */ - public function getBalanceSheet() : array + public function getBalanceSheet(): array { return $this->statementDetails['balanceSheet'] ?? []; } @@ -46,79 +44,71 @@ public function getBalanceSheet() : array /** * @return string Return contingentLiabilities */ - public function getContingentLiabilities() : string + public function getContingentLiabilities(): string { return $this->statementDetails['otherFinancials']['contingentLiabilities'] ?? ''; } /** - * * @return float | null Return workingCapital */ - public function getWorkingCapital() : ?float + public function getWorkingCapital(): ?float { return $this->statementDetails['otherFinancials']['workingCapital']; } /** - * * @return float | null Return net worth */ - public function getNetWorth() : ?float + public function getNetWorth(): ?float { return $this->statementDetails['otherFinancials']['netWorth']; } /** - * * @return array Get Ratio statistics like currentratio , currentdebtratio etc */ - public function getRatios() : array + public function getRatios(): array { return $this->statementDetails['ratios'] ?? []; } /** - * * @return \DateTime | null Get the Financial Year End Date */ - public function getYearEndDate() : ?\DateTime + public function getYearEndDate(): ?\DateTime { return $this->statementDetails['yearEndDate']; } /** - * * @return int | null Gets the number of accountable weeks */ - public function getNumberOfWeeks() : ?int + public function getNumberOfWeeks(): ?int { return $this->statementDetails['numberOfWeeks']; } /** - * * @return string Returns the Currency as a string */ - public function getCurrency() : string + public function getCurrency(): string { return $this->statementDetails['currency'] ?? []; } /** - * * @return bool Returns true or false if consolidated Accounts */ - public function getConsolidatedAccounts() : bool + public function getConsolidatedAccounts(): bool { return $this->statementDetails['consolidatedAccounts']; } /** - * * @return string Return Type */ - public function getType() : string + public function getType(): string { return $this->statementDetails['type'] ?? []; } diff --git a/src/Models/Company/Shareholder.php b/src/Models/Company/Shareholder.php index d3c11c9..38563fd 100644 --- a/src/Models/Company/Shareholder.php +++ b/src/Models/Company/Shareholder.php @@ -5,17 +5,18 @@ use SynergiTech\Creditsafe\Models\Company; /** - * [Shareholder description] + * [Shareholder description]. */ class Shareholder { protected $company; protected $shareholderDetails; + /** - * [__construct description] + * [__construct description]. + * * @param Company $company Used to store the client in the Company Class * @param array $shareholderDetails Shareholder Data that needs to be stored in the Shareholder Class - */ public function __construct(Company $company, array $shareholderDetails) { @@ -28,46 +29,41 @@ public function __construct(Company $company, array $shareholderDetails) } /** - * * @return string Returns Shareholder Name */ - public function getShareHolderName() : string + public function getShareHolderName(): string { return $this->shareholderDetails['name'] ?? ''; } /** - * * @return string Returns the type of shareholder */ - public function getshareholderType() : string + public function getshareholderType(): string { return $this->shareholderDetails['shareholderType'] ?? ''; } /** - * * @return string Returns the shareholder percetage */ - public function getShareHolderPercentage() : string + public function getShareHolderPercentage(): string { return $this->shareholderDetails['percentSharesHeld'] ?? ''; } /** - * * @return string Returns the num of shares owned */ - public function getNumOfSharesOwned() : string + public function getNumOfSharesOwned(): string { - return $this->shareholderDetails['numberOfSharesOwned'] ?? '' ; + return $this->shareholderDetails['numberOfSharesOwned'] ?? ''; } /** - * * @return string Returns the share type */ - public function getShareType() : string + public function getShareType(): string { return $this->shareholderDetails['shareType'] ?? ''; } diff --git a/src/Models/CompanySearchResult.php b/src/Models/CompanySearchResult.php index 44a7bbe..7f8f2d7 100644 --- a/src/Models/CompanySearchResult.php +++ b/src/Models/CompanySearchResult.php @@ -101,7 +101,7 @@ public function __construct($client, array $companyDetails) * * @return string Get ID */ - public function getID() : string + public function getID(): string { return $this->id; } @@ -110,7 +110,7 @@ public function getID() : string * Get Country * @return string Get Country */ - public function getCountry() : string + public function getCountry(): string { return $this->country ?? ''; } @@ -119,7 +119,7 @@ public function getCountry() : string * * @return string Get Reference Number */ - public function getRefNo() : string + public function getRefNo(): string { return $this->regNo ?? ''; } @@ -128,7 +128,7 @@ public function getRefNo() : string * * @return string Get Safe Number */ - public function getSafeNo() : string + public function getSafeNo(): string { return $this->safeNo ?? ''; } @@ -137,7 +137,7 @@ public function getSafeNo() : string * * @return string Get Company Name */ - public function getName() : string + public function getName(): string { return $this->name ?? ''; } @@ -146,7 +146,7 @@ public function getName() : string * * @return array Get Address */ - public function getAddress() : array + public function getAddress(): array { return $this->address ?? []; } @@ -155,7 +155,7 @@ public function getAddress() : array * * @return string Get Status */ - public function getStatus() : string + public function getStatus(): string { return $this->status ?? ''; } @@ -164,7 +164,7 @@ public function getStatus() : string * * @return string Get Type */ - public function getType() : string + public function getType(): string { return $this->type ?? ''; } @@ -172,7 +172,7 @@ public function getType() : string /** * @return string Get OfficeType */ - public function getOfficeType() : string + public function getOfficeType(): string { return $this->officeType ?? ''; } @@ -180,7 +180,7 @@ public function getOfficeType() : string /** * @return array */ - public function getTradingNames() : array + public function getTradingNames(): array { return $this->tradingNames ?? []; } @@ -188,7 +188,7 @@ public function getTradingNames() : array /** * @return array */ - public function getVatNo() : array + public function getVatNo(): array { return $this->vatNo ?? []; } @@ -197,7 +197,7 @@ public function getVatNo() : array * * @return DateTime Get Date Of Latest Change */ - public function getDateOfLatestChange() : \DateTime + public function getDateOfLatestChange(): \DateTime { return new \DateTime($this->dateOfLatestChange); } @@ -205,7 +205,7 @@ public function getDateOfLatestChange() : \DateTime * Gets the company from a company searches result * @return Company Returns the Company Report */ - public function get() : Company + public function get(): Company { return $this->client->companies()->get($this->getID()); } diff --git a/src/Service/CompanyEventService.php b/src/Service/CompanyEventService.php index c1b9754..ae94e83 100644 --- a/src/Service/CompanyEventService.php +++ b/src/Service/CompanyEventService.php @@ -5,7 +5,7 @@ use SynergiTech\Creditsafe\Client; /** - * This class is used to call the Company Events Endpoint + * This class is used to call the Company Events Endpoint. */ class CompanyEventService { @@ -13,7 +13,8 @@ class CompanyEventService protected $id; /** - * This Constructor builds the CompaniesEvents Class + * This Constructor builds the CompaniesEvents Class. + * * @param array $client This variable stores the client in the CompaniesEvents Class */ public function __construct(Client $client) @@ -22,13 +23,15 @@ public function __construct(Client $client) } /** - * This function gets the companies Events endpoint - * @param string $id The ID of the company events we are searching for - * @param array $params Params for the endpoint - * @return array Returns the results of the endpoint + * This function gets the companies Events endpoint. + * + * @param string $id The ID of the company events we are searching for + * @param array $params Params for the endpoint + * + * @return array Returns the results of the endpoint */ - public function companyEvents(string $id, array $params) : array + public function companyEvents(string $id, array $params): array { - return $this->client->get('monitoring/companies/'.$id.'/events', $params); + return $this->client->get('monitoring/companies/' . $id . '/events', $params); } } diff --git a/src/Service/CompanyService.php b/src/Service/CompanyService.php index e8711b1..d2439e9 100644 --- a/src/Service/CompanyService.php +++ b/src/Service/CompanyService.php @@ -2,12 +2,12 @@ namespace SynergiTech\Creditsafe\Service; -use \SynergiTech\Creditsafe\ListResult; -use \SynergiTech\Creditsafe\Models\CompanySearchResult; -use \SynergiTech\Creditsafe\Models\Company; +use SynergiTech\Creditsafe\ListResult; +use SynergiTech\Creditsafe\Models\Company; +use SynergiTech\Creditsafe\Models\CompanySearchResult; /** - * This class is used by the client to call endpoints relating to a company + * This class is used by the client to call endpoints relating to a company. */ class CompanyService { @@ -15,7 +15,8 @@ class CompanyService protected $id; /** - * This constructor builds the CompanyServices Class + * This constructor builds the CompanyServices Class. + * * @param array $client This variable stores the client in the CompanyServices Class */ public function __construct($client) @@ -24,34 +25,40 @@ public function __construct($client) } /** - * This function is used to call the endpoint that searchs for companies - * @param array $params Contains params that can be passed to the endpoint - * @return array Returns the results of the search endpoint + * This function is used to call the endpoint that searchs for companies. + * + * @param array $params Contains params that can be passed to the endpoint + * + * @return array Returns the results of the search endpoint */ - public function search(array $params) : ListResult + public function search(array $params): ListResult { - $list = new ListResult($this->client, CompanySearchResult::class, 'companies', $params); + $list = new ListResult($this->client, CompanySearchResult::class, 'companies', $params, 'companies'); + return $list; } /** - * This function is used to call the endpoint that gets the company report + * This function is used to call the endpoint that gets the company report. + * * @param string $id The ID of the given company that you want to get a report for - * @param string $reportLang + * * @return Company Returns the results of the get endpoint */ - public function get(string $id, string $reportLang = 'en') : Company + public function get(string $id, string $reportLang = 'en'): Company { - return new Company($this->client, $this->client->get('companies/'.$id, ['language' => $reportLang])); + return new Company($this->client, $this->client->get('companies/' . $id, ['language' => $reportLang])); } /** * This function is used to call the endpoint that gets the search Criteria - * for companies based on the country code given - * @param array $params Contains params that can be passed to the endpoint - * @return array Returns the results of the searchCriteria endpoint + * for companies based on the country code given. + * + * @param array $params Contains params that can be passed to the endpoint + * + * @return array Returns the results of the searchCriteria endpoint */ - public function searchCriteria(array $params) :array + public function searchCriteria(array $params): array { return $this->client->get('companies/searchcriteria', $params); } diff --git a/tests/ListResultTest.php b/tests/ListResultTest.php new file mode 100644 index 0000000..8ebf351 --- /dev/null +++ b/tests/ListResultTest.php @@ -0,0 +1,32 @@ + $guzzle, + ]); + + $iterator = $client->companies()->search([ + 'countries' => 'GB', + 'name' => 'Test', + ]); + + $this->assertInstanceOf(\Iterator::class, $iterator); + + $array = iterator_to_array($iterator); + } + + public function providerMaxPageLength() + { + return $this->dataToGuzzleMock(require 'data/iterator/max_page_length.php'); + } +}