From 7648d31e53401fcdc15d289ad9641bd93516b16b Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Wed, 15 Feb 2017 15:35:41 -0500 Subject: [PATCH] More code styles fixes --- src/Controller/Anime.php | 16 +++++++------- src/Controller/Collection.php | 8 +++---- src/Controller/Manga.php | 4 ++-- src/Model/AnimeCollection.php | 24 ++++++++++----------- src/Model/Collection.php | 40 ++++++++++++++++------------------- src/Model/DB.php | 10 ++++----- tests/DispatcherTest.php | 4 ++-- 7 files changed, 51 insertions(+), 55 deletions(-) diff --git a/src/Controller/Anime.php b/src/Controller/Anime.php index e525e143..baac5d8d 100644 --- a/src/Controller/Anime.php +++ b/src/Controller/Anime.php @@ -122,7 +122,7 @@ class Anime extends BaseController { * * @return void */ - public function add_form() + public function addForm() { $statuses = [ AnimeWatchingStatus::WATCHING => 'Currently Watching', @@ -220,17 +220,17 @@ class Anime extends BaseController { * * @return void */ - public function form_update() + public function formUpdate() { $data = $this->request->getParsedBody(); // Do some minor data manipulation for // large form-based updates $transformer = new AnimeListTransformer(); - $post_data = $transformer->untransform($data); - $full_result = $this->model->updateLibraryItem($post_data); + $postData = $transformer->untransform($data); + $fullResult = $this->model->updateLibraryItem($postData); - if ($full_result['statusCode'] === 200) + if ($fullResult['statusCode'] === 200) { $this->set_flash_message("Successfully updated.", 'success'); $this->cache->clear(); @@ -291,12 +291,12 @@ class Anime extends BaseController { /** * View details of an anime * - * @param string $anime_id + * @param string $animeId * @return void */ - public function details($anime_id) + public function details($animeId) { - $data = $this->model->getAnime($anime_id); + $data = $this->model->getAnime($animeId); $this->outputHTML('anime/details', [ 'title' => 'Anime · ' . $data['titles'][0], diff --git a/src/Controller/Collection.php b/src/Controller/Collection.php index eee00bc4..88352c53 100644 --- a/src/Controller/Collection.php +++ b/src/Controller/Collection.php @@ -91,17 +91,17 @@ class Collection extends BaseController { */ public function index($view) { - $view_map = [ + $viewMap = [ '' => 'cover', 'list' => 'list' ]; - $data = $this->animeCollectionModel->get_collection(); + $data = $this->animeCollectionModel->getCollection(); - $this->outputHTML('collection/' . $view_map[$view], [ + $this->outputHTML('collection/' . $viewMap[$view], [ 'title' => $this->config->get('whose_list') . "'s Anime Collection", 'sections' => $data, - 'genres' => $this->animeCollectionModel->get_genre_list() + 'genres' => $this->animeCollectionModel->getGenreList() ]); } diff --git a/src/Controller/Manga.php b/src/Controller/Manga.php index f493522b..6cfd1e2a 100644 --- a/src/Controller/Manga.php +++ b/src/Controller/Manga.php @@ -101,7 +101,7 @@ class Manga extends Controller { * * @return void */ - public function add_form() + public function addForm() { $raw_status_list = MangaReadingStatus::getConstList(); @@ -190,7 +190,7 @@ class Manga extends Controller { * * @return void */ - public function form_update() + public function formUpdate() { $data = $this->request->getParsedBody(); diff --git a/src/Model/AnimeCollection.php b/src/Model/AnimeCollection.php index 42312ad3..99a47fc1 100644 --- a/src/Model/AnimeCollection.php +++ b/src/Model/AnimeCollection.php @@ -31,9 +31,9 @@ class AnimeCollection extends Collection { * * @return array */ - public function get_collection() + public function getCollection() { - $raw_collection = $this->_get_collection(); + $raw_collection = $this->_getCollection(); $collection = []; @@ -57,7 +57,7 @@ class AnimeCollection extends Collection { * * @return array */ - public function get_media_type_list() + public function getMediaTypeList() { $output = []; @@ -79,7 +79,7 @@ class AnimeCollection extends Collection { * @param int $id * @return array */ - public function get_collection_entry($id) + public function getCollectionEntry($id) { $query = $this->db->from('anime_set') ->where('hummingbird_id', (int)$id) @@ -93,9 +93,9 @@ class AnimeCollection extends Collection { * * @return array */ - private function _get_collection() + private function _getCollection() { - if ( ! $this->valid_database) + if ( ! $this->validDatabase) { return []; } @@ -119,7 +119,7 @@ class AnimeCollection extends Collection { */ public function add($data) { - $anime = (object)$this->anime_model->getAnimeById($data['id']); + $anime = (object)$this->animeModel->getAnimeById($data['id']); $this->db->set([ 'hummingbird_id' => $data['id'], 'slug' => $anime->slug, @@ -134,7 +134,7 @@ class AnimeCollection extends Collection { 'notes' => $data['notes'] ])->insert('anime_set'); - $this->update_genre($data['id']); + $this->updateGenre($data['id']); } /** @@ -201,13 +201,13 @@ class AnimeCollection extends Collection { * @param int $anime_id The current anime * @return void */ - private function update_genre($anime_id) + private function updateGenre($anime_id) { - $genre_info = $this->get_genre_data(); + $genre_info = $this->getGenreData(); extract($genre_info); // Get api information - $anime = $this->anime_model->getAnimeById($anime_id); + $anime = $this->animeModel->getAnimeById($anime_id); foreach ($anime['genres'] as $genre) { @@ -248,7 +248,7 @@ class AnimeCollection extends Collection { * * @return array */ - private function get_genre_data() + private function getGenreData() { $genres = []; $links = []; diff --git a/src/Model/Collection.php b/src/Model/Collection.php index e3ff607c..80c4822c 100644 --- a/src/Model/Collection.php +++ b/src/Model/Collection.php @@ -16,10 +16,8 @@ namespace Aviat\AnimeClient\Model; - -use Aviat\Ion\Di\ContainerAware; -use Aviat\Ion\Di\ContainerInterface; -use Aviat\Ion\Model\DB; +use Aviat\AnimeClient\Model\DB; +use Aviat\Ion\Di\{ContainerAware, ContainerInterface}; use PDO; use PDOException; @@ -32,15 +30,15 @@ class Collection extends DB { /** * Anime API Model - * @var object $anime_model + * @var object $animeModel */ - protected $anime_model; + protected $animeModel; /** * Whether the database is valid for querying * @var boolean */ - protected $valid_database = FALSE; + protected $validDatabase = FALSE; /** * Create a new collection object @@ -48,41 +46,39 @@ class Collection extends DB { * @param ContainerInterface $container */ public function __construct(ContainerInterface $container) - { - $this->container = $container; - - parent::__construct($container->get('config')); + { + parent::__construct($container); try { - $this->db = \Query($this->db_config['collection']); + $this->db = \Query($this->dbConfig['collection']); } catch (PDOException $e) { - //$this->valid_database = FALSE; + //$this->validDatabase = FALSE; //return FALSE; } - $this->anime_model = $container->get('anime-model'); + $this->animeModel = $container->get('anime-model'); // Is database valid? If not, set a flag so the // app can be run without a valid database - if ($this->db_config['collection']['type'] === 'sqlite') + if ($this->dbConfig['collection']['type'] === 'sqlite') { - $db_file_name = $this->db_config['collection']['file']; + $dbFileName = $this->dbConfig['collection']['file']; - if ($db_file_name !== ':memory:' && file_exists($db_file_name)) + if ($dbFileName !== ':memory:' && file_exists($dbFileName)) { - $db_file = file_get_contents($db_file_name); - $this->valid_database = (strpos($db_file, 'SQLite format 3') === 0); + $dbFile = file_get_contents($dbFileName); + $this->validDatabase = (strpos($dbFile, 'SQLite format 3') === 0); } else { - $this->valid_database = FALSE; + $this->validDatabase = FALSE; } } else { - $this->valid_database = TRUE; + $this->validDatabase = TRUE; } } @@ -92,7 +88,7 @@ class Collection extends DB { * @param array $filter * @return array */ - public function get_genre_list($filter = []) + public function getGenreList($filter = []) { $this->db->select('hummingbird_id, genre') ->from('genre_anime_set_link gl') diff --git a/src/Model/DB.php b/src/Model/DB.php index dcacd4d6..c63dc771 100644 --- a/src/Model/DB.php +++ b/src/Model/DB.php @@ -16,14 +16,14 @@ namespace Aviat\AnimeClient\Model; -use Aviat\Ion\Di\ContainerInterface; +use Aviat\Ion\Di\{ContainerAware, ContainerInterface}; use Aviat\Ion\Model; /** * Base model for database interaction */ class DB extends Model { - use \Aviat\Ion\Di\ContainerAware; + use ContainerAware; /** * The query builder object @@ -33,9 +33,9 @@ class DB extends Model { /** * The database connection information array - * @var array $db_config + * @var array $dbConfig */ - protected $db_config; + protected $dbConfig = []; /** * Constructor @@ -44,7 +44,7 @@ class DB extends Model { */ public function __construct(ContainerInterface $container) { - $this->db_config = $container->get('config')->get('database'); + $this->dbConfig = $container->get('config')->get('database'); $this->setContainer($container); } } diff --git a/tests/DispatcherTest.php b/tests/DispatcherTest.php index 05ad50c2..e62b7e1f 100644 --- a/tests/DispatcherTest.php +++ b/tests/DispatcherTest.php @@ -199,7 +199,7 @@ class DispatcherTest extends AnimeClient_TestCase { public function dataGetControllerList() { - return array( + return [ 'controller_list_sanity_check' => [ 'config' => [ 'routes' => [ @@ -242,7 +242,7 @@ class DispatcherTest extends AnimeClient_TestCase { 'collection' => 'Aviat\AnimeClient\Controller\Collection', ] ] - ); + ]; } /**