Lots of style fixes, with more to come

This commit is contained in:
Timothy Warren 2017-02-17 10:55:17 -05:00
parent 1f58d7a419
commit 9951053b4f
21 changed files with 119 additions and 67 deletions

View File

@ -118,9 +118,7 @@ class RoboFile extends Tasks {
public function docs() public function docs()
{ {
$cmd_parts = [ $cmd_parts = [
'cd build', 'phpdox',
'../vendor/bin/phpdox',
'cd ..'
]; ];
$this->_run($cmd_parts, ' && '); $this->_run($cmd_parts, ' && ');
} }
@ -209,11 +207,6 @@ class RoboFile extends Tasks {
$this->lint(); $this->lint();
$this->_run(['phpunit']); $this->_run(['phpunit']);
/*$this->taskPHPUnit()
->configFile('phpunit.xml')
->printed(true)
->run();*/
} }
/** /**

View File

@ -65,7 +65,7 @@ class LogicalNotSpacingSniff implements Sniff
$next_token = $tokens[$stackPtr + 1]; $next_token = $tokens[$stackPtr + 1];
if (T_WHITESPACE !== $previous_token['code'] || T_WHITESPACE !== $next_token['code']) { if (T_WHITESPACE !== $previous_token['code'] || T_WHITESPACE !== $next_token['code']) {
$error = 'Logical operator ! should always be preceded and followed with a whitespace.'; $error = 'Logical operator ! should always be preceded and followed with a whitespace.';
$phpcsFile->addError($error, $stackPtr); $phpcsFile->addError($error, $stackPtr, 'badNot');
} }
}//end process() }//end process()

View File

@ -34,11 +34,11 @@
"require-dev": { "require-dev": {
"pdepend/pdepend": "^2.2", "pdepend/pdepend": "^2.2",
"sebastian/phpcpd": "^3.0", "sebastian/phpcpd": "^3.0",
"theseer/phpdox": "*", "theseer/phpdox": "0.9.0",
"phploc/phploc": "^3.0", "phploc/phploc": "^3.0",
"phpmd/phpmd": "^2.4", "phpmd/phpmd": "^2.4",
"phpunit/phpunit": "^6.0", "phpunit/phpunit": "^6.0",
"robmorgan/phinx": "^0.6.4", "robmorgan/phinx": "~0.6.4",
"consolidation/robo": "~1.0", "consolidation/robo": "~1.0",
"henrikbjorn/lurker": "^1.1.0", "henrikbjorn/lurker": "^1.1.0",
"symfony/var-dumper": "^3.1", "symfony/var-dumper": "^3.1",
@ -47,6 +47,7 @@
"scripts": { "scripts": {
"build:css": "cd public && npm run build && cd ..", "build:css": "cd public && npm run build && cd ..",
"coverage": "vendor/bin/phpunit -c build", "coverage": "vendor/bin/phpunit -c build",
"docs": "vendor/bin/phpdox",
"watch:css": "cd public && npm run watch", "watch:css": "cd public && npm run watch",
"test": "vendor/bin/phpunit" "test": "vendor/bin/phpunit"
} }

View File

@ -8,11 +8,11 @@
<target>phpdoc</target> <target>phpdoc</target>
</transformer> </transformer>
<transformations> <transformations>
<template name="zend" /> <template name="clean" />
</transformations> </transformations>
<files> <files>
<directory>src</directory> <directory>src</directory>
<directory>vendor/aviat/ion/src</directory> <!-- <directory>vendor/aviat/ion/src</directory>
<directory>vendor/container-interop/container-interop/src</directory> <directory>vendor/container-interop/container-interop/src</directory> -->
</files> </files>
</phpdoc> </phpdoc>

View File

@ -9,7 +9,7 @@
<bootstrap /> <bootstrap />
<!-- A phpDox project to process, you can have multiple projects in one config file --> <!-- A phpDox project to process, you can have multiple projects in one config file -->
<project name="Hummingbird Anime Client" source="../src" workdir="phpdox/xml"> <project name="Hummingbird Anime Client" source="src" workdir="build/phpdox/xml">
<!-- @name - The name of the project --> <!-- @name - The name of the project -->
<!-- @source - The source directory of the application to process --> <!-- @source - The source directory of the application to process -->
<!-- @workdir - The directory to store the xml data files in --> <!-- @workdir - The directory to store the xml data files in -->
@ -56,12 +56,12 @@
</collector> </collector>
<!-- Configuration of generation process --> <!-- Configuration of generation process -->
<generator output="../docs"> <generator output="docs">
<!-- @output - (Base-)Directory to store output data in --> <!-- @output - (Base-)Directory to store output data in -->
<!-- A generation process consists of one or more build tasks and of (optional) enrich sources --> <!-- A generation process consists of one or more build tasks and of (optional) enrich sources -->
<enrich base="logs"> <enrich base="build/logs">
<!-- @base - (Base-)Directory of datafiles used for enrich process --> <!-- @base - (Base-)Directory of datafiles used for enrich process -->
<!--<source type="...">--> <!--<source type="...">-->
@ -117,10 +117,10 @@
<!-- An engine and thus build node can have additional configuration child nodes, please check the documentation for the engine to find out more --> <!-- An engine and thus build node can have additional configuration child nodes, please check the documentation for the engine to find out more -->
<!-- default engine "html" --> <!-- default engine "html" -->
<build engine="html" enabled="true"> <build engine="html" output="html" />
<template dir="${phpDox.home}/templates/html" /> <!-- <template dir="${phpDox.home}/templates/html" /> -
<file extension="html" /> <file extension="html" />
</build> </build> -->
</generator> </generator>
</project> </project>

View File

@ -207,6 +207,7 @@ class APIRequestBuilder {
* *
* @param string $type * @param string $type
* @param string $uri * @param string $uri
* @throws InvalidArgumentException
* @return self * @return self
*/ */
public function newRequest(string $type, string $uri): self public function newRequest(string $type, string $uri): self

