diff --git a/.php_cs b/.php_cs index dd317cd..5184eaf 100644 --- a/.php_cs +++ b/.php_cs @@ -1,20 +1,45 @@ setUsingCache(true) - ->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL) - // use default SYMFONY_LEVEL and extra fixers: - ->fixers(array( - 'concat_with_spaces', - 'ordered_use', - 'phpdoc_order', - 'strict', - 'strict_param', - 'short_array_syntax', - )) - ->finder( - Symfony\CS\Finder::create() +return PhpCsFixer\Config::create() + ->setRiskyAllowed(true) + ->setRules([ + '@Symfony' => true, + '@Symfony:risky' => true, + 'array_syntax' => [ + 'syntax' => 'short' + ], + 'combine_consecutive_unsets' => true, + 'heredoc_to_nowdoc' => true, + 'no_extra_consecutive_blank_lines' => [ + 'break', + 'continue', + 'extra', + 'return', + 'throw', + 'use', + 'parenthesis_brace_block', + 'square_brace_block', + 'curly_brace_block' + ], + 'no_unreachable_default_argument_value' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'ordered_class_elements' => true, + 'ordered_imports' => true, + 'php_unit_strict' => true, + 'phpdoc_order' => true, + // 'psr4' => true, + 'strict_comparison' => true, + 'strict_param' => true, + 'concat_space' => [ + 'spacing' => 'one' + ], + ]) + ->setFinder( + PhpCsFixer\Finder::create() + ->exclude([ + 'vendor', + ]) ->in(__DIR__) - ->exclude(array('vendor')) ) ; diff --git a/.travis.yml b/.travis.yml index 491012a..b668bcf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,21 +1,20 @@ language: php php: - - 5.5 - 5.6 - 7.0 - 7.1 + - 7.2 + - 7.3 - nightly - - hhvm # run build against nightly but allow them to fail matrix: fast_finish: true include: - - php: 7.0 + - php: 7.2 env: CS_FIXER=run allow_failures: - - php: hhvm - php: nightly # faster builds on new travis setup not using sudo @@ -34,7 +33,7 @@ before_script: - composer install --prefer-dist --no-interaction script: - - phpunit --coverage-clover=coverage.clover + - ./vendor/bin/simple-phpunit -v --coverage-clover=coverage.clover - if [ "$CS_FIXER" = "run" ]; then php vendor/bin/php-cs-fixer fix --verbose --dry-run ; fi; after_script: diff --git a/README.md b/README.md index d7fcbff..1260f8b 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Uses [Imgur API v3](https://api.imgur.com/). * Branch [2.x](https://github.com/j0k3r/php-imgur-api-client/tree/2.x) use Guzzle 5 * Branch [3.x](https://github.com/j0k3r/php-imgur-api-client/tree/3.x) use Guzzle 6 -All actives branches required PHP >= 5.5 +All actives branches required PHP >= 5.6 ## Composer @@ -52,7 +52,7 @@ if (isset($_SESSION['token'])) { $client->setAccessToken($_SESSION['token']); if ($client->checkAccessTokenExpired()) { - $client->refreshToken(); + $client->refreshToken(); } } elseif (isset($_GET['code'])) { $client->requestAccessToken($_GET['code']); diff --git a/composer.json b/composer.json index 5dd2197..10bb460 100644 --- a/composer.json +++ b/composer.json @@ -34,12 +34,13 @@ } }, "require": { - "php": ">=5.5.0", + "php": ">=5.6.0", "ext-curl": "*", "guzzlehttp/guzzle": "^5.3.1" }, "require-dev": { - "friendsofphp/php-cs-fixer": "~1.9" + "friendsofphp/php-cs-fixer": "~2.11", + "symfony/phpunit-bridge": "^4.0" }, "extra": { "branch-alias": { diff --git a/lib/Imgur/Api/AbstractApi.php b/lib/Imgur/Api/AbstractApi.php index 7b5d376..57a6b3b 100644 --- a/lib/Imgur/Api/AbstractApi.php +++ b/lib/Imgur/Api/AbstractApi.php @@ -98,20 +98,6 @@ public function delete($url, $parameters = []) return $httpClient->parseResponse($response); } - /** - * Global method to validate an argument. - * - * @param string $type The required parameter (used for the error message) - * @param string $input Input value - * @param array $possibleValues Possible values for this argument - */ - private function validateArgument($type, $input, $possibleValues) - { - if (!in_array($input, $possibleValues, true)) { - throw new InvalidArgumentException($type . ' parameter "' . $input . '" is wrong. Possible values are: ' . implode(', ', $possibleValues)); - } - } - /** * Validate "sort" parameter and throw an exception if it's a bad value. * @@ -144,4 +130,18 @@ protected function validateVoteArgument($vote, $possibleValues) { $this->validateArgument('Vote', $vote, $possibleValues); } + + /** + * Global method to validate an argument. + * + * @param string $type The required parameter (used for the error message) + * @param string $input Input value + * @param array $possibleValues Possible values for this argument + */ + private function validateArgument($type, $input, $possibleValues) + { + if (!\in_array($input, $possibleValues, true)) { + throw new InvalidArgumentException($type . ' parameter "' . $input . '" is wrong. Possible values are: ' . implode(', ', $possibleValues)); + } + } } diff --git a/lib/Imgur/Api/Account.php b/lib/Imgur/Api/Account.php index 074c56c..33656a4 100644 --- a/lib/Imgur/Api/Account.php +++ b/lib/Imgur/Api/Account.php @@ -5,7 +5,7 @@ /** * CRUD for Accounts. * - * @link https://api.imgur.com/endpoints/account + * @see https://api.imgur.com/endpoints/account * * @author Adrian Ghiuta */ @@ -16,7 +16,7 @@ class Account extends AbstractApi * * @param string $username * - * @link https://api.imgur.com/endpoints/account#account + * @see https://api.imgur.com/endpoints/account#account * * @return array Account (@see https://api.imgur.com/models/account) */ @@ -45,7 +45,7 @@ public function deleteAccount($username) * @param int $page * @param string $sort 'oldest', or 'newest'. Defaults to 'newest' * - * @link https://api.imgur.com/endpoints/account#account-gallery-favorites + * @see https://api.imgur.com/endpoints/account#account-gallery-favorites * * @return array Gallery Image (@see https://api.imgur.com/models/gallery_image) OR Gallery Album (@see https://api.imgur.com/models/gallery_album) */ @@ -61,7 +61,7 @@ public function galleryFavorites($username = 'me', $page = 0, $sort = 'newest') * * @param string $username * - * @link https://api.imgur.com/endpoints/account#account-favorites + * @see https://api.imgur.com/endpoints/account#account-favorites * * @return array Gallery Image (@see https://api.imgur.com/models/gallery_image) OR Gallery Album (@see https://api.imgur.com/models/gallery_album) */ @@ -76,7 +76,7 @@ public function favorites($username = 'me') * @param string $username * @param int $page * - * @link https://api.imgur.com/endpoints/account#account-submissions + * @see https://api.imgur.com/endpoints/account#account-submissions * * @return array Gallery Image (@see https://api.imgur.com/models/gallery_image) OR Gallery Album (@see https://api.imgur.com/models/gallery_album) */ @@ -90,7 +90,7 @@ public function submissions($username = 'me', $page = 0) * * @param string $username * - * @link https://api.imgur.com/endpoints/account#account-settings + * @see https://api.imgur.com/endpoints/account#account-settings * * @return array Account Settings (@see https://api.imgur.com/models/account_settings) */ @@ -104,7 +104,7 @@ public function settings($username = 'me') * * @param array $parameters * - * @link https://api.imgur.com/endpoints/account#update-settings + * @see https://api.imgur.com/endpoints/account#update-settings * * @return bool */ @@ -131,7 +131,7 @@ public function accountStats($username = 'me') * * @param string $username * - * @link https://api.imgur.com/endpoints/account#account-profile + * @see https://api.imgur.com/endpoints/account#account-profile * * @return array Gallery Profile (@see https://api.imgur.com/models/gallery_profile) */ @@ -145,7 +145,7 @@ public function accountGalleryProfile($username = 'me') * * @param string $username * - * @link https://api.imgur.com/endpoints/account#verify-email + * @see https://api.imgur.com/endpoints/account#verify-email * * @return bool */ @@ -159,7 +159,7 @@ public function verifyUsersEmail($username = 'me') * * @param string $username * - * @link https://api.imgur.com/endpoints/account#send-verify-email + * @see https://api.imgur.com/endpoints/account#send-verify-email * * @return bool */ @@ -174,7 +174,7 @@ public function sendVerificationEmail($username = 'me') * @param string $username * @param int $page * - * @link https://api.imgur.com/endpoints/account#albums + * @see https://api.imgur.com/endpoints/account#albums * * @return array Array of Album (@see https://api.imgur.com/models/album) */ @@ -190,7 +190,7 @@ public function albums($username = 'me', $page = 0) * @param string $username * @param string $albumId * - * @link https://api.imgur.com/endpoints/account#album + * @see https://api.imgur.com/endpoints/account#album * * @return array Album (@see https://api.imgur.com/models/album) */ @@ -205,7 +205,7 @@ public function album($albumId, $username = 'me') * @param string $username * @param int $page * - * @link https://api.imgur.com/endpoints/account#album-ids + * @see https://api.imgur.com/endpoints/account#album-ids * * @return array */ @@ -219,7 +219,7 @@ public function albumIds($username = 'me', $page = 0) * * @param string $username * - * @link https://api.imgur.com/endpoints/account#album-count + * @see https://api.imgur.com/endpoints/account#album-count * * @return int */ @@ -234,7 +234,7 @@ public function albumCount($username = 'me') * @param string $username * @param string $albumId * - * @link https://api.imgur.com/endpoints/account#album-delete + * @see https://api.imgur.com/endpoints/account#album-delete * * @return bool */ @@ -250,7 +250,7 @@ public function albumDelete($albumId, $username = 'me') * @param int $page * @param string $sort 'best', 'worst', 'oldest', or 'newest'. Defaults to 'newest' * - * @link https://api.imgur.com/endpoints/account#comments + * @see https://api.imgur.com/endpoints/account#comments * * @return array Array of Comment (@see https://api.imgur.com/models/comment) */ @@ -268,7 +268,7 @@ public function comments($username = 'me', $page = 0, $sort = 'newest') * @param string $commentId * @param string $username * - * @link https://api.imgur.com/endpoints/account#comment + * @see https://api.imgur.com/endpoints/account#comment * * @return array Comment (@see https://api.imgur.com/models/comment) */ @@ -284,7 +284,7 @@ public function comment($commentId, $username = 'me') * @param int $page * @param string $sort 'best', 'worst', 'oldest', or 'newest'. Defaults to 'newest' * - * @link https://api.imgur.com/endpoints/account#comment-ids + * @see https://api.imgur.com/endpoints/account#comment-ids * * @return array */ @@ -300,7 +300,7 @@ public function commentIds($username = 'me', $page = 0, $sort = 'newest') * * @param string $username * - * @link https://api.imgur.com/endpoints/account#comment-count + * @see https://api.imgur.com/endpoints/account#comment-count * * @return int */ @@ -315,7 +315,7 @@ public function commentCount($username = 'me') * @param string $commentId * @param string $username * - * @link https://api.imgur.com/endpoints/account#comment-delete + * @see https://api.imgur.com/endpoints/account#comment-delete * * @return bool */ @@ -331,7 +331,7 @@ public function commentDelete($commentId, $username = 'me') * @param string $username * @param int $page * - * @link https://api.imgur.com/endpoints/account#images + * @see https://api.imgur.com/endpoints/account#images * * @return array Array of Image (@see https://api.imgur.com/models/image) */ @@ -347,7 +347,7 @@ public function images($username = 'me', $page = 0) * @param string $imageId * @param string $username * - * @link https://api.imgur.com/endpoints/account#image + * @see https://api.imgur.com/endpoints/account#image * * @return array Image (@see https://api.imgur.com/models/image) */ @@ -362,7 +362,7 @@ public function image($imageId, $username = 'me') * @param string $username * @param int $page * - * @link https://api.imgur.com/endpoints/account#image-ids + * @see https://api.imgur.com/endpoints/account#image-ids * * @return array */ @@ -376,7 +376,7 @@ public function imageIds($username = 'me', $page = 0) * * @param string $username * - * @link https://api.imgur.com/endpoints/account#image-count + * @see https://api.imgur.com/endpoints/account#image-count * * @return int */ @@ -391,7 +391,7 @@ public function imageCount($username = 'me') * @param string $deleteHash * @param string $username * - * @link https://api.imgur.com/endpoints/account#image-delete + * @see https://api.imgur.com/endpoints/account#image-delete * * @return bool */ @@ -406,7 +406,7 @@ public function imageDelete($deleteHash, $username = 'me') * @param string $username * @param bool $onlyNew * - * @link https://api.imgur.com/endpoints/account#replies + * @see https://api.imgur.com/endpoints/account#replies * * @return array Array of Notification (@see https://api.imgur.com/models/notification) */ diff --git a/lib/Imgur/Api/Album.php b/lib/Imgur/Api/Album.php index 1e4336b..a30ceed 100644 --- a/lib/Imgur/Api/Album.php +++ b/lib/Imgur/Api/Album.php @@ -5,7 +5,7 @@ /** * CRUD for Albums. * - * @link https://api.imgur.com/endpoints/album + * @see https://api.imgur.com/endpoints/album * * @author Adrian Ghiuta */ @@ -16,7 +16,7 @@ class Album extends AbstractApi * * @param string $albumId * - * @link https://api.imgur.com/endpoints/album#album + * @see https://api.imgur.com/endpoints/album#album * * @return array Album (@see https://api.imgur.com/models/album) */ @@ -30,7 +30,7 @@ public function album($albumId) * * @param string $albumId * - * @link https://api.imgur.com/endpoints/album#album-images + * @see https://api.imgur.com/endpoints/album#album-images * * @return array Array of Image (@see https://api.imgur.com/models/image) */ @@ -45,7 +45,7 @@ public function albumImages($albumId) * @param string $albumId * @param string $imageId * - * @link https://api.imgur.com/endpoints/album#album-image + * @see https://api.imgur.com/endpoints/album#album-image * * @return array Image (@see https://api.imgur.com/models/image) */ @@ -62,7 +62,7 @@ public function albumImage($albumId, $imageId) * * @param array $data * - * @link https://api.imgur.com/endpoints/album#album-upload + * @see https://api.imgur.com/endpoints/album#album-upload * * @return bool */ @@ -78,7 +78,7 @@ public function create($data) * @param string $deletehashOrAlbumId * @param array $data * - * @link https://api.imgur.com/endpoints/album#album-update + * @see https://api.imgur.com/endpoints/album#album-update * * @return bool */ @@ -94,7 +94,7 @@ public function update($deletehashOrAlbumId, $data) * * @param string $deletehashOrAlbumId * - * @link https://api.imgur.com/endpoints/album#album-delete + * @see https://api.imgur.com/endpoints/album#album-delete * * @return bool */ @@ -108,7 +108,7 @@ public function deleteAlbum($deletehashOrAlbumId) * * @param string $albumId * - * @link https://api.imgur.com/endpoints/album#album-favorite + * @see https://api.imgur.com/endpoints/album#album-favorite * * @return bool */ @@ -124,7 +124,7 @@ public function favoriteAlbum($albumId) * @param string $albumId * @param array $imageIds * - * @link https://api.imgur.com/endpoints/album#album-set-to + * @see https://api.imgur.com/endpoints/album#album-set-to * * @return bool */ @@ -140,7 +140,7 @@ public function setAlbumImages($albumId, array $imageIds) * @param string $albumId * @param array $imageIds * - * @link https://api.imgur.com/endpoints/album#album-add-to + * @see https://api.imgur.com/endpoints/album#album-add-to * * @return bool */ @@ -156,7 +156,7 @@ public function addImages($albumId, array $imageIds) * @param string $deletehashOrAlbumId * @param array $imageIds * - * @link https://api.imgur.com/endpoints/album#album-remove-from + * @see https://api.imgur.com/endpoints/album#album-remove-from * * @return bool */ diff --git a/lib/Imgur/Api/AlbumOrImage.php b/lib/Imgur/Api/AlbumOrImage.php index c10830e..64fdf79 100644 --- a/lib/Imgur/Api/AlbumOrImage.php +++ b/lib/Imgur/Api/AlbumOrImage.php @@ -24,7 +24,7 @@ public function find($imageIdOrAlbumId) try { return $this->get('image/' . $imageIdOrAlbumId); } catch (ExceptionInterface $e) { - if ($e->getCode() !== 404) { + if (404 !== $e->getCode()) { throw $e; } } @@ -32,7 +32,7 @@ public function find($imageIdOrAlbumId) try { return $this->get('album/' . $imageIdOrAlbumId); } catch (ExceptionInterface $e) { - if ($e->getCode() !== 404) { + if (404 !== $e->getCode()) { throw $e; } } diff --git a/lib/Imgur/Api/Comment.php b/lib/Imgur/Api/Comment.php index 4741f10..20a5bcb 100644 --- a/lib/Imgur/Api/Comment.php +++ b/lib/Imgur/Api/Comment.php @@ -7,7 +7,7 @@ /** * CRUD for Comment. * - * @link https://api.imgur.com/endpoints/comment + * @see https://api.imgur.com/endpoints/comment * * @author Adrian Ghiuta */ @@ -18,7 +18,7 @@ class Comment extends AbstractApi * * @param string $commentId * - * @link https://api.imgur.com/endpoints/comment#comment + * @see https://api.imgur.com/endpoints/comment#comment * * @return array Comment (@see https://api.imgur.com/endpoints/gallery#gallery-comments) */ @@ -32,7 +32,7 @@ public function comment($commentId) * * @param array $data * - * @link https://api.imgur.com/endpoints/comment#comment-create + * @see https://api.imgur.com/endpoints/comment#comment-create * * @return bool */ @@ -50,7 +50,7 @@ public function create($data) * * @param string $commentId * - * @link https://api.imgur.com/endpoints/comment#comment-delete + * @see https://api.imgur.com/endpoints/comment#comment-delete * * @return bool */ @@ -64,7 +64,7 @@ public function deleteComment($commentId) * * @param string $commentId * - * @link https://api.imgur.com/endpoints/comment#comment-replies + * @see https://api.imgur.com/endpoints/comment#comment-replies * * @return array Comment (@see https://api.imgur.com/endpoints/gallery#gallery-comments) */ @@ -79,7 +79,7 @@ public function replies($commentId) * @param string $commentId * @param array $data * - * @link https://api.imgur.com/endpoints/comment#comment-reply-create + * @see https://api.imgur.com/endpoints/comment#comment-reply-create * * @return bool */ @@ -98,7 +98,7 @@ public function createReply($commentId, $data) * @param string $commentId * @param string $vote * - * @link https://api.imgur.com/endpoints/comment#comment-vote + * @see https://api.imgur.com/endpoints/comment#comment-vote * * @return bool */ @@ -114,7 +114,7 @@ public function vote($commentId, $vote) * * @param string $commentId * - * @link https://api.imgur.com/endpoints/comment#comment-report + * @see https://api.imgur.com/endpoints/comment#comment-report * * @return bool */ diff --git a/lib/Imgur/Api/Conversation.php b/lib/Imgur/Api/Conversation.php index ba85deb..90b3327 100644 --- a/lib/Imgur/Api/Conversation.php +++ b/lib/Imgur/Api/Conversation.php @@ -7,7 +7,7 @@ /** * CRUD for Conversations. * - * @link https://api.imgur.com/endpoints/conversation + * @see https://api.imgur.com/endpoints/conversation * * @author Adrian Ghiuta */ @@ -16,7 +16,7 @@ class Conversation extends AbstractApi /** * Get list of all conversations for the logged in user. * - * @link https://api.imgur.com/endpoints/conversation#conversation-list + * @see https://api.imgur.com/endpoints/conversation#conversation-list * * @return array Array of Conversation (@see https://api.imgur.com/models/conversation) */ @@ -30,7 +30,7 @@ public function conversations() * * @param string $conversationId * - * @link https://api.imgur.com/endpoints/conversation#conversation + * @see https://api.imgur.com/endpoints/conversation#conversation * * @return array Conversation (@see https://api.imgur.com/models/conversation) */ @@ -45,7 +45,7 @@ public function conversation($conversationId) * * @param array $data * - * @link https://api.imgur.com/endpoints/conversation#message-create + * @see https://api.imgur.com/endpoints/conversation#message-create * * @return bool */ @@ -63,7 +63,7 @@ public function messageCreate($data) * * @param string $conversationId * - * @link https://api.imgur.com/endpoints/conversation#message-delete + * @see https://api.imgur.com/endpoints/conversation#message-delete * * @return bool */ @@ -77,7 +77,7 @@ public function conversationDelete($conversationId) * * @param string $username * - * @link https://api.imgur.com/endpoints/conversation#message-report + * @see https://api.imgur.com/endpoints/conversation#message-report * * @return bool */ @@ -91,7 +91,7 @@ public function reportSender($username) * * @param string $username * - * @link https://api.imgur.com/endpoints/conversation#message-block + * @see https://api.imgur.com/endpoints/conversation#message-block * * @return bool */ diff --git a/lib/Imgur/Api/CustomGallery.php b/lib/Imgur/Api/CustomGallery.php index c9aa45c..f20a92d 100644 --- a/lib/Imgur/Api/CustomGallery.php +++ b/lib/Imgur/Api/CustomGallery.php @@ -5,7 +5,7 @@ /** * CRUD for CustomGallery. * - * @link https://api.imgur.com/endpoints/custom_gallery + * @see https://api.imgur.com/endpoints/custom_gallery */ class CustomGallery extends AbstractApi { @@ -16,7 +16,7 @@ class CustomGallery extends AbstractApi * @param int $page * @param string $window (day | week | month | year | all) * - * @link https://api.imgur.com/endpoints/custom_gallery#custom-gallery + * @see https://api.imgur.com/endpoints/custom_gallery#custom-gallery * * @return array Custom Gallery (@see https://api.imgur.com/models/custom_gallery) */ @@ -35,7 +35,7 @@ public function customGallery($sort = 'viral', $page = 0, $window = 'week') * @param int $page * @param string $window (day | week | month | year | all) * - * @link https://api.imgur.com/endpoints/custom_gallery#filtered-out-gallery + * @see https://api.imgur.com/endpoints/custom_gallery#filtered-out-gallery * * @return array Custom Gallery (@see https://api.imgur.com/models/custom_gallery) */ @@ -52,7 +52,7 @@ public function filtered($sort = 'viral', $page = 0, $window = 'week') * * @param string $imageId The ID for the gallery item * - * @link https://api.imgur.com/endpoints/custom_gallery#custom-gallery-image + * @see https://api.imgur.com/endpoints/custom_gallery#custom-gallery-image * * @return array Gallery Image (@see https://api.imgur.com/models/gallery_image) OR Gallery Album (@see https://api.imgur.com/models/gallery_album) */ @@ -66,7 +66,7 @@ public function image($imageId) * * @param array $tags * - * @link https://api.imgur.com/endpoints/custom_gallery#custom-gallery-add + * @see https://api.imgur.com/endpoints/custom_gallery#custom-gallery-add * * @return bool */ @@ -80,7 +80,7 @@ public function addTags(array $tags) * * @param array $tags * - * @link https://api.imgur.com/endpoints/custom_gallery#custom-gallery-remove + * @see https://api.imgur.com/endpoints/custom_gallery#custom-gallery-remove * * @return bool */ @@ -94,7 +94,7 @@ public function removeTags(array $tags) * * @param string $tag * - * @link https://api.imgur.com/endpoints/custom_gallery#filtered-out-block + * @see https://api.imgur.com/endpoints/custom_gallery#filtered-out-block * * @return bool */ @@ -108,7 +108,7 @@ public function blockTag($tag) * * @param string $tag * - * @link https://api.imgur.com/endpoints/custom_gallery#filtered-out-unblock + * @see https://api.imgur.com/endpoints/custom_gallery#filtered-out-unblock * * @return bool */ diff --git a/lib/Imgur/Api/Gallery.php b/lib/Imgur/Api/Gallery.php index 0fd84a7..dd0a999 100644 --- a/lib/Imgur/Api/Gallery.php +++ b/lib/Imgur/Api/Gallery.php @@ -8,7 +8,7 @@ /** * CRUD for Gallery. * - * @link https://api.imgur.com/endpoints/gallery + * @see https://api.imgur.com/endpoints/gallery * * @author Adrian Ghiuta */ @@ -23,7 +23,7 @@ class Gallery extends AbstractApi * @param string $window (day | week | month | year | all) * @param bool $showViral * - * @link https://api.imgur.com/endpoints/gallery#gallery + * @see https://api.imgur.com/endpoints/gallery#gallery * * @return array Gallery Image (@see https://api.imgur.com/models/gallery_image) OR Gallery Album (@see https://api.imgur.com/models/gallery_album) */ @@ -33,7 +33,7 @@ public function gallery($section = 'hot', $sort = 'viral', $page = 0, $window = $this->validateWindowArgument($window, ['day', 'week', 'month', 'year', 'all']); $sectionValues = ['hot', 'top', 'user']; - if (!in_array($section, $sectionValues, true)) { + if (!\in_array($section, $sectionValues, true)) { throw new InvalidArgumentException('Section parameter "' . $section . '" is wrong. Possible values are: ' . implode(', ', $sectionValues)); } @@ -49,7 +49,7 @@ public function gallery($section = 'hot', $sort = 'viral', $page = 0, $window = * @param int $page * @param string $window (day | week | month | year | all) * - * @link https://api.imgur.com/endpoints/gallery#meme-subgallery + * @see https://api.imgur.com/endpoints/gallery#meme-subgallery * * @return array Gallery Image (@see https://api.imgur.com/models/gallery_image) OR Gallery Album (@see https://api.imgur.com/models/gallery_album) */ @@ -67,7 +67,7 @@ public function memesSubgallery($sort = 'viral', $page = 0, $window = 'day') * * @param string $imageId * - * @link https://api.imgur.com/endpoints/gallery#meme-subgallery-image + * @see https://api.imgur.com/endpoints/gallery#meme-subgallery-image * * @return array Gallery Image (@see https://api.imgur.com/models/gallery_image) */ @@ -84,7 +84,7 @@ public function memeSubgalleryImage($imageId) * @param int $page * @param string $window (day | week | month | year | all) * - * @link https://api.imgur.com/endpoints/gallery#subreddit + * @see https://api.imgur.com/endpoints/gallery#subreddit * * @return array Gallery Image (@see https://api.imgur.com/models/gallery_image) */ @@ -102,7 +102,7 @@ public function subredditGalleries($subreddit, $sort = 'time', $page = 0, $windo * @param string $subreddit (e.g pics - A valid sub-reddit name) * @param string $imageId * - * @link https://api.imgur.com/endpoints/gallery#subreddit-image + * @see https://api.imgur.com/endpoints/gallery#subreddit-image * * @return array Gallery Image (@see https://api.imgur.com/models/gallery_image) */ @@ -119,7 +119,7 @@ public function subredditImage($subreddit, $imageId) * @param int $page * @param string $window (day | week | month | year | all) * - * @link https://api.imgur.com/endpoints/gallery#gallery-tag + * @see https://api.imgur.com/endpoints/gallery#gallery-tag * * @return array Tag (@see https://api.imgur.com/models/tag) */ @@ -137,7 +137,7 @@ public function galleryTag($name, $sort = 'viral', $page = 0, $window = 'week') * @param string $name The name of the tag * @param string $imageId The ID for the image * - * @link https://api.imgur.com/endpoints/gallery#gallery-tag-image + * @see https://api.imgur.com/endpoints/gallery#gallery-tag-image * * @return array Gallery Image (@see https://api.imgur.com/models/gallery_image) */ @@ -151,7 +151,7 @@ public function galleryTagImage($name, $imageId) * * @param string $imageOrAlbumId ID of the gallery item * - * @link https://api.imgur.com/endpoints/gallery#gallery-item-tags + * @see https://api.imgur.com/endpoints/gallery#gallery-item-tags * * @return array of Tag Votes (@see https://api.imgur.com/models/tag_vote) */ @@ -167,7 +167,7 @@ public function galleryItemTags($imageOrAlbumId) * @param string $name Name of the tag (implicitly created, if doesn't exist) * @param string $vote 'up' or 'down' * - * @link https://api.imgur.com/endpoints/gallery#gallery-tag-vote + * @see https://api.imgur.com/endpoints/gallery#gallery-tag-vote * * @return bool */ @@ -187,7 +187,7 @@ public function galleryVoteTag($id, $name, $vote) * @param string $sort (time | viral | top) * @param int $page * - * @link https://api.imgur.com/endpoints/gallery#gallery-search + * @see https://api.imgur.com/endpoints/gallery#gallery-search * * @return array Gallery Image (@see https://api.imgur.com/models/gallery_image) OR Gallery Album (@see https://api.imgur.com/models/gallery_album) */ @@ -203,7 +203,7 @@ public function search($query, $sort = 'time', $page = 0) * * @param int $page * - * @link https://api.imgur.com/endpoints/gallery#gallery-random + * @see https://api.imgur.com/endpoints/gallery#gallery-random * * @return array Gallery Image (@see https://api.imgur.com/models/gallery_image) OR Gallery Album (@see https://api.imgur.com/models/gallery_album) */ @@ -218,7 +218,7 @@ public function randomGalleryImages($page = 0) * @param string $imageOrAlbumId * @param array $data * - * @link https://api.imgur.com/endpoints/gallery#to-gallery + * @see https://api.imgur.com/endpoints/gallery#to-gallery * * @return bool */ @@ -236,7 +236,7 @@ public function submitToGallery($imageOrAlbumId, $data) * * @param string $imageOrAlbumId * - * @link https://api.imgur.com/endpoints/gallery#from-gallery + * @see https://api.imgur.com/endpoints/gallery#from-gallery * * @return bool */ @@ -250,7 +250,7 @@ public function removeFromGallery($imageOrAlbumId) * * @param string $albumId * - * @link https://api.imgur.com/endpoints/gallery#album + * @see https://api.imgur.com/endpoints/gallery#album * * @return array Gallery Album (@see https://api.imgur.com/models/gallery_album) */ @@ -264,7 +264,7 @@ public function album($albumId) * * @param string $imageId * - * @link https://api.imgur.com/endpoints/gallery#image + * @see https://api.imgur.com/endpoints/gallery#image * * @return array Gallery Image (@see https://api.imgur.com/models/gallery_image) */ @@ -278,7 +278,7 @@ public function image($imageId) * * @param string $imageOrAlbumId * - * @link https://api.imgur.com/endpoints/gallery#gallery-reporting + * @see https://api.imgur.com/endpoints/gallery#gallery-reporting * * @return bool */ @@ -292,7 +292,7 @@ public function report($imageOrAlbumId) * * @param string $imageOrAlbumId * - * @link https://api.imgur.com/endpoints/gallery#gallery-votes + * @see https://api.imgur.com/endpoints/gallery#gallery-votes * * @return array Vote (@see https://api.imgur.com/models/vote) */ @@ -307,7 +307,7 @@ public function votes($imageOrAlbumId) * @param string $imageOrAlbumId * @param string $vote (up | down | veto) * - * @link https://api.imgur.com/endpoints/gallery#gallery-voting + * @see https://api.imgur.com/endpoints/gallery#gallery-voting * * @return bool */ @@ -324,7 +324,7 @@ public function vote($imageOrAlbumId, $vote) * @param string $imageOrAlbumId * @param string $sort (best | top | new) * - * @link https://api.imgur.com/endpoints/gallery#gallery-comments + * @see https://api.imgur.com/endpoints/gallery#gallery-comments * * @return array Array of Comment (@see https://api.imgur.com/endpoints/gallery#gallery-comments) */ @@ -341,7 +341,7 @@ public function comments($imageOrAlbumId, $sort = 'best') * @param string $imageOrAlbumId * @param string $commentId * - * @link https://api.imgur.com/endpoints/gallery#gallery-comment + * @see https://api.imgur.com/endpoints/gallery#gallery-comment * * @return array Comment (@see https://api.imgur.com/endpoints/gallery#gallery-comments) */ @@ -356,7 +356,7 @@ public function comment($imageOrAlbumId, $commentId) * @param string $imageOrAlbumId * @param array $data * - * @link https://api.imgur.com/endpoints/gallery#gallery-comment-creation + * @see https://api.imgur.com/endpoints/gallery#gallery-comment-creation * * @return bool */ @@ -376,7 +376,7 @@ public function createComment($imageOrAlbumId, $data) * @param string $commentId * @param array $data * - * @link https://api.imgur.com/endpoints/gallery#gallery-comment-reply + * @see https://api.imgur.com/endpoints/gallery#gallery-comment-reply * * @return bool */ @@ -394,7 +394,7 @@ public function createReply($imageOrAlbumId, $commentId, $data) * * @param string $imageOrAlbumId * - * @link https://api.imgur.com/endpoints/gallery#gallery-comment-ids + * @see https://api.imgur.com/endpoints/gallery#gallery-comment-ids * * @return array */ @@ -408,7 +408,7 @@ public function commentIds($imageOrAlbumId) * * @param string $imageOrAlbumId * - * @link https://api.imgur.com/endpoints/gallery#gallery-comment-count + * @see https://api.imgur.com/endpoints/gallery#gallery-comment-count * * @return int */ diff --git a/lib/Imgur/Api/Image.php b/lib/Imgur/Api/Image.php index ee09548..fdbbe35 100644 --- a/lib/Imgur/Api/Image.php +++ b/lib/Imgur/Api/Image.php @@ -8,7 +8,7 @@ /** * CRUD for Images. * - * @link https://api.imgur.com/endpoints/image + * @see https://api.imgur.com/endpoints/image * * @author Adrian Ghiuta */ @@ -19,7 +19,7 @@ class Image extends AbstractApi * * @param string $imageId * - * @link https://api.imgur.com/endpoints/image#image + * @see https://api.imgur.com/endpoints/image#image * * @return array (@see https://api.imgur.com/models/image) */ @@ -33,7 +33,7 @@ public function image($imageId) * * @param array $data * - * @link https://api.imgur.com/endpoints/image#image-upload + * @see https://api.imgur.com/endpoints/image#image-upload * * @return bool */ @@ -44,7 +44,7 @@ public function upload($data) } $typeValues = ['file', 'base64', 'url']; - if (isset($data['type']) && !in_array(strtolower($data['type']), $typeValues, true)) { + if (isset($data['type']) && !\in_array(strtolower($data['type']), $typeValues, true)) { throw new InvalidArgumentException('Type parameter "' . $data['type'] . '" is wrong. Possible values are: ' . implode(', ', $typeValues)); } @@ -61,7 +61,7 @@ public function upload($data) * * @param string $imageIdOrDeleteHash * - * @link https://api.imgur.com/endpoints/image#image-delete + * @see https://api.imgur.com/endpoints/image#image-delete * * @return bool */ @@ -78,7 +78,7 @@ public function deleteImage($imageIdOrDeleteHash) * @param string $imageIdOrDeleteHash * @param array $data * - * @link https://api.imgur.com/endpoints/image#image-update + * @see https://api.imgur.com/endpoints/image#image-update * * @return bool */ @@ -92,7 +92,7 @@ public function update($imageIdOrDeleteHash, $data) * * @param string $imageIdOrDeleteHash * - * @link https://api.imgur.com/endpoints/image#image-favorite + * @see https://api.imgur.com/endpoints/image#image-favorite * * @return bool */ diff --git a/lib/Imgur/Api/Memegen.php b/lib/Imgur/Api/Memegen.php index dd7a09a..4606c2b 100644 --- a/lib/Imgur/Api/Memegen.php +++ b/lib/Imgur/Api/Memegen.php @@ -5,7 +5,7 @@ /** * CRUD for Memegen. * - * @link https://api.imgur.com/endpoints/memegen + * @see https://api.imgur.com/endpoints/memegen * * @author Adrian Ghiuta */ @@ -14,7 +14,7 @@ class Memegen extends AbstractApi /** * Get the list of default memes. * - * @link https://api.imgur.com/endpoints/memegen#defaults + * @see https://api.imgur.com/endpoints/memegen#defaults * * @return array Of images (@see Image.php) */ diff --git a/lib/Imgur/Api/Notification.php b/lib/Imgur/Api/Notification.php index d3eac01..c412954 100644 --- a/lib/Imgur/Api/Notification.php +++ b/lib/Imgur/Api/Notification.php @@ -5,7 +5,7 @@ /** * CRUD for Notifications. * - * @link https://api.imgur.com/endpoints/notification + * @see https://api.imgur.com/endpoints/notification * * @author Adrian Ghiuta */ @@ -16,7 +16,7 @@ class Notification extends AbstractApi * * @param string $new false for all notifications, true for only non-viewed notification * - * @link https://api.imgur.com/endpoints/notification#notifications + * @see https://api.imgur.com/endpoints/notification#notifications * * @return array With keys "replies" & "messages" */ @@ -32,7 +32,7 @@ public function notifications($new = true) * * @param string $notificationId * - * @link https://api.imgur.com/endpoints/notification#notification + * @see https://api.imgur.com/endpoints/notification#notification * * @return array (@see https://api.imgur.com/models/notification) */ @@ -46,7 +46,7 @@ public function notification($notificationId) * * @param string $notificationId * - * @link https://api.imgur.com/endpoints/notification#notification-viewed + * @see https://api.imgur.com/endpoints/notification#notification-viewed * * @return bool */ diff --git a/lib/Imgur/Api/Topic.php b/lib/Imgur/Api/Topic.php index d81a86f..df484bc 100644 --- a/lib/Imgur/Api/Topic.php +++ b/lib/Imgur/Api/Topic.php @@ -5,14 +5,14 @@ /** * CRUD for Topic. * - * @link https://api.imgur.com/endpoints/topic + * @see https://api.imgur.com/endpoints/topic */ class Topic extends AbstractApi { /** * Get the list of default topics. * - * @link https://api.imgur.com/endpoints/topic#defaults + * @see https://api.imgur.com/endpoints/topic#defaults * * @return array Topic (@see https://api.imgur.com/models/topic) */ @@ -29,7 +29,7 @@ public function defaultTopics() * @param int $page * @param string $window (day | week | month | year | all) * - * @link https://api.imgur.com/endpoints/topic#gallery-topic + * @see https://api.imgur.com/endpoints/topic#gallery-topic * * @return array Gallery Image (@see https://api.imgur.com/models/gallery_image) OR Gallery Album (@see https://api.imgur.com/models/gallery_album) */ @@ -47,7 +47,7 @@ public function galleryTopic($topicId, $sort = 'viral', $page = 0, $window = 'we * @param string $topicId The ID or URL-formatted name of the topic. If using a topic's name, replace its spaces with underscores (Mother's_Day) * @param int $itemId The ID for the gallery item * - * @link https://api.imgur.com/endpoints/topic#gallery-topic-item + * @see https://api.imgur.com/endpoints/topic#gallery-topic-item * * @return array Gallery Image (@see https://api.imgur.com/models/gallery_image) OR Gallery Album (@see https://api.imgur.com/models/gallery_album) */ diff --git a/lib/Imgur/Auth/AuthInterface.php b/lib/Imgur/Auth/AuthInterface.php index d5f178c..d11d71a 100644 --- a/lib/Imgur/Auth/AuthInterface.php +++ b/lib/Imgur/Auth/AuthInterface.php @@ -20,11 +20,14 @@ interface AuthInterface public function getAuthenticationUrl($responseType = 'code', $state = null); public function getAccessToken(); + public function requestAccessToken($code, $responseType); + public function setAccessToken($accessToken); public function sign(); public function refreshToken(); + public function checkAccessTokenExpired(); } diff --git a/lib/Imgur/Auth/OAuth2.php b/lib/Imgur/Auth/OAuth2.php index 26829c1..d0787cd 100644 --- a/lib/Imgur/Auth/OAuth2.php +++ b/lib/Imgur/Auth/OAuth2.php @@ -13,6 +13,9 @@ */ class OAuth2 implements AuthInterface { + const AUTHORIZATION_ENDPOINT = 'https://api.imgur.com/oauth2/authorize'; + const ACCESS_TOKEN_ENDPOINT = 'https://api.imgur.com/oauth2/token'; + /** * Indicates the client that is making the request. * @@ -57,9 +60,6 @@ class OAuth2 implements AuthInterface */ private $token; - const AUTHORIZATION_ENDPOINT = 'https://api.imgur.com/oauth2/authorize'; - const ACCESS_TOKEN_ENDPOINT = 'https://api.imgur.com/oauth2/token'; - /** * Instantiates the OAuth2 class, but does not trigger the authentication process. * @@ -78,7 +78,7 @@ public function __construct(HttpClientInterface $httpClient, $clientId, $clientS * Generates the authentication URL to which a user should be pointed at in order to start the OAuth2 process. * * @param string $responseType - * @param null|string $state + * @param string|null $state * * @return string */ @@ -110,7 +110,6 @@ public function requestAccessToken($code, $requestType) $grantType = 'pin'; $type = 'pin'; break; - case 'code': default: $grantType = 'authorization_code'; @@ -190,7 +189,7 @@ public function refreshToken() */ public function setAccessToken($token) { - if (!is_array($token)) { + if (!\is_array($token)) { throw new AuthException('Token is not a valid json string.'); } diff --git a/lib/Imgur/Client.php b/lib/Imgur/Client.php index 0e10597..b762f7f 100644 --- a/lib/Imgur/Client.php +++ b/lib/Imgur/Client.php @@ -39,7 +39,7 @@ class Client /** * Instantiate a new Imgur client. * - * @param null|HttpClientInterface $httpClient Imgur http client + * @param HttpClientInterface|null $httpClient Imgur http client */ public function __construct(AuthInterface $authenticationClient = null, HttpClientInterface $httpClient = null) { @@ -98,7 +98,7 @@ public function setHttpClient(HttpClientInterface $httpClient) */ public function getOption($name) { - if (!array_key_exists($name, $this->options)) { + if (!\array_key_exists($name, $this->options)) { throw new InvalidArgumentException(sprintf('Undefined option called: "%s"', $name)); } @@ -113,7 +113,7 @@ public function getOption($name) */ public function setOption($name, $value) { - if (!array_key_exists($name, $this->options)) { + if (!\array_key_exists($name, $this->options)) { throw new InvalidArgumentException(sprintf('Undefined option called: "%s"', $name)); } diff --git a/lib/Imgur/Exception/MissingArgumentException.php b/lib/Imgur/Exception/MissingArgumentException.php index 707c1b8..50a00f3 100644 --- a/lib/Imgur/Exception/MissingArgumentException.php +++ b/lib/Imgur/Exception/MissingArgumentException.php @@ -6,7 +6,7 @@ class MissingArgumentException extends ErrorException { public function __construct($required, $code = 0, $previous = null) { - if (is_string($required)) { + if (\is_string($required)) { $required = [$required]; } diff --git a/lib/Imgur/HttpClient/HttpClient.php b/lib/Imgur/HttpClient/HttpClient.php index bb122a3..f84e098 100644 --- a/lib/Imgur/HttpClient/HttpClient.php +++ b/lib/Imgur/HttpClient/HttpClient.php @@ -116,7 +116,7 @@ public function createRequest($url, $parameters, $httpMethod = 'GET') $options['query'] = $parameters['query']; } - if ($httpMethod === 'POST' || $httpMethod === 'PUT' || $httpMethod === 'DELETE') { + if ('POST' === $httpMethod || 'PUT' === $httpMethod || 'DELETE' === $httpMethod) { $options['body'] = $parameters; } diff --git a/lib/Imgur/Listener/AuthListener.php b/lib/Imgur/Listener/AuthListener.php index f6bc3e6..f87ee0f 100644 --- a/lib/Imgur/Listener/AuthListener.php +++ b/lib/Imgur/Listener/AuthListener.php @@ -19,7 +19,7 @@ public function before(BeforeEvent $event) { $request = $event->getRequest(); - if (is_array($this->token) && !empty($this->token['access_token'])) { + if (\is_array($this->token) && !empty($this->token['access_token'])) { $request->setHeader( 'Authorization', 'Bearer ' . $this->token['access_token'] diff --git a/lib/Imgur/Listener/ErrorListener.php b/lib/Imgur/Listener/ErrorListener.php index 58abb92..6c34acb 100644 --- a/lib/Imgur/Listener/ErrorListener.php +++ b/lib/Imgur/Listener/ErrorListener.php @@ -32,14 +32,16 @@ public function error(ErrorEvent $event) $responseData = $body; } - if (is_array($responseData) && isset($responseData['data']) && isset($responseData['data']['error'])) { - throw new ErrorException( - 'Request to: ' . $responseData['data']['request'] . ' failed with: "' . $responseData['data']['error'] . '"', - $response->getStatusCode() - ); + if (\is_array($responseData) && isset($responseData['data']) && isset($responseData['data']['error'])) { + $message = 'Request failed with: "' . $responseData['data']['error'] . '"'; + if (isset($responseData['data']['request'])) { + $message = 'Request to: ' . $responseData['data']['request'] . ' failed with: "' . $responseData['data']['error'] . '"'; + } + + throw new ErrorException($message, $response->getStatusCode()); } - throw new RuntimeException(is_array($responseData) && isset($responseData['message']) ? $responseData['message'] : $responseData, $response->getStatusCode()); + throw new RuntimeException(\is_array($responseData) && isset($responseData['message']) ? $responseData['message'] : $responseData, $response->getStatusCode()); } /** diff --git a/tests/Api/AbstractApiTest.php b/tests/Api/AbstractApiTest.php index e3200b1..131cac9 100644 --- a/tests/Api/AbstractApiTest.php +++ b/tests/Api/AbstractApiTest.php @@ -6,7 +6,7 @@ use Imgur\Client; use Imgur\Pager\BasicPager; -class AbstractApiTest extends \PHPUnit_Framework_TestCase +class AbstractApiTest extends \PHPUnit\Framework\TestCase { public function testGet() { diff --git a/tests/Api/AccountTest.php b/tests/Api/AccountTest.php index 3174270..e554c51 100644 --- a/tests/Api/AccountTest.php +++ b/tests/Api/AccountTest.php @@ -12,11 +12,6 @@ class AccountTest extends ApiTestCase { - protected function getApiClass() - { - return 'Imgur\Api\Account'; - } - /** * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required @@ -633,4 +628,9 @@ public function testReplies() $this->assertSame($expectedValue, $api->replies()); } + + protected function getApiClass() + { + return 'Imgur\Api\Account'; + } } diff --git a/tests/Api/AlbumOrImageTest.php b/tests/Api/AlbumOrImageTest.php index b1d5b69..c5b4517 100644 --- a/tests/Api/AlbumOrImageTest.php +++ b/tests/Api/AlbumOrImageTest.php @@ -10,7 +10,7 @@ use Imgur\Client; use Imgur\HttpClient\HttpClient; -class AlbumOrImageTest extends \PHPUnit_Framework_TestCase +class AlbumOrImageTest extends \PHPUnit\Framework\TestCase { public function testWithImageId() { diff --git a/tests/Api/AlbumTest.php b/tests/Api/AlbumTest.php index cbe26d0..7b5e639 100644 --- a/tests/Api/AlbumTest.php +++ b/tests/Api/AlbumTest.php @@ -12,11 +12,6 @@ class AlbumTest extends ApiTestCase { - protected function getApiClass() - { - return 'Imgur\Api\Album'; - } - /** * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required @@ -298,4 +293,9 @@ public function testRemoveImages() $this->assertSame($expectedValue, $api->removeImages('VOMXz', ['POvvB', 'P1vvB'])); } + + protected function getApiClass() + { + return 'Imgur\Api\Album'; + } } diff --git a/tests/Api/ApiTestCase.php b/tests/Api/ApiTestCase.php index 9af6c0f..8f68f96 100644 --- a/tests/Api/ApiTestCase.php +++ b/tests/Api/ApiTestCase.php @@ -4,7 +4,7 @@ use Imgur\Client; -abstract class ApiTestCase extends \PHPUnit_Framework_TestCase +abstract class ApiTestCase extends \PHPUnit\Framework\TestCase { abstract protected function getApiClass(); diff --git a/tests/Api/CommentTest.php b/tests/Api/CommentTest.php index 6efa396..3a3c6dd 100644 --- a/tests/Api/CommentTest.php +++ b/tests/Api/CommentTest.php @@ -12,11 +12,6 @@ class CommentTest extends ApiTestCase { - protected function getApiClass() - { - return 'Imgur\Api\Comment'; - } - /** * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required @@ -233,4 +228,9 @@ public function testReport() $this->assertSame($expectedValue, $api->report('726305564')); } + + protected function getApiClass() + { + return 'Imgur\Api\Comment'; + } } diff --git a/tests/Api/ConversationTest.php b/tests/Api/ConversationTest.php index cfa5ad2..560c642 100644 --- a/tests/Api/ConversationTest.php +++ b/tests/Api/ConversationTest.php @@ -12,11 +12,6 @@ class ConversationTest extends ApiTestCase { - protected function getApiClass() - { - return 'Imgur\Api\Conversation'; - } - /** * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required @@ -182,4 +177,9 @@ public function testBlockSender() $this->assertSame($expectedValue, $api->blockSender('imgur')); } + + protected function getApiClass() + { + return 'Imgur\Api\Conversation'; + } } diff --git a/tests/Api/CustomGalleryTest.php b/tests/Api/CustomGalleryTest.php index c6ac3d1..520d317 100644 --- a/tests/Api/CustomGalleryTest.php +++ b/tests/Api/CustomGalleryTest.php @@ -12,11 +12,6 @@ class CustomGalleryTest extends ApiTestCase { - protected function getApiClass() - { - return 'Imgur\Api\CustomGallery'; - } - /** * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required @@ -255,4 +250,9 @@ public function testUnBlockTag() $this->assertSame($expectedValue, $api->unBlockTag('funny')); } + + protected function getApiClass() + { + return 'Imgur\Api\CustomGallery'; + } } diff --git a/tests/Api/GalleryTest.php b/tests/Api/GalleryTest.php index b3959fb..c70004f 100644 --- a/tests/Api/GalleryTest.php +++ b/tests/Api/GalleryTest.php @@ -12,11 +12,6 @@ class GalleryTest extends ApiTestCase { - protected function getApiClass() - { - return 'Imgur\Api\Gallery'; - } - /** * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required @@ -709,4 +704,9 @@ public function testCommentCount() $this->assertSame($expectedValue, $api->commentCount('VOMXz')); } + + protected function getApiClass() + { + return 'Imgur\Api\Gallery'; + } } diff --git a/tests/Api/ImageTest.php b/tests/Api/ImageTest.php index d71bdda..8032184 100644 --- a/tests/Api/ImageTest.php +++ b/tests/Api/ImageTest.php @@ -12,11 +12,6 @@ class ImageTest extends ApiTestCase { - protected function getApiClass() - { - return 'Imgur\Api\Image'; - } - /** * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required @@ -217,4 +212,9 @@ public function testFavorite() $this->assertSame($expectedValue, $api->favorite('ZOY11VC')); } + + protected function getApiClass() + { + return 'Imgur\Api\Image'; + } } diff --git a/tests/Api/MemegenTest.php b/tests/Api/MemegenTest.php index ab55903..ef7e6ae 100644 --- a/tests/Api/MemegenTest.php +++ b/tests/Api/MemegenTest.php @@ -12,11 +12,6 @@ class MemegenTest extends ApiTestCase { - protected function getApiClass() - { - return 'Imgur\Api\Memegen'; - } - /** * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required @@ -112,4 +107,9 @@ public function testMemegen() $this->assertSame($expectedValue, $api->defaultMemes()); } + + protected function getApiClass() + { + return 'Imgur\Api\Memegen'; + } } diff --git a/tests/Api/NotificationTest.php b/tests/Api/NotificationTest.php index 2803441..2ba5345 100644 --- a/tests/Api/NotificationTest.php +++ b/tests/Api/NotificationTest.php @@ -12,11 +12,6 @@ class NotificationTest extends ApiTestCase { - protected function getApiClass() - { - return 'Imgur\Api\Notification'; - } - /** * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required @@ -143,4 +138,9 @@ public function testNotificationViewed() $this->assertSame($expectedValue, $api->notificationViewed('76878181')); } + + protected function getApiClass() + { + return 'Imgur\Api\Notification'; + } } diff --git a/tests/Api/TopicTest.php b/tests/Api/TopicTest.php index d28406b..18feb22 100644 --- a/tests/Api/TopicTest.php +++ b/tests/Api/TopicTest.php @@ -12,11 +12,6 @@ class TopicTest extends ApiTestCase { - protected function getApiClass() - { - return 'Imgur\Api\Topic'; - } - /** * @expectedException \Imgur\Exception\ErrorException * @expectedExceptionMessage Authentication required @@ -204,4 +199,9 @@ public function testGalleryTopicItem() $this->assertSame($expectedValue, $api->galleryTopicItem(155, 'Fbae9SG')); } + + protected function getApiClass() + { + return 'Imgur\Api\Topic'; + } } diff --git a/tests/Auth/OAuth2Test.php b/tests/Auth/OAuth2Test.php index 7a07e80..8fd17b4 100644 --- a/tests/Auth/OAuth2Test.php +++ b/tests/Auth/OAuth2Test.php @@ -9,7 +9,7 @@ use Imgur\Auth\OAuth2; use Imgur\HttpClient\HttpClient; -class OAuth2Test extends \PHPUnit_Framework_TestCase +class OAuth2Test extends \PHPUnit\Framework\TestCase { public function testGetAuthenticationUrl() { @@ -165,5 +165,7 @@ public function testAuthenticatedRequest() $auth->requestAccessToken('code', null); $httpClient->get('http://google.com'); + + $this->assertTrue($auth->checkAccessTokenExpired()); } } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index bc9ae60..0aea8d3 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -4,34 +4,8 @@ use Imgur\Client; -class ClientTest extends \PHPUnit_Framework_TestCase +class ClientTest extends \PHPUnit\Framework\TestCase { - private function getHttpClientMock(array $methods = []) - { - $methods = array_merge( - ['get', 'post', 'delete', 'request', 'performRequest', 'createRequest', 'parseResponse'], - $methods - ); - - return $this->getMockBuilder('Imgur\HttpClient\HttpClient') - ->disableOriginalConstructor() - ->setMethods($methods) - ->getMock(); - } - - private function getAuthenticationClientMock(array $methods = []) - { - $methods = array_merge( - ['getAuthenticationUrl', 'getAccessToken', 'requestAccessToken', 'setAccessToken', 'sign', 'refreshToken'], - $methods - ); - - return $this->getMockBuilder('Imgur\Auth\OAuth2') - ->disableOriginalConstructor() - ->setMethods($methods) - ->getMock(); - } - public function testNoParameters() { $client = new Client(); @@ -191,4 +165,30 @@ public function testSetAccessToken() $client = new Client($authenticationClient, $httpClient); $client->setAccessToken('token'); } + + private function getHttpClientMock(array $methods = []) + { + $methods = array_merge( + ['get', 'post', 'delete', 'request', 'performRequest', 'createRequest', 'parseResponse'], + $methods + ); + + return $this->getMockBuilder('Imgur\HttpClient\HttpClient') + ->disableOriginalConstructor() + ->setMethods($methods) + ->getMock(); + } + + private function getAuthenticationClientMock(array $methods = []) + { + $methods = array_merge( + ['getAuthenticationUrl', 'getAccessToken', 'requestAccessToken', 'setAccessToken', 'sign', 'refreshToken'], + $methods + ); + + return $this->getMockBuilder('Imgur\Auth\OAuth2') + ->disableOriginalConstructor() + ->setMethods($methods) + ->getMock(); + } } diff --git a/tests/HttpClient/HttpClientTest.php b/tests/HttpClient/HttpClientTest.php index 7b02e95..e8e91a8 100644 --- a/tests/HttpClient/HttpClientTest.php +++ b/tests/HttpClient/HttpClientTest.php @@ -8,7 +8,7 @@ use GuzzleHttp\Subscriber\Mock; use Imgur\HttpClient\HttpClient; -class HttpClientTest extends \PHPUnit_Framework_TestCase +class HttpClientTest extends \PHPUnit\Framework\TestCase { public function testOptionsToConstructor() { diff --git a/tests/Listener/AuthListenerTest.php b/tests/Listener/AuthListenerTest.php index 2a9ad3f..4b43e2b 100644 --- a/tests/Listener/AuthListenerTest.php +++ b/tests/Listener/AuthListenerTest.php @@ -3,10 +3,9 @@ namespace Imgur\Tests\HttpClient; use GuzzleHttp\Message\Request; -use Imgur\Client; use Imgur\Listener\AuthListener; -class AuthListenerTest extends \PHPUnit_Framework_TestCase +class AuthListenerTest extends \PHPUnit\Framework\TestCase { public function testDefineClientIdOnBadToken() { diff --git a/tests/Listener/ErrorListenerTest.php b/tests/Listener/ErrorListenerTest.php index c2a333e..123a3cd 100644 --- a/tests/Listener/ErrorListenerTest.php +++ b/tests/Listener/ErrorListenerTest.php @@ -5,7 +5,7 @@ use Guzzle\Http\Message\Request; use Imgur\Listener\ErrorListener; -class ErrorListenerTest extends \PHPUnit_Framework_TestCase +class ErrorListenerTest extends \PHPUnit\Framework\TestCase { public function testNothinHappenOnOKResponse() { @@ -118,6 +118,42 @@ public function testErrorWithJson() $listener->error($this->getEventMock($response)); } + /** + * @expectedException \Imgur\Exception\ErrorException + * @expectedExceptionMessage Request failed with: "Imgur is temporarily over capacity. Please try again later." + */ + public function testErrorOverCapacity() + { + $response = $this->getMockBuilder('GuzzleHttp\Message\ResponseInterface') + ->disableOriginalConstructor() + ->getMock(); + $response->expects($this->exactly(2)) + ->method('getStatusCode') + ->will($this->returnValue(429)); + $response->expects($this->once()) + ->method('getBody') + ->will($this->returnValue(json_encode(['status' => 500, 'success' => false, 'data' => ['error' => 'Imgur is temporarily over capacity. Please try again later.']]))); + $response->expects($this->at(1)) + ->method('getHeader') + ->with('X-RateLimit-UserRemaining') + ->will($this->returnValue(9)); + $response->expects($this->at(2)) + ->method('getHeader') + ->with('X-RateLimit-UserLimit') + ->will($this->returnValue(10)); + $response->expects($this->at(3)) + ->method('getHeader') + ->with('X-RateLimit-ClientRemaining') + ->will($this->returnValue(9)); + $response->expects($this->at(4)) + ->method('getHeader') + ->with('X-RateLimit-ClientLimit') + ->will($this->returnValue(10)); + + $listener = new ErrorListener(); + $listener->error($this->getEventMock($response)); + } + /** * @expectedException \Imgur\Exception\RuntimeException * @expectedExceptionMessage hihi