Move Kitsu class out of API namespace

This commit is contained in:
Timothy Warren 2020-08-26 15:22:14 -04:00
parent e20601053c
commit aace368b24
26 changed files with 62 additions and 321 deletions

View File

@ -1,6 +1,6 @@
<?php
use Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\Kitsu;
use function Aviat\AnimeClient\getLocalImg;
?>

View File

@ -1,4 +1,4 @@
<?php use function Aviat\AnimeClient\col_not_empty; ?>
<?php use function Aviat\AnimeClient\colNotEmpty; ?>
<main class="media-list">
<?php if ($auth->isAuthenticated()): ?>
<a class="bracketed" href="<?= $url->generate('anime.add.get') ?>">Add Item</a>
@ -15,7 +15,7 @@
<h3>There's nothing here!</h3>
<?php else: ?>
<?php
$hasNotes = col_not_empty($items, 'notes');
$hasNotes = colNotEmpty($items, 'notes');
?>
<table class='media-wrap'>
<thead>

View File

@ -1,7 +1,7 @@
<?php
use function Aviat\AnimeClient\getLocalImg;
use Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\Kitsu;
?>
<main class="character-page details fixed">

View File

@ -1,4 +1,4 @@
<?php use function Aviat\AnimeClient\col_not_empty; ?>
<?php use function Aviat\AnimeClient\colNotEmpty; ?>
<main>
<?php if ($auth->isAuthenticated()): ?>
<a class="bracketed" href="<?= $url->generate($collection_type . '.collection.add.get') ?>">Add Item</a>
@ -12,7 +12,7 @@
<?php $i = 0; ?>
<div class="tabs">
<?php foreach ($sections as $name => $items): ?>
<?php $hasNotes = col_not_empty($items, 'notes') ?>
<?php $hasNotes = colNotEmpty($items, 'notes') ?>
<input type="radio" id="collection-tab-<?= $i ?>" name="collection-tabs" />
<label for="collection-tab-<?= $i ?>"><h2><?= $name ?></h2></label>
<div class="content full-height">

View File

@ -1,6 +1,6 @@
<?php
use function Aviat\AnimeClient\getLocalImg;
use Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\Kitsu;
?>
<main class="details fixed">
<section class="flex flex-no-wrap">

View File

@ -1,5 +1,5 @@
<?php
use Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\Kitsu;
?>
<main class="user-page details">
<h2 class="toph">

View File

