diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 29ef794..2665269 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -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" diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index d267576..31eb003 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -14,7 +14,7 @@ env: jobs: phpunit: name: "PHPUnit (PHP ${{ matrix.php }})" - runs-on: "ubuntu-20.04" + runs-on: "ubuntu-latest" strategy: matrix: @@ -26,7 +26,7 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v4" + uses: "actions/checkout@v5" with: fetch-depth: 2 @@ -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: @@ -58,7 +58,7 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v4" + uses: "actions/checkout@v5" with: fetch-depth: 2 diff --git a/lib/Imgur/Client.php b/lib/Imgur/Client.php index a454dd8..246c6b5 100644 --- a/lib/Imgur/Client.php +++ b/lib/Imgur/Client.php @@ -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]; @@ -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; diff --git a/lib/Imgur/Exception/MissingArgumentException.php b/lib/Imgur/Exception/MissingArgumentException.php index d95d797..b7fc891 100644 --- a/lib/Imgur/Exception/MissingArgumentException.php +++ b/lib/Imgur/Exception/MissingArgumentException.php @@ -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); } } diff --git a/lib/Imgur/Middleware/ErrorMiddleware.php b/lib/Imgur/Middleware/ErrorMiddleware.php index 85d2c43..d1b4a55 100644 --- a/lib/Imgur/Middleware/ErrorMiddleware.php +++ b/lib/Imgur/Middleware/ErrorMiddleware.php @@ -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()); } diff --git a/phpstan.neon b/phpstan.neon index 9744cfb..33a79fe 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -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 diff --git a/tests/Api/AlbumTest.php b/tests/Api/AlbumTest.php index eb51da6..afa418d 100644 --- a/tests/Api/AlbumTest.php +++ b/tests/Api/AlbumTest.php @@ -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); diff --git a/tests/Api/ImageTest.php b/tests/Api/ImageTest.php index 844c624..15c5c72 100644 --- a/tests/Api/ImageTest.php +++ b/tests/Api/ImageTest.php @@ -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);