From 5e2a68dc8435c402daef5570bfe820ce9e360b59 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Thu, 20 Oct 2016 22:09:36 -0400 Subject: [PATCH] Update EVERYTHING --- app/bootstrap.php | 7 +-- build/animeclient_header_comment.txt | 5 ++- build/update_header_comments.php | 44 +++++++++++++------ composer.json | 2 +- public/css.php | 4 +- public/js.php | 4 +- src/AnimeClient.php | 4 +- src/Auth/HummingbirdAuth.php | 4 +- src/Command/BaseCommand.php | 4 +- src/Command/CacheImages.php | 4 +- src/Command/ClearCache.php | 4 +- src/Controller.php | 35 +++++++-------- src/Controller/Anime.php | 4 +- src/Controller/Collection.php | 4 +- src/Controller/Manga.php | 5 ++- src/Dispatcher.php | 5 ++- src/Helper/Menu.php | 4 +- src/Hummingbird/Enum/AnimeAiringStatus.php | 4 +- src/Hummingbird/Enum/AnimeShowType.php | 4 +- src/Hummingbird/Enum/AnimeWatchingStatus.php | 4 +- src/Hummingbird/Enum/MangaReadingStatus.php | 4 +- .../Transformer/AnimeListTransformer.php | 20 ++++----- .../Transformer/MangaListTransformer.php | 4 +- .../Transformer/MangaListsZipper.php | 4 +- src/MenuGenerator.php | 11 ++--- src/Model/API.php | 13 +++--- src/Model/Anime.php | 10 ++--- src/Model/AnimeCollection.php | 4 +- src/Model/Collection.php | 4 +- src/Model/DB.php | 5 ++- src/Model/Manga.php | 28 ++++++------ src/RoutingBase.php | 5 ++- src/UrlGenerator.php | 5 ++- src/Util.php | 6 +-- tests/Model/MangaModelTest.php | 6 +-- .../Transformer/AnimeListTransformerTest.php | 5 +-- .../Transformer/MangaListTransformerTest.php | 2 +- tests/mocks.php | 2 +- 38 files changed, 153 insertions(+), 140 deletions(-) diff --git a/app/bootstrap.php b/app/bootstrap.php index e648b7b1..f7d48ae9 100644 --- a/app/bootstrap.php +++ b/app/bootstrap.php @@ -1,10 +1,10 @@ - @@ -14,9 +14,6 @@ * @link https://github.com/timw4mail/HummingBirdAnimeClient */ -/** - * Bootstrap / Dependency Injection - */ namespace Aviat\AnimeClient; use Aura\Html\HelperLocatorFactory; diff --git a/build/animeclient_header_comment.txt b/build/animeclient_header_comment.txt index fafb11dd..24806616 100644 --- a/build/animeclient_header_comment.txt +++ b/build/animeclient_header_comment.txt @@ -3,7 +3,7 @@ * * An API client for Hummingbird to manage anime and manga watch lists * - * PHP version 5.6 + * PHP version 7 * * @package HummingbirdAnimeClient * @author Timothy J. Warren @@ -11,4 +11,5 @@ * @license http://www.opensource.org/licenses/mit-license.html MIT License * @version 3.1 * @link https://github.com/timw4mail/HummingBirdAnimeClient - */ \ No newline at end of file + */ + diff --git a/build/update_header_comments.php b/build/update_header_comments.php index 662814e8..7aa9554c 100644 --- a/build/update_header_comments.php +++ b/build/update_header_comments.php @@ -4,7 +4,8 @@ $animeclient_file_patterns = [ 'app/config/*.php', 'app/bootstrap.php', 'src/functions.php', - 'src/*.php' + 'src/*.php', + 'tests/**/*.php' ]; if ( ! function_exists('glob_recursive')) @@ -26,21 +27,30 @@ if ( ! function_exists('glob_recursive')) function get_text_to_replace($tokens) { - if ($tokens[0][0] !== T_OPEN_TAG) + $output = ''; + + // Tokens have the follow structure if arrays: + // [0] => token type constant + // [1] => raw sytax parsed to that token + // [2] => line number + foreach($tokens as $token) { - return NULL; + // Since we only care about opening docblocks, + // bail out when we get to the namespace token + if (is_array($token) && $token[0] === T_NAMESPACE) + { + break; + } + + if (is_array($token)) + { + $token = $token[1]; + } + + $output .= $token; } - // If there is already a docblock, as the second token after the - // open tag, get the contents of that token to replace - if ($tokens[1][0] === T_DOC_COMMENT) - { - return " diff --git a/public/js.php b/public/js.php index 6314df4a..07f5a30a 100644 --- a/public/js.php +++ b/public/js.php @@ -1,10 +1,10 @@ - diff --git a/src/AnimeClient.php b/src/AnimeClient.php index cfb27521..fda780f8 100644 --- a/src/AnimeClient.php +++ b/src/AnimeClient.php @@ -1,10 +1,10 @@ - diff --git a/src/Auth/HummingbirdAuth.php b/src/Auth/HummingbirdAuth.php index ed734bfc..07629fa9 100644 --- a/src/Auth/HummingbirdAuth.php +++ b/src/Auth/HummingbirdAuth.php @@ -1,10 +1,10 @@ - diff --git a/src/Command/BaseCommand.php b/src/Command/BaseCommand.php index d02cb691..5840d31e 100644 --- a/src/Command/BaseCommand.php +++ b/src/Command/BaseCommand.php @@ -1,10 +1,10 @@ - diff --git a/src/Command/CacheImages.php b/src/Command/CacheImages.php index b75b540a..de30f261 100644 --- a/src/Command/CacheImages.php +++ b/src/Command/CacheImages.php @@ -1,10 +1,10 @@ - diff --git a/src/Command/ClearCache.php b/src/Command/ClearCache.php index 0de7ddd3..14c8f2f7 100644 --- a/src/Command/ClearCache.php +++ b/src/Command/ClearCache.php @@ -1,10 +1,10 @@ - diff --git a/src/Controller.php b/src/Controller.php index a6e76876..62e52565 100644 --- a/src/Controller.php +++ b/src/Controller.php @@ -1,10 +1,10 @@ - @@ -13,13 +13,12 @@ * @version 3.1 * @link https://github.com/timw4mail/HummingBirdAnimeClient */ + namespace Aviat\AnimeClient; -use Aviat\Ion\Di\ContainerInterface; -use Aviat\Ion\View\HttpView; -use Aviat\Ion\View\HtmlView; -use Aviat\Ion\View\JsonView; -use Doctrine\Instantiator\Exception\InvalidArgumentException; +use Aviat\Ion\Di\{ContainerAware, ContainerInterface}; +use Aviat\Ion\View\{HtmlView, HttpView, JsonView}; +use InvalidArgumentException; /** * Controller base, defines output methods @@ -28,7 +27,7 @@ use Doctrine\Instantiator\Exception\InvalidArgumentException; */ class Controller { - use \Aviat\Ion\Di\ContainerAware; + use ContainerAware; /** * Cache manager @@ -166,7 +165,7 @@ class Controller { if (is_null($url)) { - $url = ($util->is_view_page()) + $url = $util->is_view_page() ? $this->request->url->get() : $server_params['HTTP_REFERER']; } @@ -197,9 +196,9 @@ class Controller { * Get a class member * * @param string $key - * @return object + * @return mixed */ - public function __get($key) + public function __get(string $key) { $allowed = ['response', 'config']; @@ -217,7 +216,7 @@ class Controller { * @param HtmlView $view * @param string $template * @param array $data - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @return string */ protected function load_partial($view, $template, array $data = []) @@ -230,17 +229,17 @@ class Controller { } $route = $router->get_route(); - $data['route_path'] = ($route) ? $router->get_route()->path : ""; + $data['route_path'] = $route ? $router->get_route()->path : ''; $template_path = _dir($this->config->get('view_path'), "{$template}.php"); if ( ! is_file($template_path)) { - throw new \InvalidArgumentException("Invalid template : {$template}"); + throw new InvalidArgumentException("Invalid template : {$template}"); } - return $view->render_template($template_path, (array)$data); + return $view->renderTemplate($template_path, (array)$data); } /** @@ -271,13 +270,13 @@ class Controller { * @param string $status * @return void */ - public function login($status = "") + public function login(string $status = '') { - $message = ""; + $message = ''; $view = new HtmlView($this->container); - if ($status !== "") + if ($status !== '') { $message = $this->show_message($view, 'error', $status); } diff --git a/src/Controller/Anime.php b/src/Controller/Anime.php index c8a83f50..185c631e 100644 --- a/src/Controller/Anime.php +++ b/src/Controller/Anime.php @@ -1,10 +1,10 @@ - diff --git a/src/Controller/Collection.php b/src/Controller/Collection.php index a5847d62..67fcb967 100644 --- a/src/Controller/Collection.php +++ b/src/Controller/Collection.php @@ -1,10 +1,10 @@ - diff --git a/src/Controller/Manga.php b/src/Controller/Manga.php index 75816037..6ef71243 100644 --- a/src/Controller/Manga.php +++ b/src/Controller/Manga.php @@ -1,10 +1,10 @@ - @@ -13,6 +13,7 @@ * @version 3.1 * @link https://github.com/timw4mail/HummingBirdAnimeClient */ + namespace Aviat\AnimeClient\Controller; use Aviat\Ion\Json; diff --git a/src/Dispatcher.php b/src/Dispatcher.php index cd8683aa..a168f745 100644 --- a/src/Dispatcher.php +++ b/src/Dispatcher.php @@ -1,10 +1,10 @@ - @@ -13,6 +13,7 @@ * @version 3.1 * @link https://github.com/timw4mail/HummingBirdAnimeClient */ + namespace Aviat\AnimeClient; use Aviat\Ion\Di\ContainerInterface; diff --git a/src/Helper/Menu.php b/src/Helper/Menu.php index 0d4e7d39..ddc623dc 100644 --- a/src/Helper/Menu.php +++ b/src/Helper/Menu.php @@ -1,10 +1,10 @@ - diff --git a/src/Hummingbird/Enum/AnimeAiringStatus.php b/src/Hummingbird/Enum/AnimeAiringStatus.php index 30f763ca..ae420a78 100644 --- a/src/Hummingbird/Enum/AnimeAiringStatus.php +++ b/src/Hummingbird/Enum/AnimeAiringStatus.php @@ -1,10 +1,10 @@ - diff --git a/src/Hummingbird/Enum/AnimeShowType.php b/src/Hummingbird/Enum/AnimeShowType.php index 83bfa5e4..47dcf6f5 100644 --- a/src/Hummingbird/Enum/AnimeShowType.php +++ b/src/Hummingbird/Enum/AnimeShowType.php @@ -1,10 +1,10 @@ - diff --git a/src/Hummingbird/Enum/AnimeWatchingStatus.php b/src/Hummingbird/Enum/AnimeWatchingStatus.php index 9e3f21f2..103ac128 100644 --- a/src/Hummingbird/Enum/AnimeWatchingStatus.php +++ b/src/Hummingbird/Enum/AnimeWatchingStatus.php @@ -1,10 +1,10 @@ - diff --git a/src/Hummingbird/Enum/MangaReadingStatus.php b/src/Hummingbird/Enum/MangaReadingStatus.php index 0ed64fa9..5743c792 100644 --- a/src/Hummingbird/Enum/MangaReadingStatus.php +++ b/src/Hummingbird/Enum/MangaReadingStatus.php @@ -1,10 +1,10 @@ - diff --git a/src/Hummingbird/Transformer/AnimeListTransformer.php b/src/Hummingbird/Transformer/AnimeListTransformer.php index 415daae3..4a6388bd 100644 --- a/src/Hummingbird/Transformer/AnimeListTransformer.php +++ b/src/Hummingbird/Transformer/AnimeListTransformer.php @@ -1,10 +1,10 @@ - @@ -33,17 +33,17 @@ class AnimeListTransformer extends AbstractTransformer { public function transform($item) { $anime =& $item['anime']; - $genres = $this->linearize_genres($item['anime']['genres']); + $genres = $this->linearizeGenres($item['anime']['genres']); $rating = NULL; if ($item['rating']['type'] === 'advanced') { - $rating = (is_numeric($item['rating']['value'])) - ? intval(2 * $item['rating']['value']) + $rating = is_numeric($item['rating']['value']) + ? (int) 2 * $item['rating']['value'] : '-'; } - $total_episodes = (is_numeric($anime['episode_count'])) + $total_episodes = is_numeric($anime['episode_count']) ? $anime['episode_count'] : '-'; @@ -54,7 +54,7 @@ class AnimeListTransformer extends AbstractTransformer { // a subset of the main title, don't list the // alternate title $not_subset = stripos($anime['title'], $anime['alternate_title']) === FALSE; - $diff = levenshtein($anime['title'], $anime['alternate_title']); + $diff = levenshtein($anime['title'], $anime['alternate_title'] ?? ''); if ($not_subset && $diff >= 5) { $alternate_title = $anime['alternate_title']; @@ -129,14 +129,14 @@ class AnimeListTransformer extends AbstractTransformer { /** * Simplify structure of genre list * - * @param array $raw_genres + * @param array $rawGenres * @return array */ - protected function linearize_genres(array $raw_genres) + protected function linearizeGenres(array $rawGenres): array { $genres = []; - foreach ($raw_genres as $genre) + foreach ($rawGenres as $genre) { $genres[] = $genre['name']; } diff --git a/src/Hummingbird/Transformer/MangaListTransformer.php b/src/Hummingbird/Transformer/MangaListTransformer.php index e795d8fc..7f32ca4a 100644 --- a/src/Hummingbird/Transformer/MangaListTransformer.php +++ b/src/Hummingbird/Transformer/MangaListTransformer.php @@ -1,10 +1,10 @@ - diff --git a/src/Hummingbird/Transformer/MangaListsZipper.php b/src/Hummingbird/Transformer/MangaListsZipper.php index 978cdd5c..c3db0458 100644 --- a/src/Hummingbird/Transformer/MangaListsZipper.php +++ b/src/Hummingbird/Transformer/MangaListsZipper.php @@ -1,10 +1,10 @@ - diff --git a/src/MenuGenerator.php b/src/MenuGenerator.php index 76a5a320..001a8bf0 100644 --- a/src/MenuGenerator.php +++ b/src/MenuGenerator.php @@ -1,10 +1,10 @@ - @@ -16,6 +16,7 @@ namespace Aviat\AnimeClient; +use Aviat\Ion\{ArrayWrapper, StringWrapper}; use Aviat\Ion\Di\ContainerInterface; /** @@ -23,8 +24,8 @@ use Aviat\Ion\Di\ContainerInterface; */ class MenuGenerator extends UrlGenerator { - use \Aviat\Ion\StringWrapper; - use \Aviat\Ion\ArrayWrapper; + use ArrayWrapper; + use StringWrapper; /** * Html generation helper @@ -87,7 +88,7 @@ class MenuGenerator extends UrlGenerator { $parsed_config = $this->parse_config($menus); // Bail out early on invalid menu - if ( ! $this->arr($parsed_config)->has_key($menu)) + if ( ! $this->arr($parsed_config)->hasKey($menu)) { return ''; } diff --git a/src/Model/API.php b/src/Model/API.php index 2848560c..67bd6ef6 100644 --- a/src/Model/API.php +++ b/src/Model/API.php @@ -1,10 +1,10 @@ - @@ -13,6 +13,7 @@ * @version 3.1 * @link https://github.com/timw4mail/HummingBirdAnimeClient */ + namespace Aviat\AnimeClient\Model; use GuzzleHttp\Client; @@ -160,7 +161,7 @@ class API extends Model { * @param string $sort_key * @return void */ - protected function sort_by_name(&$array, $sort_key) + protected function sort_by_name(array &$array, string $sort_key) { $sort = []; @@ -180,7 +181,7 @@ class API extends Model { * @param string $password * @return string|false */ - public function authenticate($username, $password) + public function authenticate(string $username, string $password) { $response = $this->post(AnimeClient::HUMMINGBIRD_AUTH_URL, [ 'form_params' => [ @@ -191,7 +192,7 @@ class API extends Model { if ($response->getStatusCode() === 201) { - return json_decode($response->getBody(), TRUE); + return json_decode((string)$response->getBody(), TRUE); } return FALSE; @@ -205,7 +206,7 @@ class API extends Model { * @param string $status * @return array */ - protected function _get_list_from_api($status) + protected function _get_list_from_api(string $status): array { return []; } diff --git a/src/Model/Anime.php b/src/Model/Anime.php index 5ce1a1fa..0593ebdf 100644 --- a/src/Model/Anime.php +++ b/src/Model/Anime.php @@ -1,10 +1,10 @@ - @@ -208,13 +208,13 @@ class Anime extends API { * @param string $status * @return array */ - protected function _get_list_from_api($status = "all") + protected function _get_list_from_api(string $status = "all"): array { $config = [ 'allow_redirects' => FALSE ]; - if ($status !== "all") + if ($status !== 'all') { $config['query']['status'] = $status; } @@ -266,7 +266,7 @@ class Anime extends API { { $api_data = Json::decode($response->getBody(), TRUE); $transformer = new AnimeListTransformer(); - $transformed = $transformer->transform_collection($api_data); + $transformed = $transformer->transformCollection($api_data); return $transformed; } } diff --git a/src/Model/AnimeCollection.php b/src/Model/AnimeCollection.php index 7c43eb56..cd084449 100644 --- a/src/Model/AnimeCollection.php +++ b/src/Model/AnimeCollection.php @@ -1,10 +1,10 @@ - diff --git a/src/Model/Collection.php b/src/Model/Collection.php index d4bb5a3d..776f67c8 100644 --- a/src/Model/Collection.php +++ b/src/Model/Collection.php @@ -1,10 +1,10 @@ - diff --git a/src/Model/DB.php b/src/Model/DB.php index cd9d2f39..a75a6cb8 100644 --- a/src/Model/DB.php +++ b/src/Model/DB.php @@ -1,10 +1,10 @@ - @@ -13,6 +13,7 @@ * @version 3.1 * @link https://github.com/timw4mail/HummingBirdAnimeClient */ + namespace Aviat\AnimeClient\Model; use Aviat\Ion\Di\ContainerInterface; diff --git a/src/Model/Manga.php b/src/Model/Manga.php index 6e8748e5..3fbe8268 100644 --- a/src/Model/Manga.php +++ b/src/Model/Manga.php @@ -1,10 +1,10 @@ - @@ -16,11 +16,11 @@ namespace Aviat\AnimeClient\Model; -use GuzzleHttp\Cookie\SetCookie; - -use Aviat\Ion\Json; use Aviat\AnimeClient\Hummingbird\Transformer; use Aviat\AnimeClient\Hummingbird\Enum\MangaReadingStatus; +use Aviat\Ion\Json; +use GuzzleHttp\Cookie\SetCookie; +use RuntimeException; /** * Model for handling requests dealing with the manga list @@ -59,7 +59,7 @@ class Manga extends API { * @param string|null $json * @return array */ - protected function _manga_api_call($type, $url, $json = NULL) + protected function _manga_api_call(string $type, string $url, $json = NULL): array { $token = $this->container->get('auth') ->get_auth_token(); @@ -144,7 +144,7 @@ class Manga extends API { * * @param string $name * @return array - * @throws \RuntimeException + * @throws RuntimeException */ public function search($name) { @@ -162,10 +162,10 @@ class Manga extends API { if ((int) $response->getStatusCode() !== 200) { - $logger->warning("Non 200 response for search api call"); + $logger->warning('Non 200 response for search api call'); $logger->warning($response->getBody()); - throw new \RuntimeException($response->getEffectiveUrl()); + throw new RuntimeException($response->getEffectiveUrl()); } return Json::decode($response->getBody(), TRUE); @@ -189,7 +189,7 @@ class Manga extends API { * @param string $status * @return array */ - public function _get_list_from_api($status = "All") + public function _get_list_from_api(string $status = "All"): array { $config = [ 'query' => [ @@ -220,11 +220,9 @@ class Manga extends API { return []; } - $zippered_data = $this->zipper_lists($api_data); + $zipperedData = $this->zipperLists($api_data); $transformer = new Transformer\MangaListTransformer(); - $transformed_data = $transformer->transform_collection($zippered_data); - - return $transformed_data; + return $transformer->transformCollection($zipperedData); } /** @@ -281,7 +279,7 @@ class Manga extends API { * @param array $raw_data * @return array */ - private function zipper_lists($raw_data) + private function zipperLists($raw_data) { return (new Transformer\MangaListsZipper($raw_data))->transform(); } diff --git a/src/RoutingBase.php b/src/RoutingBase.php index 4c32bf6c..2a1f479a 100644 --- a/src/RoutingBase.php +++ b/src/RoutingBase.php @@ -1,10 +1,10 @@ - @@ -13,6 +13,7 @@ * @version 3.1 * @link https://github.com/timw4mail/HummingBirdAnimeClient */ + namespace Aviat\AnimeClient; use Aviat\Ion\Di\ContainerInterface; diff --git a/src/UrlGenerator.php b/src/UrlGenerator.php index e9a94d64..88970b08 100644 --- a/src/UrlGenerator.php +++ b/src/UrlGenerator.php @@ -1,10 +1,10 @@ - @@ -13,6 +13,7 @@ * @version 3.1 * @link https://github.com/timw4mail/HummingBirdAnimeClient */ + namespace Aviat\AnimeClient; use Aviat\Ion\Di\ContainerInterface; diff --git a/src/Util.php b/src/Util.php index e26d7be0..309e981a 100644 --- a/src/Util.php +++ b/src/Util.php @@ -1,10 +1,10 @@ - @@ -91,7 +91,7 @@ class Util { { $url = $this->container->get('request') ->getUri(); - $page_segments = explode("/", $url); + $page_segments = explode("/", (string) $url); $intersect = array_intersect($page_segments, self::$form_pages); diff --git a/tests/Model/MangaModelTest.php b/tests/Model/MangaModelTest.php index 8835df9a..813876d9 100644 --- a/tests/Model/MangaModelTest.php +++ b/tests/Model/MangaModelTest.php @@ -1,11 +1,7 @@ mockDir . '/manga.json'); $expected = Json::decodeFile($this->mockDir . '/manga-zippered.json'); - $this->assertEquals($expected, $this->model->zipper_lists($raw_data)); + $this->assertEquals($expected, $this->model->zipperLists($raw_data)); } public function testMapByStatus() diff --git a/tests/Transformer/AnimeListTransformerTest.php b/tests/Transformer/AnimeListTransformerTest.php index 396203fa..742e26ac 100644 --- a/tests/Transformer/AnimeListTransformerTest.php +++ b/tests/Transformer/AnimeListTransformerTest.php @@ -36,7 +36,7 @@ class AnimeListTransformerTest extends AnimeClient_TestCase { */ public function testLinearizeGenres($original, $expected) { - $actual = $this->transformerFriend->linearize_genres($original); + $actual = $this->transformerFriend->linearizeGenres($original); $this->assertEquals($expected, $actual); } @@ -44,8 +44,7 @@ class AnimeListTransformerTest extends AnimeClient_TestCase { { $json = Json::decodeFile($this->start_file); $expected = Json::decodeFile($this->res_file); - $actual = $this->transformer->transform_collection($json); -//file_put_contents($this->res_file, json_encode($actual)); + $actual = $this->transformer->transformCollection($json); $this->assertEquals($expected, $actual); } } \ No newline at end of file diff --git a/tests/Transformer/MangaListTransformerTest.php b/tests/Transformer/MangaListTransformerTest.php index 36f0913c..fad7570e 100644 --- a/tests/Transformer/MangaListTransformerTest.php +++ b/tests/Transformer/MangaListTransformerTest.php @@ -19,7 +19,7 @@ class MangaListTransformerTest extends AnimeClient_TestCase { $orig_json = Json::decodeFile($this->start_file); $expected = Json::decodeFile($this->res_file); - $actual = $this->transformer->transform_collection($orig_json); + $actual = $this->transformer->transformCollection($orig_json); $this->assertEquals($expected, $actual); } diff --git a/tests/mocks.php b/tests/mocks.php index fca39551..55ea76aa 100644 --- a/tests/mocks.php +++ b/tests/mocks.php @@ -150,7 +150,7 @@ class MockBaseApiModel extends BaseApiModel { use MockInjectionTrait; protected $base_url = 'https://httpbin.org/'; - protected function _get_list_from_api($status) + protected function _get_list_from_api(string $status): array { return []; }