@ -17,9 +17,9 @@
namespace Aviat\AnimeClient\API\Kitsu;
use Amp\Http\Client\Request;
use Aviat\AnimeClient\Kitsu as K;
use Aviat\AnimeClient\API\Enum\AnimeWatchingStatus\Kitsu as KitsuWatchingStatus;
use Aviat\AnimeClient\API\JsonAPI;
use Aviat\AnimeClient\API\Kitsu as K;
use Aviat\AnimeClient\API\Kitsu\Transformer\AnimeHistoryTransformer;
use Aviat\AnimeClient\API\Kitsu\Transformer\AnimeListTransformer;
use Aviat\AnimeClient\API\Kitsu\Transformer\AnimeTransformer;
@ -100,7 +100,7 @@ trait AnimeTrait {
if ($list === NULL)
{
$raw = $this->getRawHistoryList('anime');
$raw = $this->getRawHistoryList();
$list = (new AnimeHistoryTransformer())->transform($raw);

View File

@ -20,10 +20,8 @@ use Aura\Session\Segment;
use const Aviat\AnimeClient\SESSION_SEGMENT;
use Aviat\AnimeClient\API\{
CacheTrait,
Kitsu as K
};
use Aviat\AnimeClient\Kitsu as K;
use Aviat\AnimeClient\API\CacheTrait;
use Aviat\Ion\Di\{ContainerAware, ContainerInterface};
use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException};
use Aviat\Ion\Event;

View File

@ -17,9 +17,9 @@
namespace Aviat\AnimeClient\API\Kitsu;
use Amp\Http\Client\Request;
use Aviat\AnimeClient\Kitsu as K;
use Aviat\AnimeClient\API\Enum\MangaReadingStatus\Kitsu as KitsuReadingStatus;
use Aviat\AnimeClient\API\JsonAPI;
use Aviat\AnimeClient\API\Kitsu as K;
use Aviat\AnimeClient\API\Kitsu\Transformer\MangaHistoryTransformer;
use Aviat\AnimeClient\API\Kitsu\Transformer\MangaListTransformer;
use Aviat\AnimeClient\API\Kitsu\Transformer\MangaTransformer;
@ -96,7 +96,7 @@ trait MangaTrait {
if ($list === NULL)
{
$raw = $this->getRawHistoryList('manga');
$raw = $this->getRawHistoryList();
$list = (new MangaHistoryTransformer())->transform($raw);
$this->cache->set($key, $list);

View File

@ -19,10 +19,10 @@ namespace Aviat\AnimeClient\API\Kitsu;
use function Amp\Promise\wait;
use Amp\Http\Client\Request;
use Aviat\AnimeClient\Kitsu as K;
use Aviat\AnimeClient\API\{
CacheTrait,
JsonAPI,
Kitsu as K,
ParallelAPIRequest
};
use Aviat\AnimeClient\API\Kitsu\Transformer\{

View File

@ -24,9 +24,9 @@ use function Aviat\AnimeClient\getResponse;
use Amp\Http\Client\Request;
use Amp\Http\Client\Response;
use Aviat\AnimeClient\Kitsu as K;
use Aviat\AnimeClient\API\APIRequestBuilder;
use Aviat\AnimeClient\API\FailedResponseException;
use Aviat\AnimeClient\API\Kitsu as K;
use Aviat\AnimeClient\Enum\EventType;
use Aviat\Ion\Di\ContainerAware;
use Aviat\Ion\Di\ContainerInterface;

View File

@ -16,7 +16,7 @@
namespace Aviat\AnimeClient\API\Kitsu\Transformer;
use Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\Kitsu;
use Aviat\AnimeClient\Types\{
FormItem,
AnimeListItem

View File

@ -16,7 +16,7 @@
namespace Aviat\AnimeClient\API\Kitsu\Transformer;
use Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\Kitsu;
use Aviat\AnimeClient\Types\AnimePage;
use Aviat\Ion\Transformer\AbstractTransformer;

View File

@ -16,7 +16,7 @@
namespace Aviat\AnimeClient\API\Kitsu\Transformer;
use Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\Kitsu;
use Aviat\AnimeClient\Types\Character;
use Aviat\Ion\Transformer\AbstractTransformer;

View File

@ -16,7 +16,7 @@
namespace Aviat\AnimeClient\API\Kitsu\Transformer;
use Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\Kitsu;
use Aviat\AnimeClient\Types\{FormItem, AnimeListItem, MangaListItem, MangaListItemDetail};
use Aviat\Ion\Transformer\AbstractTransformer;
use Aviat\Ion\Type\StringType;

View File

@ -16,7 +16,7 @@
namespace Aviat\AnimeClient\API\Kitsu\Transformer;
use Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\Kitsu;
use Aviat\AnimeClient\Types\{
FormItem, FormItemData,
MangaListItem, MangaListItemDetail

View File

@ -16,7 +16,7 @@
namespace Aviat\AnimeClient\API\Kitsu\Transformer;
use Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\Kitsu;
use Aviat\AnimeClient\Types\MangaPage;
use Aviat\Ion\Transformer\AbstractTransformer;

View File

@ -16,7 +16,7 @@
namespace Aviat\AnimeClient\API\Kitsu\Transformer;
use Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\Kitsu;
use function Aviat\AnimeClient\getLocalImg;
use Aviat\AnimeClient\Types\User;

View File

@ -16,7 +16,7 @@
namespace Aviat\AnimeClient;
use Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\Kitsu;
use Psr\SimpleCache\CacheInterface;
use Psr\SimpleCache\InvalidArgumentException;
use function Amp\Promise\wait;
@ -83,43 +83,6 @@ function loadTomlFile(string $filename): array
return Toml::parseFile($filename);
}
/**
* Recursively create a toml file from a data array
*
* @param TomlBuilder $builder
* @param iterable $data
* @param null $parentKey
*/
function _iterateToml(TomlBuilder $builder, iterable $data, $parentKey = NULL): void
{
foreach ($data as $key => $value)
{
if ($value === NULL)
{
continue;
}
if (is_scalar($value) || isSequentialArray($value))
{
// $builder->addTable('');
$builder->addValue($key, $value);
continue;
}
$newKey = ($parentKey !== NULL)
? "{$parentKey}.{$key}"
: $key;
if ( ! isSequentialArray($value))
{
$builder->addTable($newKey);
}
_iterateToml($builder, $value, $newKey);
}
}
/**
* Serialize config data into a Toml file
*
@ -129,6 +92,35 @@ function _iterateToml(TomlBuilder $builder, iterable $data, $parentKey = NULL):
function arrayToToml(iterable $data): string
{
$builder = new TomlBuilder();
function _iterateToml(TomlBuilder $builder, iterable $data, $parentKey = NULL): void
{
foreach ($data as $key => $value)
{
if ($value === NULL)
{
continue;
}
if (is_scalar($value) || isSequentialArray($value))
{
// $builder->addTable('');
$builder->addValue($key, $value);
continue;
}
$newKey = ($parentKey !== NULL)
? "{$parentKey}.{$key}"
: $key;
if ( ! isSequentialArray($value))
{
$builder->addTable($newKey);
}
_iterateToml($builder, $value, $newKey);
}
}
_iterateToml($builder, $data);
@ -346,7 +338,7 @@ function createPlaceholderImage ($path, ?int $width, ?int $height, $text = 'Imag
* @param string $key
* @return bool
*/
function col_not_empty(array $search, string $key): bool
function colNotEmpty(array $search, string $key): bool
{
$items = array_filter(array_column($search, $key), fn ($x) => ( ! empty($x)));
return count($items) > 0;

View File

@ -16,7 +16,7 @@
namespace Aviat\AnimeClient\Command;
use Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\Kitsu;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
use function Aviat\AnimeClient\clearCache;

View File

@ -26,7 +26,6 @@ use Aviat\AnimeClient\API\{
};
use Aviat\AnimeClient\API;
use Aviat\AnimeClient\API\Anilist;
use Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\API\Mapping\{AnimeWatchingStatus, MangaReadingStatus};
use Aviat\AnimeClient\Enum\{APISource, ListType, SyncAction};
use Aviat\AnimeClient\Types\FormItem;
@ -50,9 +49,9 @@ final class SyncLists extends BaseCommand {
/**
* Model for making requests to Kitsu API
* @var Kitsu\Model
* @var API\Kitsu\Model
*/
private Kitsu\Model $kitsuModel;
private API\Kitsu\Model $kitsuModel;
/**
* Does the Kitsu API have valid authentication?

View File

@ -1,205 +0,0 @@
<?php declare(strict_types=1);
/**
* Hummingbird Anime List Client
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.4
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 5.1
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Controller;
use Aura\Router\Exception\RouteNotFound;
use Aviat\AnimeClient\Controller as BaseController;
use Aviat\Ion\Di\Exception\ContainerException;
use Aviat\Ion\Di\Exception\NotFoundException;
use Aviat\Ion\Exception\DoubleRenderException;
use Aviat\AnimeClient\Model\{
Manga as MangaModel,
MangaCollection as MangaCollectionModel
};
use Aviat\Ion\Di\ContainerInterface;
use InvalidArgumentException;
/**
* Controller for manga collection pages
*/
final class MangaCollection extends BaseController {
/**
* The manga collection model
* @var MangaCollectionModel $mangaCollectionModel
*/
private $mangaCollectionModel;
/**
* The manga API model
* @var MangaModel $mangaModel
*/
private $mangaModel;
/**
* Constructor
*
* @param ContainerInterface $container
* @throws ContainerException
* @throws NotFoundException
* @throws \InvalidArgumentException
*/
public function __construct(ContainerInterface $container)
{
parent::__construct($container);
$this->mangaModel = $container->get('manga-model');
$this->mangaCollectionModel = $container->get('manga-collection-model');
$this->baseData = array_merge($this->baseData, [
'collection_type' => 'manga',
'menu_name' => 'manga-collection',
'other_type' => 'anime',
'url_type' => 'manga',
]);
}
/**
* Search for manga
*
* @throws DoubleRenderException
* @return void
*/
public function search(): void
{
$queryParams = $this->request->getQueryParams();
$query = $queryParams['query'];
$this->outputJSON($this->mangaModel->search($query));
}
/**
* Show the manga collection page
*
* @param string $view
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @return void
*/
public function index($view): void
{
$viewMap = [
'' => 'cover',
'list' => 'list'
];
$data = $this->mangaCollectionModel->getCollection();
$this->outputHTML('collection/' . $viewMap[$view], [
'title' => $this->config->get('whose_list') . "'s Manga Collection",
'sections' => $data,
'genres' => $this->mangaCollectionModel->getGenreList()
]);
}
/**
* Show the manga collection add/edit form
*
* @param integer|null $id
* @throws ContainerException
* @throws NotFoundException
* @throws RouteNotFound
* @throws InvalidArgumentException
* @return void
*/
public function form($id = NULL): void
{
$this->setSessionRedirect();
$action = $id === NULL ? 'Add' : 'Edit';
$urlAction = strtolower($action);
$this->outputHTML('collection/' . $urlAction, [
'action' => $action,
'action_url' => $this->url->generate("manga.collection.{$urlAction}.post"),
'title' => $this->formatTitle(
$this->config->get('whose_list') . "'s manga Collection",
$action
),
'media_items' => $this->mangaCollectionModel->getMediaTypeList(),
'item' => ($action === 'Edit') ? $this->mangaCollectionModel->get($id) : []
]);
}
/**
* Update a collection item
*
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @return void
*/
public function edit(): void
{
$data = $this->request->getParsedBody();
if (array_key_exists('hummingbird_id', $data))
{
$this->mangaCollectionModel->update($data);
$this->setFlashMessage('Successfully updated collection item.', 'success');
}
else
{
$this->setFlashMessage('Failed to update collection item', 'error');
}
$this->sessionRedirect();
}
/**
* Add a collection item
*
* @throws ContainerException
* @throws NotFoundException
* @throws InvalidArgumentException
* @return void
*/
public function add(): void
{
$data = $this->request->getParsedBody();
if (array_key_exists('id', $data))
{
$this->mangaCollectionModel->add($data);
$this->setFlashMessage('Successfully added collection item', 'success');
}
else
{
$this->setFlashMessage('Failed to add collection item.', 'error');
}
$this->sessionRedirect();
}
/**
* Remove a collection item
*
* @return void
*/
public function delete(): void
{
$data = $this->request->getParsedBody();
if ( ! array_key_exists('hummingbird_id', $data))
{
$this->redirect('/manga-collection/view', 303);
}
$this->mangaCollectionModel->delete($data);
$this->setFlashMessage('Successfully removed manga from collection.', 'success');
$this->redirect('/manga-collection/view', 303);
}
}
// End of CollectionController.php

View File

@ -14,7 +14,7 @@
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\API;
namespace Aviat\AnimeClient;
use Aviat\AnimeClient\API\Kitsu\Enum\AnimeAiringStatus;
use Aviat\AnimeClient\API\Kitsu\Enum\MangaPublishingStatus;

View File

@ -1,43 +0,0 @@
<?php declare(strict_types=1);
/**
* Hummingbird Anime List Client
*
* An API client for Kitsu to manage anime and manga watch lists
*
* PHP version 7.4
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2015 - 2020 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @version 5.1
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Model;
use Aviat\Ion\Di\ContainerInterface;
/**
* Model for getting anime collection data
*/
final class MangaCollection extends Collection {
/**
* Manga API Model
* @var Manga $mangaModel
*/
protected $mangaModel;
/**
* Create the collection model
*
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
parent::__construct($container);
$this->mangaModel = $container->get('manga-model');
}
}
// End of MangaCollectionModel.php

View File

@ -23,7 +23,7 @@ use Aviat\AnimeClient\Controller\{
Anime as AnimeController,
Character as CharacterController,
AnimeCollection as AnimeCollectionController,
MangaCollection as MangaCollectionController,
// MangaCollection as MangaCollectionController,
Manga as MangaController
};
@ -73,10 +73,10 @@ class ControllerTest extends AnimeClientTestCase {
Controller::class,
new AnimeCollectionController($this->container)
);
$this->assertInstanceOf(
/* $this->assertInstanceOf(
Controller::class,
new MangaCollectionController($this->container)
);
); */
}
public function testBaseControllerSanity()

View File

@ -16,7 +16,7 @@
namespace Aviat\AnimeClient\Tests\API;
use Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\Kitsu;
use Aviat\AnimeClient\API\Kitsu\Enum\AnimeAiringStatus;
use PHPUnit\Framework\TestCase;