Minor code quality fixes for Scrutinizer

This commit is contained in:
Timothy Warren 2016-02-02 21:28:32 -05:00
parent 93b885dc0d
commit 6555aac2fb
9 changed files with 82 additions and 36 deletions

View File

@ -20,7 +20,9 @@
$.get('/public/templates/anime-ajax-search-results.html', tempHtml => {
$('#search').on('keypress', AnimeClient.throttle(250, function(e) {
let query = encodeURIComponent($(this).val());
console.log($(this).val());
if (query === '') {
return;
}
search(tempHtml, query);
}));

View File

@ -244,8 +244,6 @@ class Anime extends BaseController {
/**
* Update an anime item
*
* @return boolean|null
*/
public function update()
{
@ -253,6 +251,15 @@ class Anime extends BaseController {
$this->outputJSON($response['body'], $response['statusCode']);
}
/**
* Remove an anime from the list
*/
public function delete()
{
$response = $this->model->update($this->request->post->get());
$this->outputJSON($response['body'], $response['statusCode']);
}
/**
* View details of an anime
*

View File

@ -178,5 +178,18 @@ class API extends BaseModel {
return FALSE;
}
/**
* Dummy function that should be abstract. Is not abstract because
* this class is used concretely for authorizing API calls
*
* @TODO Refactor, and make this abstract
* @param string $status
* @return array
*/
protected function _get_list_from_api($status)
{
return [];
}
}
// End of BaseApiModel.php

View File

@ -74,6 +74,33 @@ class Anime extends API {
];
}
/**
* Remove an anime from a list
*
* @param array $data
* @return array
*/
public function delete($data)
{
$auth = $this->container->get('auth');
if ( ! $auth->is_authenticated() || ! array_key_exists('id', $data))
{
return FALSE;
}
$id = $data['id'];
$data['auth_token'] = $auth->get_auth_token();
$response = $this->client->post("libraries/{$id}/remove", [
'form_params' => $data
]);
return [
'statusCode' => $response->getStatusCode(),
'body' => Json::decode($response->getBody(), TRUE)
];
}
/**
* Get the full set of anime lists
*

View File

@ -50,7 +50,7 @@ class Manga extends API {
*/
protected $base_url = "https://hummingbird.me/";
protected function _auth_json_call($type, $url, $json)
protected function _manga_api_call($type, $url, $json=null)
{
$token = $this->container->get('auth')
->get_auth_token();
@ -65,10 +65,16 @@ class Manga extends API {
]);
$cookieJar->setCookie($cookie_data);
$result = $this->client->request(strtoupper($type), $url, [
'cookies' => $cookieJar,
'json' => $json
]);
$config = [
'cookies' => $cookieJar
];
if ( ! is_null($json))
{
$config['json'] = $json;
}
$result = $this->client->request(strtoupper($type), $url, $config);
return [
'statusCode' => $result->getStatusCode(),
@ -90,7 +96,7 @@ class Manga extends API {
]
];
return $this->_auth_json_call('post', 'manga_library_entries', $object);
return $this->_manga_api_call('post', 'manga_library_entries', $object);
}
/**
@ -103,7 +109,7 @@ class Manga extends API {
{
$id = $data['id'];
return $this->_auth_json_call(
return $this->_manga_api_call(
'put',
"manga_library_entries/{$id}",
['manga_library_entry' => $data]
@ -120,27 +126,7 @@ class Manga extends API {
{
$id = $data['id'];
$token = $this->container->get('auth')
->get_auth_token();
// Set the token cookie, with the authentication token
// from the auth class.
$cookieJar = $this->cookieJar;
$cookie_data = new SetCookie([
'Name' => 'token',
'Value' => $token,
'Domain' => 'hummingbird.me'
]);
$cookieJar->setCookie($cookie_data);
$result = $this->delete("manga_library_entries/{$id}", [
'cookies' => $cookieJar,
]);
return [
'statusCode' => $result->getStatusCode(),
'body' => $result->getBody()
];
return $this->_manga_api_call('delete', "manga_library_entries/{$id}");
}
/**

View File

@ -39,6 +39,12 @@ class RoutingBase {
*/
protected $routes;
/**
* Route configuration options
* @var array
*/
protected $route_config;
/**
* Constructor
*
@ -48,8 +54,9 @@ class RoutingBase {
{
$this->container = $container;
$this->config = $container->get('config');
$this->base_routes = $this->config->get('routes');
$this->routes = $this->base_routes['routes'];
$base_routes = $this->config->get('routes');
$this->routes = $base_routes['routes'];
$this->route_config = $base_routes['route_config'];
}
/**
@ -60,7 +67,7 @@ class RoutingBase {
*/
public function __get($key)
{
$routing_config = $this->base_routes['route_config'];
$routing_config =& $this->route_config;
if (array_key_exists($key, $routing_config))
{

View File

@ -23,8 +23,8 @@ class Json {
* Encode data in json format
*
* @param mixed $data
* @param int $options=0
* @param int $depth=512
* @param int $options
* @param int $depth
* @return string
*/
public static function encode($data, $options = 0, $depth = 512)

View File

@ -144,6 +144,10 @@ class MockBaseApiModel extends BaseApiModel {
use MockInjectionTrait;
protected $base_url = 'https://httpbin.org/';
protected function _get_list_from_api($status)
{
return [];
}
}
class TestAnimeModel extends AnimeModel {