From 8cbfaf3646d015b440aed0a9c6eb5e3e8b384502 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Wed, 15 Feb 2017 15:56:10 -0500 Subject: [PATCH] More snake case to camel case --- app/appConf/routes.php | 6 ++--- app/views/anime/add.php | 2 +- app/views/anime/cover.php | 2 +- app/views/anime/edit.php | 2 +- app/views/anime/list.php | 2 +- app/views/collection/add.php | 2 +- app/views/collection/edit.php | 2 +- app/views/collection/list.php | 8 +++--- app/views/footer.php | 2 +- app/views/header.php | 4 +-- app/views/main-menu.php | 8 +++--- app/views/manga/add.php | 2 +- app/views/manga/cover.php | 2 +- app/views/manga/list.php | 6 ++--- src/Controller.php | 2 +- src/Controller/Collection.php | 8 +++--- src/UrlGenerator.php | 40 +++++++++------------------- tests/DispatcherTest.php | 6 ++--- tests/UrlGeneratorTest.php | 49 ++--------------------------------- 19 files changed, 48 insertions(+), 107 deletions(-) diff --git a/app/appConf/routes.php b/app/appConf/routes.php index 4ead95bf..cb5f2fa1 100644 --- a/app/appConf/routes.php +++ b/app/appConf/routes.php @@ -53,7 +53,7 @@ return [ // --------------------------------------------------------------------- 'anime.add.get' => [ 'path' => '/anime/add', - 'action' => 'add_form', + 'action' => 'addForm', 'verb' => 'get', ], 'anime.add.post' => [ @@ -82,7 +82,7 @@ return [ ], 'manga.add.get' => [ 'path' => '/manga/add', - 'action' => 'add_form', + 'action' => 'addForm', 'verb' => 'get', ], 'manga.add.post' => [ @@ -183,7 +183,7 @@ return [ ], 'update.post' => [ 'path' => '/{controller}/update_form', - 'action' => 'form_update', + 'action' => 'formUpdate', 'verb' => 'post', 'tokens' => [ 'controller' => '[a-z_]+', diff --git a/app/views/anime/add.php b/app/views/anime/add.php index fac82700..1818fa02 100644 --- a/app/views/anime/add.php +++ b/app/views/anime/add.php @@ -36,5 +36,5 @@ - + \ No newline at end of file diff --git a/app/views/anime/cover.php b/app/views/anime/cover.php index bd5d4bc2..61a1b9b2 100644 --- a/app/views/anime/cover.php +++ b/app/views/anime/cover.php @@ -86,5 +86,5 @@ is_authenticated()): ?> - + \ No newline at end of file diff --git a/app/views/anime/edit.php b/app/views/anime/edit.php index 75cc7578..e01d90f9 100644 --- a/app/views/anime/edit.php +++ b/app/views/anime/edit.php @@ -107,5 +107,5 @@ - + \ No newline at end of file diff --git a/app/views/anime/list.php b/app/views/anime/list.php index ebb473e3..4f08e588 100644 --- a/app/views/anime/list.php +++ b/app/views/anime/list.php @@ -87,4 +87,4 @@ is_authenticated()) ? 'table_edit' : 'table' ?> - \ No newline at end of file + \ No newline at end of file diff --git a/app/views/collection/add.php b/app/views/collection/add.php index 61c3a7e1..64f472c0 100644 --- a/app/views/collection/add.php +++ b/app/views/collection/add.php @@ -39,5 +39,5 @@ - + \ No newline at end of file diff --git a/app/views/collection/edit.php b/app/views/collection/edit.php index 0d1add75..67bb7bec 100644 --- a/app/views/collection/edit.php +++ b/app/views/collection/edit.php @@ -62,5 +62,5 @@ - + \ No newline at end of file diff --git a/app/views/collection/list.php b/app/views/collection/list.php index 61840d5f..71b48d51 100644 --- a/app/views/collection/list.php +++ b/app/views/collection/list.php @@ -1,6 +1,6 @@
is_authenticated()): ?> -Add Item +Add Item

There's nothing here!