View File

@ -18,6 +18,9 @@ namespace Aviat\AnimeClient\API;
use UnexpectedValueException; use UnexpectedValueException;
/**
* Exception for an API Request that fails validation
*/
class FailedResponseException extends UnexpectedValueException { class FailedResponseException extends UnexpectedValueException {
} }

View File

@ -27,7 +27,7 @@ class JsonAPI {
* The full data array * The full data array
* *
* Basic structure is generally like so: * Basic structure is generally like so:
* @example [ * [
* 'id' => '12016665', * 'id' => '12016665',
* 'type' => 'libraryEntries', * 'type' => 'libraryEntries',
* 'links' => [ * 'links' => [

View File

@ -74,7 +74,7 @@ class Kitsu {
* @param string $endDate * @param string $endDate
* @return string * @return string
*/ */
public static function getAiringStatus(string $startDate = null, string $endDate = null): string public static function getAiringStatus(string $startDate = NULL, string $endDate = NULL): string
{ {
$startAirDate = new DateTimeImmutable($startDate ?? 'tomorrow'); $startAirDate = new DateTimeImmutable($startDate ?? 'tomorrow');
$endAirDate = new DateTimeImmutable($endDate ?? 'next year'); $endAirDate = new DateTimeImmutable($endDate ?? 'next year');
@ -83,7 +83,7 @@ class Kitsu {
$isDoneAiring = $now > $endAirDate; $isDoneAiring = $now > $endAirDate;
$isCurrentlyAiring = ($now > $startAirDate) && ! $isDoneAiring; $isCurrentlyAiring = ($now > $startAirDate) && ! $isDoneAiring;
switch (true) switch (TRUE)
{ {
case $isCurrentlyAiring: case $isCurrentlyAiring:
return AnimeAiringStatus::AIRING; return AnimeAiringStatus::AIRING;
@ -102,28 +102,28 @@ class Kitsu {
* @param string $hostname * @param string $hostname
* @return array * @return array
*/ */
protected static function getServiceMetaData(string $hostname = null): array protected static function getServiceMetaData(string $hostname = NULL): array
{ {
switch($hostname) switch($hostname)
{ {
case 'www.crunchyroll.com': case 'www.crunchyroll.com':
return [ return [
'name' => 'Crunchyroll', 'name' => 'Crunchyroll',
'link' => true, 'link' => TRUE,
'image' => 'streaming-logos/crunchyroll.svg', 'image' => 'streaming-logos/crunchyroll.svg',
]; ];
case 'www.funimation.com': case 'www.funimation.com':
return [ return [
'name' => 'Funimation', 'name' => 'Funimation',
'link' => true, 'link' => TRUE,
'image' => 'streaming-logos/funimation.svg', 'image' => 'streaming-logos/funimation.svg',
]; ];
case 'www.hulu.com': case 'www.hulu.com':
return [ return [
'name' => 'Hulu', 'name' => 'Hulu',
'link' => true, 'link' => TRUE,
'image' => 'streaming-logos/hulu.svg', 'image' => 'streaming-logos/hulu.svg',
]; ];
@ -132,7 +132,7 @@ class Kitsu {
default: default:
return [ return [
'name' => 'Netflix', 'name' => 'Netflix',
'link' => false, 'link' => FALSE,
'image' => 'streaming-logos/netflix.svg', 'image' => 'streaming-logos/netflix.svg',
]; ];
} }
@ -172,6 +172,7 @@ class Kitsu {
* Reorganize streaming links for the current list item * Reorganize streaming links for the current list item
* *
* @param array $included * @param array $included
* @param string $animeId
* @return array * @return array
*/ */
public static function parseListItemStreamingLinks(array $included, string $animeId): array public static function parseListItemStreamingLinks(array $included, string $animeId): array
@ -235,11 +236,11 @@ class Kitsu {
* @param array $existingTitles * @param array $existingTitles
* @return bool * @return bool
*/ */
private static function titleIsUnique(string $title = null, array $existingTitles = []): bool private static function titleIsUnique(string $title = NULL, array $existingTitles = []): bool
{ {
if (empty($title)) if (empty($title))
{ {
return false; return FALSE;
} }
foreach($existingTitles as $existing) foreach($existingTitles as $existing)
@ -248,12 +249,12 @@ class Kitsu {
$diff = levenshtein($existing, $title); $diff = levenshtein($existing, $title);
$onlydifferentCase = (mb_strtolower($existing) === mb_strtolower($title)); $onlydifferentCase = (mb_strtolower($existing) === mb_strtolower($title));
if ($diff < 3 || $isSubset || $onlydifferentCase) if ($diff < 3 OR $isSubset OR $onlydifferentCase)
{ {
return false; return FALSE;
} }
} }
return true; return TRUE;
} }
} }

View File

@ -16,8 +16,10 @@
namespace Aviat\AnimeClient\API\Kitsu; namespace Aviat\AnimeClient\API\Kitsu;
use Aviat\AnimeClient\API\APIRequestBuilder; use Aviat\AnimeClient\API\{
use Aviat\AnimeClient\API\Kitsu as K; APIRequestBuilder,
Kitsu as K
};
use Aviat\Ion\Json; use Aviat\Ion\Json;
class KitsuRequestBuilder extends APIRequestBuilder { class KitsuRequestBuilder extends APIRequestBuilder {

View File

@ -118,7 +118,7 @@ trait MALTrait {
*/ */
private function getResponse(string $type, string $url, array $options = []) private function getResponse(string $type, string $url, array $options = [])
{ {
$logger = null; $logger = NULL;
if ($this->getContainer()) if ($this->getContainer())
{ {
$logger = $this->container->getLogger('mal-request'); $logger = $this->container->getLogger('mal-request');
@ -148,7 +148,7 @@ trait MALTrait {
*/ */
private function request(string $type, string $url, array $options = []): array private function request(string $type, string $url, array $options = []): array
{ {
$logger = null; $logger = NULL;
if ($this->getContainer()) if ($this->getContainer())
{ {
$logger = $this->container->getLogger('mal-request'); $logger = $this->container->getLogger('mal-request');
@ -156,7 +156,7 @@ trait MALTrait {
$response = $this->getResponse($type, $url, $options); $response = $this->getResponse($type, $url, $options);
if ((int) $response->getStatus() > 299 || (int) $response->getStatus() < 200) if ((int) $response->getStatus() > 299 OR (int) $response->getStatus() < 200)
{ {
if ($logger) if ($logger)
{ {
@ -170,7 +170,7 @@ trait MALTrait {
/** /**
* Remove some boilerplate for get requests * Remove some boilerplate for get requests
* *
* @param array $args * @param mixed ...$args
* @return array * @return array
*/ */
protected function getRequest(...$args): array protected function getRequest(...$args): array
@ -181,12 +181,12 @@ trait MALTrait {
/** /**
* Remove some boilerplate for post requests * Remove some boilerplate for post requests
* *
* @param array $args * @param mixed ...$args
* @return array * @return array
*/ */
protected function postRequest(...$args): array protected function postRequest(...$args): array
{ {
$logger = null; $logger = NULL;
if ($this->getContainer()) if ($this->getContainer())
{ {
$logger = $this->container->getLogger('mal-request'); $logger = $this->container->getLogger('mal-request');

View File

@ -37,6 +37,8 @@ class Model {
/** /**
* MAL Model constructor. * MAL Model constructor.
*
* @param ListItem $listItem
*/ */
public function __construct(ListItem $listItem) public function __construct(ListItem $listItem)
{ {

View File

@ -39,7 +39,7 @@ class ParallelAPIRequest {
* @param string|number $key * @param string|number $key
* @return self * @return self
*/ */
public function addRequest($request, $key = null): self public function addRequest($request, $key = NULL): self
{ {
if ( ! is_null($key)) if ( ! is_null($key))
{ {

View File

@ -39,6 +39,9 @@ class XML {
/** /**
* XML constructor * XML constructor
*
* @param string $xml
* @param array $data
*/ */
public function __construct(string $xml = '', array $data = []) public function __construct(string $xml = '', array $data = [])
{ {
@ -47,6 +50,8 @@ class XML {
/** /**
* Serialize the data to an xml string * Serialize the data to an xml string
*
* @return string
*/ */
public function __toString(): string public function __toString(): string
{ {
@ -67,7 +72,7 @@ class XML {
* Set the data to create xml from * Set the data to create xml from
* *
* @param array $data * @param array $data
* @return $this * @return self
*/ */
public function setData(array $data): self public function setData(array $data): self
{ {
@ -89,7 +94,7 @@ class XML {
* Set the xml to parse the data from * Set the xml to parse the data from
* *
* @param string $xml * @param string $xml
* @return $this * @return self
*/ */
public function setXML(string $xml): self public function setXML(string $xml): self
{ {
@ -161,20 +166,28 @@ class XML {
return static::toXML($this->getData()); return static::toXML($this->getData());
} }
/**
* Strip whitespace from raw xml to remove irrelevant text nodes
*
* @param string $xml
* @return string
*/
private static function stripXMLWhitespace(string $xml): string private static function stripXMLWhitespace(string $xml): string
{ {
// Get rid of unimportant text nodes by removing // Get rid of unimportant text nodes by removing
// whitespace characters from between xml tags, // whitespace characters from between xml tags,
// except for the xml declaration tag, Which looks // except for the xml declaration tag, Which looks
// something like: // something like:
/* <?xml version="1.0" encoding="UTF-8"?> */ /* <?xml version="1.0" encoding="UTF-8"?> */
return preg_replace('/([^\?])>\s+</', '$1><', $xml); return preg_replace('/([^\?])>\s+</', '$1><', $xml);
} }
/** /**
* Recursively create array structure based on xml structure * Recursively create array structure based on xml structure
* *
* @param array &$root A reference to the current array location * @param array $root A reference to the current array location
* @param DOMNodeList $nodeList The current NodeList object * @param DOMNodeList $nodeList The current NodeList object
* @return void * @return void
*/ */
@ -187,7 +200,7 @@ class XML {
$current =& $root[$el->nodeName]; $current =& $root[$el->nodeName];
// It's a top level element! // It's a top level element!
if (is_a($el->childNodes->item(0), 'DomText') || ( ! $el->hasChildNodes())) if (is_a($el->childNodes->item(0), 'DomText') OR ( ! $el->hasChildNodes()))
{ {
$current = $el->textContent; $current = $el->textContent;
continue; continue;

View File

@ -23,6 +23,8 @@ class ClearCache extends BaseCommand {
/** /**
* Clear the API cache * Clear the API cache
* *
* @param array $args
* @param array $options
* @return void * @return void
* @throws \ConsoleKit\ConsoleException * @throws \ConsoleKit\ConsoleException
*/ */

View File

@ -29,7 +29,16 @@ use Aviat\Ion\Json;
*/ */
class SyncKitsuWithMal extends BaseCommand { class SyncKitsuWithMal extends BaseCommand {
/**
* Model for making requests to Kitsu API
* @var Aviat\AnimeClient\API\Kitsu
*/
protected $kitsuModel; protected $kitsuModel;
/**
* Model for making requests to MAL API
* @var Aviat\AnimeClient\API\MAL
*/
protected $malModel; protected $malModel;
/** /**
@ -56,12 +65,11 @@ class SyncKitsuWithMal extends BaseCommand {
$data = $this->diffLists(); $data = $this->diffLists();
$this->echoBox("Number of items that need to be added to MAL: " . count($data)); $this->echoBox("Number of items that need to be added to MAL: " . count($data));
if (! empty($data['addToMAL'])) if ( ! empty($data['addToMAL']))
{ {
$this->echoBox("Adding missing list items to MAL"); $this->echoBox("Adding missing list items to MAL");
$this->createMALListItems($data['addToMAL']); $this->createMALListItems($data['addToMAL']);
} }
} }
public function getKitsuList() public function getKitsuList()
@ -113,8 +121,6 @@ class SyncKitsuWithMal extends BaseCommand {
return $output; return $output;
} }
// 2015-05-20T23:48:47.731Z
public function formatMALList() public function formatMALList()
{ {
$orig = $this->getMALList(); $orig = $this->getMALList();
@ -155,7 +161,7 @@ class SyncKitsuWithMal extends BaseCommand {
{ {
$animeId = $listItem['relationships']['anime']['data']['id']; $animeId = $listItem['relationships']['anime']['data']['id'];
$potentialMappings = $includes['anime'][$animeId]['relationships']['mappings']; $potentialMappings = $includes['anime'][$animeId]['relationships']['mappings'];
$malId = null; $malId = NULL;
foreach ($potentialMappings as $mappingId) foreach ($potentialMappings as $mappingId)
{ {
@ -166,7 +172,7 @@ class SyncKitsuWithMal extends BaseCommand {
} }
// Skip to the next item if there isn't a MAL ID // Skip to the next item if there isn't a MAL ID
if ($malId === null) if (is_null($malId))
{ {
continue; continue;
} }

View File

@ -369,7 +369,7 @@ class Controller {
{ {
static $messages; static $messages;
if (!$messages) if ( ! $messages)
{ {
$messages = []; $messages = [];
} }

View File

@ -26,7 +26,7 @@ class API extends AbstractModel {
* *
* @codeCoverageIgnore * @codeCoverageIgnore
* @param array $array * @param array $array
* @param string $sort_key * @param string $sortKey
* @return void * @return void
*/ */
protected function sortByName(array &$array, string $sortKey) protected function sortByName(array &$array, string $sortKey)

View File

@ -48,17 +48,34 @@ class Anime extends API {
AnimeWatchingStatus::COMPLETED => self::COMPLETED, AnimeWatchingStatus::COMPLETED => self::COMPLETED,
]; ];
/**
* Model for making requests to Kitsu API
*
* @var Aviat\AnimeClient\API\Kitsu\Model
*/
protected $kitsuModel; protected $kitsuModel;
/**
* Model for making requests to MAL API
*
* @var Aviat\AnimeClient\API\MAL\Model
*/
protected $malModel; protected $malModel;
/**
* Whether to use the MAL api
*
* @var boolean
*/
protected $useMALAPI; protected $useMALAPI;
/** /**
* Anime constructor. * Anime constructor.
*
* @param ContainerInterface $container * @param ContainerInterface $container
*/ */
public function __construct(ContainerInterface $container) { public function __construct(ContainerInterface $container)
{
$config = $container->get('config'); $config = $container->get('config');
$this->kitsuModel = $container->get('kitsu-model'); $this->kitsuModel = $container->get('kitsu-model');
$this->malModel = $container->get('mal-model'); $this->malModel = $container->get('mal-model');
@ -193,7 +210,7 @@ class Anime extends API {
* @param string|null $malId * @param string|null $malId
* @return bool * @return bool
*/ */
public function deleteLibraryItem(string $id, string $malId = null): bool public function deleteLibraryItem(string $id, string $malId = NULL): bool
{ {
$requests = []; $requests = [];

View File

@ -44,6 +44,10 @@ class Manga extends API
MangaReadingStatus::COMPLETED => self::COMPLETED MangaReadingStatus::COMPLETED => self::COMPLETED
]; ];
/**
* Maps url segments to their title equivalents
* @var array
*/
protected $statusMap = [ protected $statusMap = [
'current' => self::READING, 'current' => self::READING,
'planned' => self::PLAN_TO_READ, 'planned' => self::PLAN_TO_READ,
@ -53,10 +57,16 @@ class Manga extends API
]; ];
/** /**
* Model for making requests to Kitsu API
* @var Aviat\AnimeClient\API\Kitsu\KitsuModel * @var Aviat\AnimeClient\API\Kitsu\KitsuModel
*/ */
protected $kitsuModel; protected $kitsuModel;
/**
* Constructor
*
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container) public function __construct(ContainerInterface $container)
{ {
$this->kitsuModel = $container->get('kitsu-model'); $this->kitsuModel = $container->get('kitsu-model');

View File

@ -44,9 +44,10 @@ class UrlGenerator extends RoutingBase {
/** /**
* Get the base url for css/js/images * Get the base url for css/js/images
* *
* @param string ...$args url segments to apend to the base asset url
* @return string * @return string
*/ */
public function assetUrl(...$args) public function assetUrl(...$args): string
{ {
$baseUrl = rtrim($this->url(""), '/'); $baseUrl = rtrim($this->url(""), '/');
$baseUrl = "{$baseUrl}" . $this->__get("asset_path"); $baseUrl = "{$baseUrl}" . $this->__get("asset_path");
@ -62,7 +63,7 @@ class UrlGenerator extends RoutingBase {
* @param string $path * @param string $path
* @return string * @return string
*/ */
public function url($path) public function url(string $path): string
{ {
$path = trim($path, '/'); $path = trim($path, '/');
@ -95,7 +96,7 @@ class UrlGenerator extends RoutingBase {
* @throws InvalidArgumentException * @throws InvalidArgumentException
* @return string * @return string
*/ */
public function defaultUrl($type) public function defaultUrl(string $type): string
{ {
$type = trim($type); $type = trim($type);
$defaultPath = $this->__get("default_{$type}_list_path"); $defaultPath = $this->__get("default_{$type}_list_path");
@ -115,9 +116,9 @@ class UrlGenerator extends RoutingBase {
* @param string $type - (optional) The controller (anime or manga), defaults to anime * @param string $type - (optional) The controller (anime or manga), defaults to anime
* @return string * @return string
*/ */
public function fullUrl($path = "", $type = "anime") public function fullUrl(string $path = "", string $type = "anime"): string
{ {
$config_default_route = $this->__get("default_{$type}_path"); $configDefaultRoute = $this->__get("default_{$type}_path");
// Remove beginning/trailing slashes // Remove beginning/trailing slashes
$path = trim($path, '/'); $path = trim($path, '/');
@ -125,7 +126,7 @@ class UrlGenerator extends RoutingBase {
// Set the default view // Set the default view
if ($path === '') if ($path === '')
{ {
$path .= trim($config_default_route, '/'); $path .= trim($configDefaultRoute, '/');
if ($this->__get('default_to_list_view')) if ($this->__get('default_to_list_view'))
{ {
$path .= '/list'; $path .= '/list';