fix: tmdb service phpstan ci

This commit is contained in:
Roardom
2023-12-30 11:01:33 +00:00
parent dfcee2a6df
commit fd12439113
13 changed files with 50 additions and 135 deletions
+2 -2
View File
@@ -479,7 +479,7 @@ Menu
$tmdbScraper = new TMDBScraper();
$tmdbScraper->movie($id);
return (new Movie($id))->getData();
return (new Movie($id))->data;
}
private function fetchTv($id)
@@ -488,7 +488,7 @@ Menu
$tmdbScraper = new TMDBScraper();
$tmdbScraper->tv($id);
return (new TV($id))->getData();
return (new TV($id))->data;
}
private function movie_ids(): array
+2 -2
View File
@@ -62,9 +62,9 @@ class WishController extends Controller
''
]);
$meta = (new Movie($request->tmdb))->getData();
$meta = (new Movie($request->tmdb))->data;
if ($meta === null || $meta === false) {
if ($meta === null) {
return to_route('users.wishes.index', ['user' => $user])
->withErrors('TMDM Bad Request!');
}
+1 -1
View File
@@ -40,7 +40,7 @@ class ProcessTvJob implements ShouldQueue
/**
* ProcessTvJob Constructor.
*/
public function __construct(public $id)
public function __construct(public int $id)
{
}
-5
View File
@@ -65,11 +65,6 @@ class Collection
$this->tmdb = new TMDB();
}
public function getData(): mixed
{
return $this->data;
}
/**
* @return array{
* id: int,
-5
View File
@@ -46,11 +46,6 @@ class Company
->json();
}
public function getData(): mixed
{
return $this->data;
}
/**
* @return array{
* id: ?int,
+1 -6
View File
@@ -243,11 +243,6 @@ class Movie
$this->tmdb = new TMDB();
}
public function getData(): ?array
{
return $this->data;
}
/**
* @return null|array{
* adult: bool,
@@ -390,7 +385,7 @@ class Movie
{
$movie_ids = \App\Models\Movie::query()
->select('id')
->findMany(array_column($this->data['recommendations']['results'] ?? [], 'id'))
->whereIntegerInRaw('id', array_column($this->data['recommendations']['results'] ?? [], 'id'))
->pluck('id');
$recommendations = [];
+8 -6
View File
@@ -61,13 +61,15 @@ class Network
$this->tmdb = new TMDB();
}
public function getData(): mixed
{
return $this->data;
}
/**
* @return array
* @return null|array{
* id: ?int,
* headquarters: ?string,
* homepage: ?string,
* logo: ?string,
* name: ?string,
* origin_country: ?string,
* }
*/
public function getNetwork(): ?array
{
-5
View File
@@ -54,11 +54,6 @@ class Person
$this->tmdb = new TMDB();
}
public function getData(): mixed
{
return $this->data;
}
/**
* @return array{
* id: ?int,
+17 -18
View File
@@ -98,11 +98,6 @@ class Season
$this->tmdb = new TMDB();
}
public function getData(): mixed
{
return $this->data;
}
/**
* @return array{
* id: int,
@@ -128,19 +123,23 @@ class Season
}
/**
* @return array{
* id: int,
* tv_id: int,
* air_date: ?string,
* name: ?string,
* episode_number: ?int,
* overview: ?string,
* still: ?string,
* production_code: ?string,
* season_number: ?int,
* vote_average: ?float,
* vote_count: ?int,
* season_id: int,
* @return array<
* int<0, max>,
* array{
* id: int,
* tv_id: int,
* air_date: ?string,
* name: ?string,
* episode_number: ?int,
* overview: ?string,
* still: ?string,
* production_code: ?string,
* season_number: ?int,
* vote_average: ?float,
* vote_count: ?int,
* season_id: int,
* }
* >
*/
public function getEpisodes(): array
{
+1 -6
View File
@@ -309,11 +309,6 @@ class TV
$this->tmdb = new TMDB();
}
public function getData(): mixed
{
return $this->data;
}
/**
* @return ?array{
* backdrop: ?string,
@@ -489,7 +484,7 @@ class TV
{
$tv_ids = \App\Models\Tv::query()
->select('id')
->findMany(array_column($this->data['recommendations']['results'] ?? [], 'id'))
->whereIntegerInRaw('id', array_column($this->data['recommendations']['results'] ?? [], 'id'))
->pluck('id');
$recommendations = [];
+17 -37
View File
@@ -15,7 +15,10 @@ namespace App\Services\Tmdb;
class TMDB
{
public function image($type, $array): ?string
/**
* @param array<mixed> $array
*/
public function image(string $type, array $array): ?string
{
if (isset($array[$type.'_path'])) {
return 'https://image.tmdb.org/t/p/original'.$array[$type.'_path'];
@@ -24,7 +27,10 @@ class TMDB
return null;
}
public function trailer($array): ?string
/**
* @param array<mixed> $array
*/
public function trailer(array $array): ?string
{
if (isset($array['videos']['results'])) {
return 'https://www.youtube.com/embed/'.$array['videos']['results'][0]['key'];
@@ -33,49 +39,23 @@ class TMDB
return null;
}
public function ifHasItems($type, $array)
/**
* @param array<mixed> $array
*/
public function ifHasItems(string $type, array $array): mixed
{
return $array[$type][0] ?? null;
}
public function ifExists($type, $array)
/**
* @param array<mixed> $array
*/
public function ifExists(string $type, array $array): mixed
{
if (isset($array[$type]) && !empty($array[$type])) {
return $array[$type];
}
return;
}
public function cast_array($cast): array
{
return [
'character' => $cast['character'],
'credit_id' => $cast['credit_id'],
'gender' => $cast['gender'],
'name' => $cast['name'],
'order' => $cast['order'],
'still' => $this->image('profile', $cast),
];
}
public function person_array($person): array
{
return [
'id' => $this->ifExists('id', $person),
'birthday' => $this->ifExists('birthday', $person),
'known_for_department' => $this->ifExists('known_for_department', $person),
'deathday' => $this->ifExists('deathday', $person),
'name' => $this->ifExists('name', $person),
//"also_known_as" => $person['also_known_as'] ?? null,
'gender' => $this->ifExists('gender', $person),
'biography' => $this->ifExists('biography', $person),
'popularity' => $this->ifExists('popularity', $person),
'place_of_birth' => $this->ifExists('place_of_birth', $person),
'still' => $this->image('profile', $person),
'adult' => $this->ifExists('adult', $person),
'imdb_id' => $this->ifExists('imdb_id', $person),
'homepage' => $this->ifExists('homepage', $person),
];
return null;
}
}
+1 -7
View File
@@ -16,20 +16,14 @@ namespace App\Services\Tmdb;
use App\Jobs\ProcessMovieJob;
use App\Jobs\ProcessTvJob;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Http\Request;
use Illuminate\Queue\SerializesModels;
class TMDBScraper implements ShouldQueue
{
use SerializesModels;
public int $id;
public function __construct(Request $request = null)
public function __construct()
{
if ($request != null) {
$this->id = $request->query('id');
}
}
public function tv(int $id): void
-35
View File
@@ -3470,16 +3470,6 @@ parameters:
count: 1
path: app/Jobs/ProcessBackup.php
-
message: "#^Method App\\\\Jobs\\\\ProcessCollectionJob\\:\\:__construct\\(\\) has parameter \\$collection with no type specified\\.$#"
count: 1
path: app/Jobs/ProcessCollectionJob.php
-
message: "#^Method App\\\\Jobs\\\\ProcessCompanyJob\\:\\:__construct\\(\\) has parameter \\$company with no type specified\\.$#"
count: 1
path: app/Jobs/ProcessCompanyJob.php
-
message: "#^Method App\\\\Jobs\\\\ProcessMassPM\\:\\:__construct\\(\\) has parameter \\$message with no type specified\\.$#"
count: 1
@@ -3500,31 +3490,6 @@ parameters:
count: 1
path: app/Jobs/ProcessMassPM.php
-
message: "#^Called 'pluck' on Laravel collection, but could have been retrieved as a query\\.$#"
count: 1
path: app/Jobs/ProcessMovieJob.php
-
message: "#^Method App\\\\Jobs\\\\ProcessMovieJob\\:\\:__construct\\(\\) has parameter \\$movie with no type specified\\.$#"
count: 1
path: app/Jobs/ProcessMovieJob.php
-
message: "#^Called 'pluck' on Laravel collection, but could have been retrieved as a query\\.$#"
count: 1
path: app/Jobs/ProcessTvJob.php
-
message: "#^Method App\\\\Jobs\\\\ProcessTvJob\\:\\:__construct\\(\\) has parameter \\$id with no type specified\\.$#"
count: 1
path: app/Jobs/ProcessTvJob.php
-
message: "#^Method App\\\\Jobs\\\\ProcessTvJob\\:\\:__construct\\(\\) has parameter \\$tv with no type specified\\.$#"
count: 1
path: app/Jobs/ProcessTvJob.php
-
message: "#^Method App\\\\Jobs\\\\SendActivationMail\\:\\:__construct\\(\\) has parameter \\$code with no type specified\\.$#"
count: 1