@@ -26,8 +26,8 @@ is_authenticated()): ?> - ">Edit - full_url("collection/delete/{$item['hummingbird_id']}") ?>">Delete*/ ?> + ">Edit + fullUrl("collection/delete/{$item['hummingbird_id']}") ?>">Delete*/ ?> @@ -49,4 +49,4 @@
- \ No newline at end of file + \ No newline at end of file diff --git a/app/views/footer.php b/app/views/footer.php index ca4c3ba4..eee70095 100644 --- a/app/views/footer.php +++ b/app/views/footer.php @@ -1,3 +1,3 @@ - + \ No newline at end of file diff --git a/app/views/header.php b/app/views/header.php index e4196144..e49e45f2 100644 --- a/app/views/header.php +++ b/app/views/header.php @@ -7,8 +7,8 @@ - - + +
diff --git a/app/views/main-menu.php b/app/views/main-menu.php index 3e0111ca..e7c5c67d 100644 --- a/app/views/main-menu.php +++ b/app/views/main-menu.php @@ -2,19 +2,19 @@

- + get('whose_list') ?>'s List get("show_{$url_type}_collection")): ?> [ Collection] - [ List] + [ List] get('whose_list') ?>'s Collection - [Anime List] - [Manga List] + [Anime List] + [Manga List] is_authenticated()): ?> diff --git a/app/views/manga/add.php b/app/views/manga/add.php index d0a3efd3..fcda2f2b 100644 --- a/app/views/manga/add.php +++ b/app/views/manga/add.php @@ -36,5 +36,5 @@ - + \ No newline at end of file diff --git a/app/views/manga/cover.php b/app/views/manga/cover.php index 496aa564..4f0e65d2 100644 --- a/app/views/manga/cover.php +++ b/app/views/manga/cover.php @@ -56,5 +56,5 @@ is_authenticated()): ?> - + \ No newline at end of file diff --git a/app/views/manga/list.php b/app/views/manga/list.php index 7a44d851..506397e6 100644 --- a/app/views/manga/list.php +++ b/app/views/manga/list.php @@ -1,7 +1,7 @@
-is_authenticated()): ?> +is_authenticated()): ?> Add Item - +

There's nothing here!

