From 8898655a4932318d65b88a5a1f523e944ca3c628 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 17 Feb 2017 08:25:19 -0500 Subject: [PATCH] Various tweaking --- RoboFile.php | 46 ++++++----------- app/views/anime/cover.php | 8 ++- app/views/header.php | 6 +-- composer.json | 8 +-- public/css/base.css | 2 + public/css/base.myth.css | 3 ++ favicon.ico => public/favicon.ico | Bin src/API/ParallelAPIRequest.php | 83 ++++++++++++++++++++++++++++++ src/Controller.php | 12 +++-- src/Controller/Anime.php | 12 ++--- src/Model/API.php | 26 ---------- src/Model/Anime.php | 3 +- src/Model/Manga.php | 10 ++-- 13 files changed, 138 insertions(+), 81 deletions(-) rename favicon.ico => public/favicon.ico (100%) create mode 100644 src/API/ParallelAPIRequest.php diff --git a/RoboFile.php b/RoboFile.php index d54b3eae..8d483d27 100644 --- a/RoboFile.php +++ b/RoboFile.php @@ -1,4 +1,7 @@ -taskPhpUnit() + $this->_run(['vendor/bin/phpunit -c build']); + /* $this->taskPhpUnit() ->configFile('build/phpunit.xml') ->printed(true) - ->run(); + ->run(); */ } /** @@ -128,7 +132,7 @@ class RoboFile extends \Robo\Tasks { { $files = $this->getAllSourceFiles(); - $chunks = array_chunk($files, 6); + $chunks = array_chunk($files, 12); foreach($chunks as $chunk) { @@ -136,29 +140,6 @@ class RoboFile extends \Robo\Tasks { } } - - /** - * Run mutation tests with humbug - * - * @param bool $stats - if true, generates stats rather than running mutation tests - */ - public function mutate($stats = FALSE) - { - $test_parts = [ - 'vendor/bin/humbug' - ]; - - $stat_parts = [ - 'vendor/bin/humbug', - '--skip-killed=yes', - '-v', - './build/humbug.json' - ]; - - $cmd_parts = ($stats) ? $stat_parts : $test_parts; - $this->_run($cmd_parts); - } - /** * Run the phpcs tool * @@ -226,10 +207,13 @@ class RoboFile extends \Robo\Tasks { public function test() { $this->lint(); - $this->taskPHPUnit() + + $this->_run(['phpunit']); + + /*$this->taskPHPUnit() ->configFile('phpunit.xml') ->printed(true) - ->run(); + ->run();*/ } /** @@ -275,7 +259,9 @@ class RoboFile extends \Robo\Tasks { $files = array_merge( glob_recursive('build/*.php'), glob_recursive('src/*.php'), + glob_recursive('src/**/*.php'), glob_recursive('tests/*.php'), + glob_recursive('tests/**/*.php'), glob('*.php') ); diff --git a/app/views/anime/cover.php b/app/views/anime/cover.php index bd320894..4c539a11 100644 --- a/app/views/anime/cover.php +++ b/app/views/anime/cover.php @@ -28,7 +28,13 @@ isAuthenticated()): ?>
- ">Edit + Edit
diff --git a/app/views/header.php b/app/views/header.php index 3575945c..f4b29528 100644 --- a/app/views/header.php +++ b/app/views/header.php @@ -6,8 +6,8 @@ - - + + @@ -16,7 +16,7 @@ diff --git a/composer.json b/composer.json index 4b91d3b0..3dfd8d94 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "require-dev": { "pdepend/pdepend": "^2.2", "sebastian/phpcpd": "^3.0", - "theseer/phpdox": "^0.9.0", + "theseer/phpdox": "*", "phploc/phploc": "^3.0", "phpmd/phpmd": "^2.4", "phpunit/phpunit": "^6.0", @@ -46,6 +46,8 @@ }, "scripts": { "build:css": "cd public && npm run build && cd ..", - "watch:css": "cd public && npm run watch" + "coverage": "vendor/bin/phpunit -c build", + "watch:css": "cd public && npm run watch", + "test": "vendor/bin/phpunit" } -} \ No newline at end of file +} diff --git a/public/css/base.css b/public/css/base.css index fca8d1cc..89b3c380 100644 --- a/public/css/base.css +++ b/public/css/base.css @@ -1044,6 +1044,7 @@ a:hover, a:active { .medium_metadata > div, .row { text-shadow:1px 2px 1px rgba(0, 0, 0, .85); + background:#000; background:rgba(0, 0, 0, .45); color:#ffffff; padding:0.25em 0.125em; @@ -1127,6 +1128,7 @@ a:hover, a:active { .anime .row, .manga .row { width:100%; + background:#000; background:rgba(0, 0, 0, .45); display: -webkit-box; display: -ms-flexbox; diff --git a/public/css/base.myth.css b/public/css/base.myth.css index d855d069..24285199 100644 --- a/public/css/base.myth.css +++ b/public/css/base.myth.css @@ -4,6 +4,7 @@ --link-shadow: 1px 1px 1px #000; --shadow: 1px 2px 1px rgba(0, 0, 0, 0.85); --title-overlay: rgba(0, 0, 0, 0.45); + --title-overlay-fallback: #000; --text-color: #ffffff; --normal-padding: 0.25em 0.125em; --link-hover-color: #7d12db; @@ -315,6 +316,7 @@ a:hover, a:active { .medium_metadata > div, .row { text-shadow: var(--shadow); + background: var(--title-overlay-fallback); background: var(--title-overlay); color: var(--text-color); padding: var(--normal-padding); @@ -398,6 +400,7 @@ a:hover, a:active { .anime .row, .manga .row { width:100%; + background: var(--title-overlay-fallback); background: var(--title-overlay); display: flex; align-content: space-around; diff --git a/favicon.ico b/public/favicon.ico similarity index 100% rename from favicon.ico rename to public/favicon.ico diff --git a/src/API/ParallelAPIRequest.php b/src/API/ParallelAPIRequest.php new file mode 100644 index 00000000..71170738 --- /dev/null +++ b/src/API/ParallelAPIRequest.php @@ -0,0 +1,83 @@ + + * @copyright 2015 - 2017 Timothy J. Warren + * @license http://www.opensource.org/licenses/mit-license.html MIT License + * @version 4.0 + * @link https://github.com/timw4mail/HummingBirdAnimeClient + */ + +namespace Aviat\AnimeClient\API; + +use function Amp\{all, some, wait}; + +use Amp\Artax\Client; + +/** + * Class to simplify making and validating simultaneous requests + */ +class ParallelAPIRequest { + + /** + * Set of requests to make in parallel + * + * @var array + */ + protected $requests = []; + + /** + * Add a request + * + * @param string|Request $request + * @param string|number $key + * @return self + */ + public function addRequest($request, $key = null): self + { + if ( ! is_null($key)) + { + $this->requests[$key] = $request; + return $this; + } + + $this->requests[] = $request; + return $this; + } + + /** + * Add multiple requests + * + * @param string[]|Request[] $requests + * @return self + */ + public function addRequests(array $requests): self + { + array_walk($requests, [$this, 'addRequest']); + return $this; + } + + /** + * Actually make the requests + * + * @param bool $allowFailingRequests + * @return array + */ + public function makeRequests(bool $allowFailingRequests = FALSE): array + { + $client = new Client(); + $promises = $client->requestMulti($this->requests); + + $func = ($allowFailingRequests) ? 'some' : 'all'; + + $results = wait($func($promises)); + + return $results; + } +} \ No newline at end of file diff --git a/src/Controller.php b/src/Controller.php index 4f27026b..5ba581c5 100644 --- a/src/Controller.php +++ b/src/Controller.php @@ -97,10 +97,14 @@ class Controller { $this->config = $container->get('config'); $this->request = $container->get('request'); $this->response = $container->get('response'); - $this->baseData['url'] = $auraUrlGenerator; - $this->baseData['urlGenerator'] = $urlGenerator; - $this->baseData['auth'] = $container->get('auth'); - $this->baseData['config'] = $this->config; + + $this->baseData = array_merge((array)$this->baseData, [ + 'url' => $auraUrlGenerator, + 'urlGenerator' => $urlGenerator, + 'auth' => $container->get('auth'), + 'config' => $this->config + ]); + $this->urlGenerator = $urlGenerator; $session = $container->get('session'); diff --git a/src/Controller/Anime.php b/src/Controller/Anime.php index 7b04fa05..814bf4b5 100644 --- a/src/Controller/Anime.php +++ b/src/Controller/Anime.php @@ -158,12 +158,12 @@ class Anime extends BaseController { if ($result) { - $this->set_flash_message('Added new anime to list', 'success'); + $this->setFlashMessage('Added new anime to list', 'success'); $this->cache->clear(); } else { - $this->set_flash_message('Failed to add new anime to list', 'error'); + $this->setFlashMessage('Failed to add new anime to list', 'error'); } $this->sessionRedirect(); @@ -232,12 +232,12 @@ class Anime extends BaseController { if ($fullResult['statusCode'] === 200) { - $this->set_flash_message("Successfully updated.", 'success'); + $this->setFlashMessage("Successfully updated.", 'success'); $this->cache->clear(); } else { - $this->set_flash_message('Failed to update anime.', 'error'); + $this->setFlashMessage('Failed to update anime.', 'error'); } $this->sessionRedirect(); @@ -277,12 +277,12 @@ class Anime extends BaseController { if ((bool)$response === TRUE) { - $this->set_flash_message("Successfully deleted anime.", 'success'); + $this->setFlashMessage("Successfully deleted anime.", 'success'); $this->cache->clear(); } else { - $this->set_flash_message('Failed to delete anime.', 'error'); + $this->setFlashMessage('Failed to delete anime.', 'error'); } $this->sessionRedirect(); diff --git a/src/Model/API.php b/src/Model/API.php index 8f07adfb..354761b6 100644 --- a/src/Model/API.php +++ b/src/Model/API.php @@ -16,7 +16,6 @@ namespace Aviat\AnimeClient\Model; -use Aviat\Ion\Di\{ContainerAware, ContainerInterface}; use Aviat\Ion\Model; /** @@ -24,31 +23,6 @@ use Aviat\Ion\Model; */ class API extends Model { - use ContainerAware; - - /** - * Config manager - * @var ConfigInterface - */ - protected $config; - - /** - * Cache manager - * @var \Psr\Cache\CacheItemPoolInterface - */ - protected $cache; - - /** - * Constructor - * - * @param ContainerInterface $container - */ - public function __construct(ContainerInterface $container) - { - $this->container = $container; - $this->config = $container->get('config'); - } - /** * Sort the list entries by their title * diff --git a/src/Model/Anime.php b/src/Model/Anime.php index a4fc70d2..969fa5a7 100644 --- a/src/Model/Anime.php +++ b/src/Model/Anime.php @@ -18,6 +18,7 @@ namespace Aviat\AnimeClient\Model; use function Amp\some; use function Amp\wait; + use Amp\Artax\Client; use Aviat\AnimeClient\API\Kitsu\Enum\AnimeWatchingStatus; use Aviat\Ion\Di\ContainerInterface; @@ -58,8 +59,6 @@ class Anime extends API { * @param ContainerInterface $container */ public function __construct(ContainerInterface $container) { - parent::__construct($container); - $config = $container->get('config'); $this->kitsuModel = $container->get('kitsu-model'); $this->malModel = $container->get('mal-model'); diff --git a/src/Model/Manga.php b/src/Model/Manga.php index 86f949e5..a3f832e1 100644 --- a/src/Model/Manga.php +++ b/src/Model/Manga.php @@ -36,7 +36,7 @@ class Manga extends API * Map API constants to display constants * @var array */ - protected $const_map = [ + protected $constMap = [ MangaReadingStatus::READING => self::READING, MangaReadingStatus::PLAN_TO_READ => self::PLAN_TO_READ, MangaReadingStatus::ON_HOLD => self::ON_HOLD, @@ -44,7 +44,7 @@ class Manga extends API MangaReadingStatus::COMPLETED => self::COMPLETED ]; - protected $status_map = [ + protected $statusMap = [ 'current' => self::READING, 'planned' => self::PLAN_TO_READ, 'completed' => self::COMPLETED, @@ -59,8 +59,6 @@ class Manga extends API public function __construct(ContainerInterface $container) { - parent::__construct($container); - $this->kitsuModel = $container->get('kitsu-model'); } @@ -72,7 +70,7 @@ class Manga extends API */ public function getList($status) { - $APIstatus = array_flip($this->const_map)[$status]; + $APIstatus = array_flip($this->constMap)[$status]; $data = $this->kitsuModel->getMangaList($APIstatus); return $this->mapByStatus($data)[$status]; } @@ -161,7 +159,7 @@ class Manga extends API ]; foreach ($data as &$entry) { - $key = $this->status_map[$entry['reading_status']]; + $key = $this->statusMap[$entry['reading_status']]; $output[$key][] = $entry; }