Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
Add missing return types in src
Browse files Browse the repository at this point in the history
  • Loading branch information
owenvoke committed Mar 7, 2019
1 parent 22bde91 commit 9e6765e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 41 deletions.
30 changes: 15 additions & 15 deletions src/Movies.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ class Movies
* @return Collection
* @throws \Exception
*/
public static function list(array $options = [])
public static function list(array $options = []): Collection
{
$options = array_merge([
'quality' => Movies::QUALITY_ALL,
'query_term' => 0,
'page' => 1,
'minimum_rating' => 0,
'genre' => '',
'sort_by' => 'date-added',
'order_by' => 'desc',
'quality' => self::QUALITY_ALL,
'query_term' => 0,
'page' => 1,
'minimum_rating' => 0,
'genre' => '',
'sort_by' => 'date-added',
'order_by' => 'desc',
'with_rt_ratings' => false,
], $options);

$response = YTS::getFromApi('list_movies.json', $options);

return Movies::buildCollection($response['data']['movies']);
return self::buildCollection($response['data']['movies']);
}

/**
Expand All @@ -45,12 +45,12 @@ public static function list(array $options = [])
* @return Movie
* @throws \Exception
*/
public static function details(array $options = [])
public static function details(array $options = []): Movie
{
$options = array_merge([
'movie_id' => null,
'movie_id' => null,
'with_images' => false,
'with_cast' => false,
'with_cast' => false,
], $options);

$response = YTS::getFromApi('movie_details.json', $options);
Expand All @@ -64,7 +64,7 @@ public static function details(array $options = [])
* @return Collection
* @throws \Exception
*/
public static function suggestions(array $options = [])
public static function suggestions(array $options = []): Collection
{
$options = array_merge([
'movie_id' => null,
Expand All @@ -73,7 +73,7 @@ public static function suggestions(array $options = [])
$response = YTS::getFromApi('movie_suggestions.json', $options);

if (isset($response['data']['movies'])) {
return Movies::buildCollection($response['data']['movies']);
return self::buildCollection($response['data']['movies']);
}

throw new Exceptions\NoDataFoundException();
Expand All @@ -84,7 +84,7 @@ public static function suggestions(array $options = [])
* @param array $data
* @return Collection
*/
public static function buildCollection(array $data)
public static function buildCollection(array $data): Collection
{
$collection = new Collection();

Expand Down
8 changes: 2 additions & 6 deletions src/Torrents.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@

class Torrents
{
/**
* Build a Collection of Torrent classes from an array.
* @param array $data
* @return Collection
*/
public static function buildCollection(array $data)
/* Build a Collection of Torrent classes from an array. */
public static function buildCollection(array $data): Collection
{
$collection = new Collection();

Expand Down
32 changes: 12 additions & 20 deletions src/YTS.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,33 @@ class YTS
/** The current version of the API. */
public const API_VERSION = 2;
/** The base uri of the API. */
public const BASE_URI = 'https://yts.am/api/v'.YTS::API_VERSION.'/';
public const BASE_URI = 'https://yts.am/api/v'.self::API_VERSION.'/';

/** @var Client */
private static $client;

/**
* Retrieve the array response from the API endpoint.
* @param string $endpoint
* @param array $parameters
* @return array|null
*/
public static function getFromApi($endpoint, $parameters = [])
/* Retrieve the array response from the API endpoint. */
public static function getFromApi(string $endpoint, array $parameters = []): ?array
{
$response = YTS::getClient()
->get($endpoint, ['query' => $parameters]);
$response = self::getClient()
->get($endpoint, ['query' => $parameters]);

return \GuzzleHttp\json_decode(
$response->getBody()
->getContents(),
->getContents(),
true
);
}

/**
* Retrieve the current GuzzleHttp Client instance.
* @return Client
*/
private static function getClient()
/* Retrieve the current GuzzleHttp Client instance. */
private static function getClient(): Client
{
if (!YTS::$client instanceof Client) {
YTS::$client = new Client([
'base_uri' => YTS::BASE_URI,
if (!self::$client instanceof Client) {
self::$client = new Client([
'base_uri' => self::BASE_URI,
]);
}

return YTS::$client;
return self::$client;
}
}

0 comments on commit 9e6765e

Please sign in to comment.