@@ -47,4 +47,4 @@
- \ No newline at end of file + \ No newline at end of file diff --git a/src/Controller.php b/src/Controller.php index a2a60be3..284673e3 100644 --- a/src/Controller.php +++ b/src/Controller.php @@ -125,7 +125,7 @@ class Controller { public function redirectToDefaultRoute() { $default_type = $this->config->get(['routes', 'route_config', 'default_list']); - $this->redirect($this->urlGenerator->default_url($default_type), 303); + $this->redirect($this->urlGenerator->defaultUrl($default_type), 303); } /** diff --git a/src/Controller/Collection.php b/src/Controller/Collection.php index 88352c53..25f667b8 100644 --- a/src/Controller/Collection.php +++ b/src/Controller/Collection.php @@ -17,8 +17,10 @@ namespace Aviat\AnimeClient\Controller; use Aviat\AnimeClient\Controller as BaseController; -use Aviat\AnimeClient\Model\Anime as AnimeModel; -use Aviat\AnimeClient\Model\AnimeCollection as AnimeCollectionModel; +use Aviat\AnimeClient\Model\{ + Anime as AnimeModel, + AnimeCollection as AnimeCollectionModel +}; use Aviat\AnimeClient\UrlGenerator; use Aviat\Ion\Di\ContainerInterface; @@ -119,7 +121,7 @@ class Collection extends BaseController { $this->outputHTML('collection/' . strtolower($action), [ 'action' => $action, - 'action_url' => $this->urlGenerator->full_url('collection/' . strtolower($action)), + 'action_url' => $this->urlGenerator->fullUrl('collection/' . strtolower($action)), 'title' => $this->config->get('whose_list') . " Anime Collection · {$action}", 'media_items' => $this->animeCollectionModel->get_media_type_list(), 'item' => ($action === "Edit") ? $this->animeCollectionModel->get($id) : [] diff --git a/src/UrlGenerator.php b/src/UrlGenerator.php index 88970b08..95df8f5c 100644 --- a/src/UrlGenerator.php +++ b/src/UrlGenerator.php @@ -17,6 +17,7 @@ namespace Aviat\AnimeClient; use Aviat\Ion\Di\ContainerInterface; +use InvalidArgumentException; /** * UrlGenerator class. @@ -45,33 +46,16 @@ class UrlGenerator extends RoutingBase { * * @return string */ - public function asset_url() + public function assetUrl(...$args) { - $args = func_get_args(); - $base_url = rtrim($this->url(""), '/'); + $baseUrl = rtrim($this->url(""), '/'); + $baseUrl = "{$baseUrl}" . $this->__get("asset_path"); - $base_url = "{$base_url}" . $this->__get("asset_path"); - - array_unshift($args, $base_url); + array_unshift($args, $baseUrl); return implode("/", $args); } - /** - * Get the base url from the config - * - * @param string $type - (optional) The controller - * @return string - */ - public function base_url($type = "anime") - { - $config_path = trim($this->__get("{$type}_path"), "/"); - - $path = ($config_path !== '') ? $config_path : ""; - - return implode("/", ['/', $this->host, $path]); - } - /** * Generate a proper url from the path * @@ -108,20 +92,20 @@ class UrlGenerator extends RoutingBase { * Full default path for the list pages * * @param string $type - * @throws \InvalidArgumentException + * @throws InvalidArgumentException * @return string */ - public function default_url($type) + public function defaultUrl($type) { $type = trim($type); - $default_path = $this->__get("default_{$type}_list_path"); + $defaultPath = $this->__get("default_{$type}_list_path"); - if ( ! is_null($default_path)) + if ( ! is_null($defaultPath)) { - return $this->url("{$type}/{$default_path}"); + return $this->url("{$type}/{$defaultPath}"); } - throw new \InvalidArgumentException("Invalid default type: '{$type}'"); + throw new InvalidArgumentException("Invalid default type: '{$type}'"); } /** @@ -131,7 +115,7 @@ class UrlGenerator extends RoutingBase { * @param string $type - (optional) The controller (anime or manga), defaults to anime * @return string */ - public function full_url($path = "", $type = "anime") + public function fullUrl($path = "", $type = "anime") { $config_default_route = $this->__get("default_{$type}_path"); diff --git a/tests/DispatcherTest.php b/tests/DispatcherTest.php index e62b7e1f..63f85465 100644 --- a/tests/DispatcherTest.php +++ b/tests/DispatcherTest.php @@ -190,11 +190,11 @@ class DispatcherTest extends AnimeClient_TestCase { ]; $this->doSetUp($config, "/", "localhost"); - $this->assertEquals('//localhost/manga/all', $this->urlGenerator->default_url('manga'), "Incorrect default url"); - $this->assertEquals('//localhost/anime/watching', $this->urlGenerator->default_url('anime'), "Incorrect default url"); + $this->assertEquals('//localhost/manga/all', $this->urlGenerator->defaultUrl('manga'), "Incorrect default url"); + $this->assertEquals('//localhost/anime/watching', $this->urlGenerator->defaultUrl('anime'), "Incorrect default url"); $this->expectException(\InvalidArgumentException::class); - $this->urlGenerator->default_url('foo'); + $this->urlGenerator->defaultUrl('foo'); } public function dataGetControllerList() diff --git a/tests/UrlGeneratorTest.php b/tests/UrlGeneratorTest.php index 6faca7c9..4a77a096 100644 --- a/tests/UrlGeneratorTest.php +++ b/tests/UrlGeneratorTest.php @@ -32,8 +32,7 @@ class UrlGeneratorTest extends AnimeClient_TestCase { { $urlGenerator = new UrlGenerator($this->container); - $result = call_user_func_array([$urlGenerator, 'asset_url'], $args); - + $result = $urlGenerator->assetUrl(...$args); $this->assertEquals($expected, $result); } @@ -88,51 +87,7 @@ class UrlGeneratorTest extends AnimeClient_TestCase { $this->container->setInstance('config', $config); $urlGenerator = new UrlGenerator($this->container); - $result = $urlGenerator->full_url($path, $type); - - $this->assertEquals($expected, $result); - } - - public function dataBaseUrl() - { - $config = [ - 'routes' => [ - 'routes' => [], - 'route_config' => [ - 'anime_path' => 'anime', - 'manga_path' => 'manga', - 'default_list' => 'manga', - 'default_anime_path' => '/watching', - 'default_manga_path' => '/all', - 'default_to_list_view' => TRUE, - ], - ] - ]; - - return [ - 'path_based_routing_anime' => [ - 'config' => $config, - 'type' => 'anime', - 'expected' => '//localhost/anime' - ], - 'path_based_routing_manga' => [ - 'config' => $config, - 'type' => 'manga', - 'expected' => '//localhost/manga' - ] - ]; - } - - /** - * @dataProvider dataBaseUrl - */ - public function testBaseUrl($config, $type, $expected) - { - $config = new Config($config); - $this->container->setInstance('config', $config); - $urlGenerator = new UrlGenerator($this->container); - - $result = $urlGenerator->base_url($type); + $result = $urlGenerator->fullUrl($path, $type); $this->assertEquals($expected, $result); }