Version 5.1 - All the GraphQL #32

Closed
timw4mail wants to merge 1160 commits from develop into master
8 changed files with 58 additions and 54 deletions
Showing only changes of commit c71ff7f38e - Show all commits

View File

@ -32,8 +32,7 @@ trait MutationTrait {
* Create a list item
*
* @param array $data
* @return Request
* @throws InvalidArgumentException
* @return Request|null
*/
public function createListItem(array $data): ?Request
{

View File

@ -405,7 +405,7 @@ final class Kitsu {
if (empty($parts))
{
return $last;
return ($last !== NULL) ? $last : '';
}
return (count($parts) > 1)

View File

@ -50,6 +50,11 @@ final class AnimeCollection extends Collection {
*/
public function getCollection(): array
{
if ($this->db === NULL)
{
return [];
}
$rawCollection = $this->getCollectionFromDatabase();
$collection = [];
@ -76,7 +81,7 @@ final class AnimeCollection extends Collection {
*/
public function getFlatCollection(): array
{
if ( ! $this->validDatabase)
if ($this->db === NULL)
{
return [];
}
@ -122,7 +127,7 @@ final class AnimeCollection extends Collection {
*/
public function getMediaTypeList(): array
{
if ($this->validDatabase === FALSE)
if ($this->db === NULL)
{
return [];
}
@ -174,7 +179,7 @@ final class AnimeCollection extends Collection {
*/
public function add(mixed $data): void
{
if ($this->validDatabase === FALSE)
if ($this->db === NULL)
{
return;
}
@ -213,7 +218,7 @@ final class AnimeCollection extends Collection {
*/
public function wasAdded(array $data): bool
{
if ($this->validDatabase === FALSE)
if ($this->db === NULL)
{
return FALSE;
}
@ -231,7 +236,7 @@ final class AnimeCollection extends Collection {
*/
public function update(array $data): void
{
if ($this->validDatabase === FALSE)
if ($this->db === NULL)
{
return;
}
@ -270,7 +275,7 @@ final class AnimeCollection extends Collection {
*/
public function wasUpdated(array $data): bool
{
if ($this->validDatabase === FALSE)
if ($this->db === NULL)
{
return FALSE;
}
@ -301,7 +306,7 @@ final class AnimeCollection extends Collection {
*/
public function delete(array $data): void
{
if ($this->validDatabase === FALSE)
if ($this->db === NULL)
{
return;
}
@ -332,7 +337,7 @@ final class AnimeCollection extends Collection {
*/
public function wasDeleted(array $data): bool
{
if ($this->validDatabase === FALSE)
if ($this->db === NULL)
{
return FALSE;
}
@ -348,7 +353,7 @@ final class AnimeCollection extends Collection {
*/
public function get(int|string $kitsuId): array
{
if ($this->validDatabase === FALSE)
if ($this->db === NULL)
{
return [];
}
@ -389,7 +394,7 @@ final class AnimeCollection extends Collection {
*/
public function has(int|string $kitsuId): bool
{
if ($this->validDatabase === FALSE)
if ($this->db === NULL)
{
return FALSE;
}
@ -411,7 +416,7 @@ final class AnimeCollection extends Collection {
*/
public function getGenreList(array $filter = []): array
{
if ($this->validDatabase === FALSE)
if ($this->db === NULL)
{
return [];
}
@ -479,7 +484,7 @@ final class AnimeCollection extends Collection {
*/
public function getMediaList(array $filter = []): array
{
if ($this->validDatabase === FALSE)
if ($this->db === NULL)
{
return [];
}
@ -541,6 +546,11 @@ final class AnimeCollection extends Collection {
private function updateMediaLink(string $animeId, array $media): void
{
if ($this->db === NULL)
{
return;
}
$this->db->beginTransaction();
// Delete the old entries
@ -570,7 +580,7 @@ final class AnimeCollection extends Collection {
*/
private function updateGenres($animeId): void
{
if ($this->validDatabase === FALSE)
if ($this->db === NULL)
{
return;
}
@ -604,13 +614,13 @@ final class AnimeCollection extends Collection {
}
}
if ( ! empty($linksToInsert))
if ($this->db !== NULL && ! empty($linksToInsert))
{
try
{
$this->db->insertBatch('anime_set_genre_link', $linksToInsert);
}
catch (PDOException $e) {}
catch (PDOException) {}
}
}
@ -621,7 +631,7 @@ final class AnimeCollection extends Collection {
*/
private function addNewGenres(array $genres): void
{
if ($this->validDatabase === FALSE)
if ($this->db === NULL)
{
return;
}
@ -663,7 +673,7 @@ final class AnimeCollection extends Collection {
private function getExistingGenres(): array
{
if ($this->validDatabase === FALSE)
if ($this->db === NULL)
{
return [];
}
@ -693,7 +703,7 @@ final class AnimeCollection extends Collection {
private function getExistingGenreLinkEntries(): array
{
if ($this->validDatabase === FALSE)
if ($this->db === NULL)
{
return [];
}
@ -734,7 +744,7 @@ final class AnimeCollection extends Collection {
*/
private function getCollectionFromDatabase(): array
{
if ( ! $this->validDatabase)
if ($this->db === NULL)
{
return [];
}

View File

@ -29,15 +29,9 @@ class Collection extends DB {
/**
* The query builder object
* @var QueryBuilderInterface
* @var QueryBuilderInterface|null
*/
protected QueryBuilderInterface $db;
/**
* Whether the database is valid for querying
* @var boolean
*/
protected bool $validDatabase = FALSE;
protected ?QueryBuilderInterface $db;
/**
* Create a new collection object
@ -51,9 +45,8 @@ class Collection extends DB {
try
{
$this->db = Query($this->dbConfig);
$this->validDatabase = TRUE;
}
catch (PDOException $e)
catch (PDOException)
{
$this->db = Query([
'type' => 'sqlite',
@ -71,16 +64,8 @@ class Collection extends DB {
{
$rawFile = file_get_contents($dbFileName);
$dbFile = ($rawFile !== FALSE) ? $rawFile : '';
$this->validDatabase = str_starts_with($dbFile, 'SQLite format 3');
$this->db = (str_starts_with($dbFile, 'SQLite format 3')) ? $this->db : NULL;
}
else
{
$this->validDatabase = FALSE;
}
}
else if ($this->db === NULL)
{
$this->validDatabase = FALSE;
}
}
}

View File

@ -100,7 +100,13 @@ trait MediaTrait {
public function createLibraryItem(array $data): bool
{
$requester = new ParallelAPIRequest();
$requester->addRequest($this->kitsuModel->createListItem($data), 'kitsu');
$kitsuRequest = $this->kitsuModel->createListItem($data);
if ($kitsuRequest === NULL)
{
return FALSE;
}
$requester->addRequest($kitsuRequest, 'kitsu');
if ($this->anilistEnabled && $data['mal_id'] !== null)
{

View File

@ -124,6 +124,10 @@ final class Settings {
public function validateSettings(array $settings): array
{
$cfg = Config::check($settings);
if ( ! is_iterable($cfg))
{
return [];
}
$looseConfig = [];
$keyedConfig = [];

View File

@ -72,7 +72,7 @@ class UrlGenerator extends RoutingBase {
{
$path = trim($path, '/');
$path = preg_replace('`{/.*?}`i', '', $path);
$path = preg_replace('`{/.*?}`i', '', $path) ?? "";
// Remove any optional parameters from the route
// and replace them with existing route parameters, if they exist
@ -87,7 +87,7 @@ class UrlGenerator extends RoutingBase {
$segments[$i + 1] = '';
}
$pathSegments[$i] = preg_replace('`{.*?}`', $segments[$i + 1], $pathSegments[$i]);
$pathSegments[$i] = preg_replace('`{.*?}`', $segments[$i + 1], $pathSegments[$i] ?? '');
}
$path = implode('/', $pathSegments);

View File

@ -101,7 +101,7 @@ class ArrayType {
* @return mixed
* @throws InvalidArgumentException
*/
public function __call(string $method, array $args)
public function __call(string $method, array $args): mixed
{
// Simple mapping for the majority of methods
if (array_key_exists($method, $this->nativeMethods))
@ -128,7 +128,7 @@ class ArrayType {
* @param int|string|array $key
* @return bool
*/
public function hasKey($key): bool
public function hasKey(int|string|array $key): bool
{
if (\is_array($key))
{
@ -158,7 +158,7 @@ class ArrayType {
* @param mixed $value
* @return array
*/
public function fill(int $start_index, int $num, $value): array
public function fill(int $start_index, int $num, mixed $value): array
{
return array_fill($start_index, $num, $value);
}
@ -179,9 +179,9 @@ class ArrayType {
*
* @param mixed $value
* @param bool $strict
* @return false|integer|string
* @return false|integer|string|null
*/
public function search($value, bool $strict = TRUE)
public function search(mixed $value, bool $strict = TRUE): int|string|false|null
{
return array_search($value, $this->arr, $strict);
}
@ -193,7 +193,7 @@ class ArrayType {
* @param bool $strict
* @return bool
*/
public function has($value, bool $strict = TRUE): bool
public function has(mixed $value, bool $strict = TRUE): bool
{
return \in_array($value, $this->arr, $strict);
}
@ -204,7 +204,7 @@ class ArrayType {
* @param string|integer|null $key
* @return mixed
*/
public function &get($key = NULL)
public function &get(string|int|null $key = NULL): mixed
{
$value = NULL;
if ($key === NULL)
@ -229,7 +229,7 @@ class ArrayType {
* @param mixed $value
* @return ArrayType
*/
public function set($key, $value): ArrayType
public function set(mixed $key, mixed $value): ArrayType
{
$this->arr[$key] = $value;
return $this;
@ -244,7 +244,7 @@ class ArrayType {
* @param array $key An array of keys of the array
* @return mixed
*/
public function &getDeepKey(array $key)
public function &getDeepKey(array $key): mixed
{
$pos =& $this->arr;
@ -273,7 +273,7 @@ class ArrayType {
* @param mixed $value
* @return array
*/
public function setDeepKey(array $key, $value): array
public function setDeepKey(array $key, mixed $value): array
{
$pos =& $this->arr;