Skip to content

Commit

Permalink
Enable PHPStan and type everything
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r committed Dec 3, 2021
1 parent 1ed3cc7 commit abce329
Show file tree
Hide file tree
Showing 41 changed files with 853 additions and 825 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ jobs:

- name: "Run PHP CS Fixer"
run: "vendor/bin/php-cs-fixer fix --verbose --dry-run"

- name: "Install PHPUnit for PHPStan"
run: "php vendor/bin/simple-phpunit install"

- name: "Run PHPStan"
run: "php vendor/bin/phpstan analyse --no-progress"
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.2",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"symfony/phpunit-bridge": "^6.0"
},
"config": {
Expand Down
47 changes: 14 additions & 33 deletions lib/Imgur/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
abstract class AbstractApi
{
/**
* @var \Imgur\Client
* @var Client
*/
protected $client;

/**
* @var \Imgur\Pager\PagerInterface
* @var PagerInterface
*/
protected $pager;

Expand All @@ -31,16 +31,12 @@ public function __construct(Client $client, PagerInterface $pager = null)

/**
* Perform a GET request and return the parsed response.
*
* @param string $url
*
* @return array
*/
public function get($url, $parameters = [])
public function get(string $url, array $parameters = []): array
{
$httpClient = $this->client->getHttpClient();

if (!empty($this->pager)) {
if (null !== $this->pager) {
$parameters['page'] = $this->pager->getPage();
$parameters['perPage'] = $this->pager->getResultsPerPage();
}
Expand All @@ -52,12 +48,8 @@ public function get($url, $parameters = [])

/**
* Perform a POST request and return the parsed response.
*
* @param string $url
*
* @return array
*/
public function post($url, $parameters = [])
public function post(string $url, array $parameters = []): array
{
$httpClient = $this->client->getHttpClient();

Expand All @@ -68,12 +60,8 @@ public function post($url, $parameters = [])

/**
* Perform a PUT request and return the parsed response.
*
* @param string $url
*
* @return array
*/
public function put($url, $parameters = [])
public function put(string $url, array $parameters = []): array
{
$httpClient = $this->client->getHttpClient();

Expand All @@ -84,12 +72,8 @@ public function put($url, $parameters = [])

/**
* Perform a DELETE request and return the parsed response.
*
* @param string $url
*
* @return array
*/
public function delete($url, $parameters = [])
public function delete(string $url, array $parameters = []): array
{
$httpClient = $this->client->getHttpClient();

Expand All @@ -101,32 +85,29 @@ public function delete($url, $parameters = [])
/**
* Validate "sort" parameter and throw an exception if it's a bad value.
*
* @param string $sort Input value
* @param array $possibleValues
* @param string $sort Input value
*/
protected function validateSortArgument($sort, $possibleValues)
protected function validateSortArgument(string $sort, array $possibleValues): void
{
$this->validateArgument('Sort', $sort, $possibleValues);
}

/**
* Validate "window" parameter and throw an exception if it's a bad value.
*
* @param string $window Input value
* @param array $possibleValues
* @param string $window Input value
*/
protected function validateWindowArgument($window, $possibleValues)
protected function validateWindowArgument(string $window, array $possibleValues): void
{
$this->validateArgument('Window', $window, $possibleValues);
}

/**
* Validate "vote" parameter and throw an exception if it's a bad value.
*
* @param string $vote Input value
* @param array $possibleValues
* @param string $vote Input value
*/
protected function validateVoteArgument($vote, $possibleValues)
protected function validateVoteArgument(string $vote, array $possibleValues): void
{
$this->validateArgument('Vote', $vote, $possibleValues);
}
Expand All @@ -138,7 +119,7 @@ protected function validateVoteArgument($vote, $possibleValues)
* @param string $input Input value
* @param array $possibleValues Possible values for this argument
*/
private function validateArgument($type, $input, $possibleValues)
private function validateArgument(string $type, string $input, array $possibleValues): void
{
if (!\in_array($input, $possibleValues, true)) {
throw new InvalidArgumentException($type . ' parameter "' . $input . '" is wrong. Possible values are: ' . implode(', ', $possibleValues));
Expand Down
26 changes: 13 additions & 13 deletions lib/Imgur/Api/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function base($username = 'me')
*
* @param string $username
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function deleteAccount($username)
{
Expand Down Expand Up @@ -106,7 +106,7 @@ public function settings($username = 'me')
*
* @see https://api.imgur.com/endpoints/account#update-settings
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function changeAccountSettings($parameters)
{
Expand Down Expand Up @@ -147,7 +147,7 @@ public function accountGalleryProfile($username = 'me')
*
* @see https://api.imgur.com/endpoints/account#verify-email
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function verifyUsersEmail($username = 'me')
{
Expand All @@ -161,7 +161,7 @@ public function verifyUsersEmail($username = 'me')
*
* @see https://api.imgur.com/endpoints/account#send-verify-email
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function sendVerificationEmail($username = 'me')
{
Expand Down Expand Up @@ -207,7 +207,7 @@ public function album($albumId, $username = 'me')
*
* @see https://api.imgur.com/endpoints/account#album-ids
*
* @return array<int>
* @return array (@see https://api.imgur.com/models/basic)
*/
public function albumIds($username = 'me', $page = 0)
{
Expand All @@ -221,7 +221,7 @@ public function albumIds($username = 'me', $page = 0)
*
* @see https://api.imgur.com/endpoints/account#album-count
*
* @return int
* @return array (@see https://api.imgur.com/models/basic)
*/
public function albumCount($username = 'me')
{
Expand All @@ -236,7 +236,7 @@ public function albumCount($username = 'me')
*
* @see https://api.imgur.com/endpoints/account#album-delete
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function albumDelete($albumId, $username = 'me')
{
Expand Down Expand Up @@ -286,7 +286,7 @@ public function comment($commentId, $username = 'me')
*
* @see https://api.imgur.com/endpoints/account#comment-ids
*
* @return array<int>
* @return array (@see https://api.imgur.com/models/basic)
*/
public function commentIds($username = 'me', $page = 0, $sort = 'newest')
{
Expand All @@ -302,7 +302,7 @@ public function commentIds($username = 'me', $page = 0, $sort = 'newest')
*
* @see https://api.imgur.com/endpoints/account#comment-count
*
* @return int
* @return array (@see https://api.imgur.com/models/basic)
*/
public function commentCount($username = 'me')
{
Expand All @@ -317,7 +317,7 @@ public function commentCount($username = 'me')
*
* @see https://api.imgur.com/endpoints/account#comment-delete
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function commentDelete($commentId, $username = 'me')
{
Expand Down Expand Up @@ -364,7 +364,7 @@ public function image($imageId, $username = 'me')
*
* @see https://api.imgur.com/endpoints/account#image-ids
*
* @return array<int>
* @return array (@see https://api.imgur.com/models/basic)
*/
public function imageIds($username = 'me', $page = 0)
{
Expand All @@ -378,7 +378,7 @@ public function imageIds($username = 'me', $page = 0)
*
* @see https://api.imgur.com/endpoints/account#image-count
*
* @return int
* @return array (@see https://api.imgur.com/models/basic)
*/
public function imageCount($username = 'me')
{
Expand All @@ -393,7 +393,7 @@ public function imageCount($username = 'me')
*
* @see https://api.imgur.com/endpoints/account#image-delete
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function imageDelete($deleteHash, $username = 'me')
{
Expand Down
14 changes: 7 additions & 7 deletions lib/Imgur/Api/Album.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function albumImage($albumId, $imageId)
*
* @see https://api.imgur.com/endpoints/album#album-upload
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function create($data)
{
Expand All @@ -80,7 +80,7 @@ public function create($data)
*
* @see https://api.imgur.com/endpoints/album#album-update
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function update($deletehashOrAlbumId, $data)
{
Expand All @@ -96,7 +96,7 @@ public function update($deletehashOrAlbumId, $data)
*
* @see https://api.imgur.com/endpoints/album#album-delete
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function deleteAlbum($deletehashOrAlbumId)
{
Expand All @@ -110,7 +110,7 @@ public function deleteAlbum($deletehashOrAlbumId)
*
* @see https://api.imgur.com/endpoints/album#album-favorite
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function favoriteAlbum($albumId)
{
Expand All @@ -125,7 +125,7 @@ public function favoriteAlbum($albumId)
*
* @see https://api.imgur.com/endpoints/album#album-set-to
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function setAlbumImages($albumId, array $imageIds)
{
Expand All @@ -140,7 +140,7 @@ public function setAlbumImages($albumId, array $imageIds)
*
* @see https://api.imgur.com/endpoints/album#album-add-to
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function addImages($albumId, array $imageIds)
{
Expand All @@ -155,7 +155,7 @@ public function addImages($albumId, array $imageIds)
*
* @see https://api.imgur.com/endpoints/album#album-remove-from
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function removeImages($deletehashOrAlbumId, array $imageIds)
{
Expand Down
10 changes: 5 additions & 5 deletions lib/Imgur/Api/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function comment($commentId)
*
* @see https://api.imgur.com/endpoints/comment#comment-create
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function create($data)
{
Expand All @@ -52,7 +52,7 @@ public function create($data)
*
* @see https://api.imgur.com/endpoints/comment#comment-delete
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function deleteComment($commentId)
{
Expand Down Expand Up @@ -81,7 +81,7 @@ public function replies($commentId)
*
* @see https://api.imgur.com/endpoints/comment#comment-reply-create
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function createReply($commentId, $data)
{
Expand All @@ -100,7 +100,7 @@ public function createReply($commentId, $data)
*
* @see https://api.imgur.com/endpoints/comment#comment-vote
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function vote($commentId, $vote)
{
Expand All @@ -116,7 +116,7 @@ public function vote($commentId, $vote)
*
* @see https://api.imgur.com/endpoints/comment#comment-report
*
* @return bool
* @return array (@see https://api.imgur.com/models/basic)
*/
public function report($commentId)
{
Expand Down
Loading

0 comments on commit abce329

Please sign in to comment.