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()
{
$cmd_parts = [
'cd build',
'../vendor/bin/phpdox',
'cd ..'
'phpdox',
];
$this->_run($cmd_parts, ' && ');
}
@ -209,11 +207,6 @@ class RoboFile extends Tasks {
$this->lint();
$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];
if (T_WHITESPACE !== $previous_token['code'] || T_WHITESPACE !== $next_token['code']) {
$error = 'Logical operator ! should always be preceded and followed with a whitespace.';
$phpcsFile->addError($error, $stackPtr);
$phpcsFile->addError($error, $stackPtr, 'badNot');
}
}//end process()

View File

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

View File

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

View File

@ -9,7 +9,7 @@
<bootstrap />
<!-- 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 -->
<!-- @source - The source directory of the application to process -->
<!-- @workdir - The directory to store the xml data files in -->
@ -56,12 +56,12 @@
</collector>
<!-- Configuration of generation process -->
<generator output="../docs">
<generator output="docs">
<!-- @output - (Base-)Directory to store output data in -->
<!-- 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 -->
<!--<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 -->
<!-- default engine "html" -->
<build engine="html" enabled="true">
<template dir="${phpDox.home}/templates/html" />
<build engine="html" output="html" />
<!-- <template dir="${phpDox.home}/templates/html" /> -
<file extension="html" />
</build>
</build> -->
</generator>
</project>

View File

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

View File

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

View File

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

View File

@ -74,7 +74,7 @@ class Kitsu {
* @param string $endDate
* @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');
$endAirDate = new DateTimeImmutable($endDate ?? 'next year');
@ -83,7 +83,7 @@ class Kitsu {
$isDoneAiring = $now > $endAirDate;
$isCurrentlyAiring = ($now > $startAirDate) && ! $isDoneAiring;
switch (true)
switch (TRUE)
{
case $isCurrentlyAiring:
return AnimeAiringStatus::AIRING;
@ -102,28 +102,28 @@ class Kitsu {
* @param string $hostname
* @return array
*/
protected static function getServiceMetaData(string $hostname = null): array
protected static function getServiceMetaData(string $hostname = NULL): array
{
switch($hostname)
{
case 'www.crunchyroll.com':
return [
'name' => 'Crunchyroll',
'link' => true,
'link' => TRUE,
'image' => 'streaming-logos/crunchyroll.svg',
];
case 'www.funimation.com':
return [
'name' => 'Funimation',
'link' => true,
'link' => TRUE,
'image' => 'streaming-logos/funimation.svg',
];
case 'www.hulu.com':
return [
'name' => 'Hulu',
'link' => true,
'link' => TRUE,
'image' => 'streaming-logos/hulu.svg',
];
@ -132,7 +132,7 @@ class Kitsu {
default:
return [
'name' => 'Netflix',
'link' => false,
'link' => FALSE,
'image' => 'streaming-logos/netflix.svg',
];
}
@ -172,6 +172,7 @@ class Kitsu {
* Reorganize streaming links for the current list item
*
* @param array $included
* @param string $animeId
* @return array
*/
public static function parseListItemStreamingLinks(array $included, string $animeId): array
@ -235,11 +236,11 @@ class Kitsu {
* @param array $existingTitles
* @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))
{
return false;
return FALSE;
}
foreach($existingTitles as $existing)
@ -248,12 +249,12 @@ class Kitsu {
$diff = levenshtein($existing, $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;
use Aviat\AnimeClient\API\APIRequestBuilder;
use Aviat\AnimeClient\API\Kitsu as K;
use Aviat\AnimeClient\API\{
APIRequestBuilder,
Kitsu as K
};
use Aviat\Ion\Json;
class KitsuRequestBuilder extends APIRequestBuilder {

View File

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

View File

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

View File

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

View File

@ -39,6 +39,9 @@ class XML {
/**
* XML constructor
*
* @param string $xml
* @param array $data
*/
public function __construct(string $xml = '', array $data = [])
{
@ -47,6 +50,8 @@ class XML {
/**
* Serialize the data to an xml string
*
* @return string
*/
public function __toString(): string
{
@ -67,7 +72,7 @@ class XML {
* Set the data to create xml from
*
* @param array $data
* @return $this
* @return self
*/
public function setData(array $data): self
{
@ -89,7 +94,7 @@ class XML {
* Set the xml to parse the data from
*
* @param string $xml
* @return $this
* @return self
*/
public function setXML(string $xml): self
{
@ -161,20 +166,28 @@ class XML {
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
{
// Get rid of unimportant text nodes by removing
// whitespace characters from between xml tags,
// except for the xml declaration tag, Which looks
// something like:
/* <?xml version="1.0" encoding="UTF-8"?> */
return preg_replace('/([^\?])>\s+</', '$1><', $xml);
}
/**
* 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
* @return void
*/
@ -187,7 +200,7 @@ class XML {
$current =& $root[$el->nodeName];
// 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;
continue;

View File

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

View File

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

View File

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

View File

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

View File

@ -44,6 +44,10 @@ class Manga extends API
MangaReadingStatus::COMPLETED => self::COMPLETED
];
/**
* Maps url segments to their title equivalents
* @var array
*/
protected $statusMap = [
'current' => self::READING,
'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
*/
protected $kitsuModel;
/**
* Constructor
*
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->kitsuModel = $container->get('kitsu-model');

View File

@ -44,9 +44,10 @@ class UrlGenerator extends RoutingBase {
/**
* Get the base url for css/js/images
*
* @param string ...$args url segments to apend to the base asset url
* @return string
*/
public function assetUrl(...$args)
public function assetUrl(...$args): string
{
$baseUrl = rtrim($this->url(""), '/');
$baseUrl = "{$baseUrl}" . $this->__get("asset_path");
@ -62,7 +63,7 @@ class UrlGenerator extends RoutingBase {
* @param string $path
* @return string
*/
public function url($path)
public function url(string $path): string
{
$path = trim($path, '/');
@ -95,7 +96,7 @@ class UrlGenerator extends RoutingBase {
* @throws InvalidArgumentException
* @return string
*/
public function defaultUrl($type)
public function defaultUrl(string $type): string
{
$type = trim($type);
$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
* @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
$path = trim($path, '/');
@ -125,7 +126,7 @@ class UrlGenerator extends RoutingBase {
// Set the default view
if ($path === '')
{
$path .= trim($config_default_route, '/');
$path .= trim($configDefaultRoute, '/');
if ($this->__get('default_to_list_view'))
{
$path .= '/list';