Skip to content

Commit

Permalink
PHPStan cleanup pass
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsizemore committed Dec 24, 2023
1 parent daa18cd commit fd74833
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ As an example, let's say you want to get a list of the available platforms. To d
```php
<?php

use Esi\LibrariesIO\Platform\Platform;
use Esi\LibrariesIO\Platform;

$api = new Platform('..yourapikey..', \sys_get_temp_dir());
$response = $api->makeRequest();
Expand Down
7 changes: 4 additions & 3 deletions src/AbstractBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public abstract function makeRequest(string $endpoint, array $options): Response
* Processes the available parameters for a given endpoint.
*
* @param string $endpoint
* @return array<string, array<int, string>|string>
* @return array<string, array<string>|string>
*/
public abstract function endpointParameters(string $endpoint): array;

Expand All @@ -212,6 +212,7 @@ public function processEndpointFormat(string $format, array $options): string
if ($key === 'page' || $key === 'per_page') {
continue;
}
/** @var string $val **/
$format = str_replace(":$key", $val, $format);
}
return $format;
Expand All @@ -221,8 +222,8 @@ public function processEndpointFormat(string $format, array $options): string
* Helper function to make sure that the $options passed to the child class' makeRequest()
* contains the required options listed in the endpoints options.
*
* @param array<string, array<int, string>|string> $endpointOptions
* @param array<string, int|string> $options
* @param array<int, string> $endpointOptions
* @param array<string, int|string> $options
* @return bool
*/
public function verifyEndpointOptions(array $endpointOptions, array $options): bool
Expand Down
3 changes: 3 additions & 0 deletions src/Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
namespace Esi\LibrariesIO;

use InvalidArgumentException;

use Esi\LibrariesIO\{
Exception\RateLimitExceededException,
AbstractBase
Expand Down Expand Up @@ -73,6 +75,7 @@ public function makeRequest(string $endpoint = 'platforms', ?array $options = nu

// Attempt the request
try {
/** @phpstan-ignore-next-line **/
return $this->client->get($endpointParameters['format']);
} catch (ClientException $e) {
if ($e->getResponse()->getStatusCode() === 429) {
Expand Down
3 changes: 2 additions & 1 deletion src/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function makeRequest(string $endpoint, array $options): ResponseInterface
);
}

/** @var array<int, string> $endpointOptions **/
$endpointOptions = $endpointParameters['options'];

if (!parent::verifyEndpointOptions($endpointOptions, $options)) {
Expand Down Expand Up @@ -105,7 +106,7 @@ public function makeRequest(string $endpoint, array $options): ResponseInterface
parent::makeClient($query);

// Attempt the request
$endpointParameters['format'] = parent::processEndpointFormat($endpointParameters['format'], $options);
$endpointParameters['format'] = parent::processEndpointFormat(/** @phpstan-ignore-line **/$endpointParameters['format'], $options);

try {
return $this->client->get($endpointParameters['format']);
Expand Down
5 changes: 3 additions & 2 deletions src/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ final class Repository extends AbstractBase
/**
* {@inheritdoc}
*/
public function makeRequest(string $endpoint, ?array $options = null): ResponseInterface
public function makeRequest(string $endpoint, array $options): ResponseInterface
{
// Make sure we have the format and options for $endpoint
$endpointParameters = $this->endpointParameters($endpoint);
Expand All @@ -73,6 +73,7 @@ public function makeRequest(string $endpoint, ?array $options = null): ResponseI
);
}

/** @var array<int, string> $endpointOptions **/
$endpointOptions = $endpointParameters['options'];

if (!parent::verifyEndpointOptions($endpointOptions, $options)) {
Expand All @@ -89,7 +90,7 @@ public function makeRequest(string $endpoint, ?array $options = null): ResponseI
]);

// Attempt the request
$endpointParameters['format'] = parent::processEndpointFormat($endpointParameters['format'], $options);
$endpointParameters['format'] = parent::processEndpointFormat(/** @phpstan-ignore-line **/$endpointParameters['format'], $options);

try {
return $this->client->get($endpointParameters['format']);
Expand Down
5 changes: 3 additions & 2 deletions src/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ final class User extends AbstractBase
/**
* {@inheritdoc}
*/
public function makeRequest(string $endpoint, ?array $options = null): ResponseInterface
public function makeRequest(string $endpoint, array $options): ResponseInterface
{
// Make sure we have the format and options for $endpoint
$endpointParameters = $this->endpointParameters($endpoint);
Expand All @@ -75,6 +75,7 @@ public function makeRequest(string $endpoint, ?array $options = null): ResponseI
);
}

/** @var array<int, string> $endpointOptions **/
$endpointOptions = $endpointParameters['options'];

if (!parent::verifyEndpointOptions($endpointOptions, $options)) {
Expand All @@ -91,7 +92,7 @@ public function makeRequest(string $endpoint, ?array $options = null): ResponseI
]);

// Attempt the request
$endpointParameters['format'] = parent::processEndpointFormat($endpointParameters['format'], $options);
$endpointParameters['format'] = parent::processEndpointFormat(/** @phpstan-ignore-line **/$endpointParameters['format'], $options);

// Attempt the request
try {
Expand Down

0 comments on commit fd74833

Please sign in to comment.