Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ on:
jobs:
coding-standards:
name: "CS Fixer (PHP ${{ matrix.php }})"
runs-on: "ubuntu-20.04"
runs-on: "ubuntu-latest"

strategy:
matrix:
php:
- "7.4"
- "8.2"

steps:
- name: "Checkout"
uses: "actions/checkout@v4"
uses: "actions/checkout@v5"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:
jobs:
phpunit:
name: "PHPUnit (PHP ${{ matrix.php }})"
runs-on: "ubuntu-20.04"
runs-on: "ubuntu-latest"

strategy:
matrix:
Expand All @@ -26,7 +26,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v4"
uses: "actions/checkout@v5"
with:
fetch-depth: 2

Expand All @@ -49,7 +49,7 @@ jobs:

phpunit-coverage:
name: "PHPUnit with coverage (PHP ${{ matrix.php }})"
runs-on: "ubuntu-20.04"
runs-on: "ubuntu-latest"

strategy:
matrix:
Expand All @@ -58,7 +58,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v4"
uses: "actions/checkout@v5"
with:
fetch-depth: 2

Expand Down
4 changes: 2 additions & 2 deletions lib/Imgur/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function setHttpClient(HttpClientInterface $httpClient): void
public function getOption(string $name): ?string
{
if (!\array_key_exists($name, $this->options)) {
throw new InvalidArgumentException(sprintf('Undefined option called: "%s"', $name));
throw new InvalidArgumentException(\sprintf('Undefined option called: "%s"', $name));
}

return $this->options[$name];
Expand All @@ -100,7 +100,7 @@ public function getOption(string $name): ?string
public function setOption(string $name, ?string $value = null): void
{
if (!\array_key_exists($name, $this->options)) {
throw new InvalidArgumentException(sprintf('Undefined option called: "%s"', $name));
throw new InvalidArgumentException(\sprintf('Undefined option called: "%s"', $name));
}

$this->options[$name] = $value;
Expand Down
2 changes: 1 addition & 1 deletion lib/Imgur/Exception/MissingArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public function __construct($required, int $code = 0)
$required = [$required];
}

parent::__construct(sprintf('One or more of required ("%s") parameters is missing!', implode('", "', $required)), $code);
parent::__construct(\sprintf('One or more of required ("%s") parameters is missing!', implode('", "', $required)), $code);
}
}
11 changes: 11 additions & 0 deletions lib/Imgur/Middleware/ErrorMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ public function checkError(ResponseInterface $response): ?ResponseInterface
throw new ErrorException($message, $response->getStatusCode());
}

if (\is_array($responseData) && isset($responseData['errors'])) {
$errorMessage = $responseData['errors'];

$message = '';
foreach ($responseData['errors'] as $error) {
$message .= $error['detail'];
}

throw new ErrorException($message, $response->getStatusCode());
}

throw new RuntimeException(\is_array($responseData) && isset($responseData['message']) ? $responseData['message'] : $responseData, $response->getStatusCode());
}

Expand Down
10 changes: 7 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ parameters:
- tests

bootstrapFiles:
- vendor/bin/.phpunit/phpunit-8.5-0/vendor/autoload.php

checkMissingIterableValueType: false
- vendor/bin/.phpunit/phpunit-9.6-0/vendor/autoload.php

ignoreErrors:
# because the test is skipped
-
message: '#Unreachable statement#'
path: %currentWorkingDirectory%/tests/Api/TopicTest.php
-
message: '#Unreachable statement#'
path: %currentWorkingDirectory%/tests/Api/ImageTest.php

-
identifier: missingType.iterableValue
2 changes: 1 addition & 1 deletion tests/Api/AlbumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AlbumTest extends ApiTestCase
public function testBaseReal(): void
{
$this->expectException(\Imgur\Exception\ErrorException::class);
$this->expectExceptionMessage('Authentication required');
$this->expectExceptionMessage('The requester is not authorized to access the resource.');

$httpClient = new HttpClient();
$client = new Client(null, $httpClient);
Expand Down
2 changes: 2 additions & 0 deletions tests/Api/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public function testBaseReal(): void
$this->expectException(\Imgur\Exception\ErrorException::class);
$this->expectExceptionMessage('Authentication required');

$this->markTestSkipped('Image endpoint does not always return 401 with no authentication ...');

$httpClient = new HttpClient();
$client = new Client(null, $httpClient);
$image = new Image($client);
Expand Down