Miscellaneous code style changes

This commit is contained in:
Timothy Warren 2017-12-06 14:40:13 -05:00
parent 1ea3a59b6a
commit 1634e98799
7 changed files with 129 additions and 100 deletions

View File

@ -90,7 +90,7 @@ class ByteOrderMarkSniff implements Sniff
$fileStartHex = bin2hex(substr($fileStartString, 0, $bomByteLength)); $fileStartHex = bin2hex(substr($fileStartString, 0, $bomByteLength));
if ($fileStartHex === $expectedBomHex) { if ($fileStartHex === $expectedBomHex) {
$error = "File contains a $bomName byte order mark (BOM)."; $error = "File contains a $bomName byte order mark (BOM).";
$phpcsFile->addError($error, $stackPtr); $phpcsFile->addError($error, $stackPtr, 123);
break; break;
} }
} }

View File

@ -17,6 +17,7 @@ namespace CodeIgniter\Sniffs\Strings;
use PHP_CodeSniffer\Sniffs\Sniff; use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Files\File;
use Exception;
/** /**
* CodeIgniter_Sniffs_Strings_DoubleQuoteUsageSniff. * CodeIgniter_Sniffs_Strings_DoubleQuoteUsageSniff.
@ -104,19 +105,19 @@ class VariableUsageSniff implements Sniff
$this->_parseVariable($strTokens, $strPtr); $this->_parseVariable($strTokens, $strPtr);
} catch (Exception $err) { } catch (Exception $err) {
$error = 'There is no variable, object nor array between curly braces. Please use the escape char for $ or {.'; $error = 'There is no variable, object nor array between curly braces. Please use the escape char for $ or {.';
$phpcsFile->addError($error, $stackPtr); $phpcsFile->addError($error, $stackPtr, 234);
} }
$variableFound = TRUE; $variableFound = TRUE;
if ('}' !== $strTokens[$strPtr]) { if ('}' !== $strTokens[$strPtr]) {
$error = 'There is no matching closing curly brace.'; $error = 'There is no matching closing curly brace.';
$phpcsFile->addError($error, $stackPtr); $phpcsFile->addError($error, $stackPtr, 345);
} }
// don't move forward, since it will be done in the main loop // don't move forward, since it will be done in the main loop
// $strPtr++; // $strPtr++;
} else if (T_VARIABLE === $strToken[0]) { } else if (T_VARIABLE === $strToken[0]) {
$variableFound = TRUE; $variableFound = TRUE;
$error = "Variable {$strToken[1]} in double-quoted strings should be enclosed with curly braces. Please consider {{$strToken[1]}}"; $error = "Variable {$strToken[1]} in double-quoted strings should be enclosed with curly braces. Please consider {{$strToken[1]}}";
$phpcsFile->addError($error, $stackPtr); $phpcsFile->addError($error, $stackPtr, 456);
} }
} }
$strPtr++; $strPtr++;

View File

@ -1,58 +1,57 @@
{ {
"name": "aviat/hummingbird-anime-client", "name": "aviat/hummingbird-anime-client",
"description": "A self-hosted anime/manga client for Kitsu.", "description": "A self-hosted anime/manga client for Kitsu.",
"license":"MIT", "license": "MIT",
"autoload": { "autoload": {
"files": [ "files": [
"src/AnimeClient.php" "src/AnimeClient.php"
], ],
"psr-4": { "psr-4": {
"Aviat\\AnimeClient\\": "src/" "Aviat\\AnimeClient\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Aviat\\AnimeClient\\Tests\\": "tests/",
"CodeIgniter\\": "build/CodeIgniter/"
}
},
"require": {
"aura/html": "^2.0",
"aura/router": "^3.0",
"aura/session": "^2.0",
"aviat/banker": "^1.0.0",
"aviat/ion": "^2.2.0",
"monolog/monolog": "^1.0",
"psr/http-message": "~1.0",
"psr/log": "~1.0",
"yosymfony/toml": "^1.0",
"zendframework/zend-diactoros": "^1.3",
"maximebf/consolekit": "^1.0",
"amphp/artax": "^2.0"
},
"require-dev": {
"pdepend/pdepend": "^2.2",
"sebastian/phpcpd": "^3.0",
"theseer/phpdox": "dev-master",
"phploc/phploc": "^4.0",
"phpmd/phpmd": "^2.4",
"phpunit/phpunit": "^6.0",
"robmorgan/phinx": "^0.9.1",
"consolidation/robo": "~1.0",
"henrikbjorn/lurker": "^1.1.0",
"symfony/var-dumper": "^4.0.1",
"squizlabs/php_codesniffer": "^3.0.0@beta",
"phpstan/phpstan": "^0.9.1",
"spatie/phpunit-snapshot-assertions": "^1.2.0"
},
"scripts": {
"build": "vendor/bin/robo build",
"build:css": "cd public && npm run build && cd ..",
"clean": "vendor/bin/robo clean",
"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build",
"docs": "vendor/bin/phpdox",
"phpstan": "phpstan analyse src tests",
"watch:css": "cd public && npm run watch",
"test": "vendor/bin/phpunit"
} }
},
"autoload-dev": {
"psr-4": {
"Aviat\\AnimeClient\\Tests\\": "tests/",
"CodeIgniter\\": "build/CodeIgniter/"
}
},
"require": {
"amphp/artax": "^2.0",
"aura/html": "^2.0",
"aura/router": "^3.0",
"aura/session": "^2.0",
"aviat/banker": "^1.0.0",
"aviat/ion": "^2.2.0",
"maximebf/consolekit": "^1.0",
"monolog/monolog": "^1.0",
"psr/http-message": "~1.0",
"psr/log": "~1.0",
"yosymfony/toml": "^1.0",
"zendframework/zend-diactoros": "^1.3"
},
"require-dev": {
"consolidation/robo": "~1.0",
"henrikbjorn/lurker": "^1.1.0",
"pdepend/pdepend": "^2.2",
"phploc/phploc": "^4.0",
"phpmd/phpmd": "^2.4",
"phpstan/phpstan": "^0.9.1",
"phpunit/phpunit": "^6.0",
"robmorgan/phinx": "^0.9.1",
"sebastian/phpcpd": "^3.0",
"spatie/phpunit-snapshot-assertions": "^1.2.0",
"squizlabs/php_codesniffer": "^3.0.0@beta",
"theseer/phpdox": "^0.10.1"
},
"scripts": {
"build": "vendor/bin/robo build",
"build:css": "cd public && npm run build && cd ..",
"clean": "vendor/bin/robo clean",
"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build",
"docs": "vendor/bin/phpdox",
"phpstan": "phpstan analyse src tests",
"watch:css": "cd public && npm run watch",
"test": "vendor/bin/phpunit"
}
} }

View File

@ -16,7 +16,6 @@
namespace Aviat\AnimeClient; namespace Aviat\AnimeClient;
use function Aviat\AnimeClient\loadToml;
use function Aviat\Ion\_dir; use function Aviat\Ion\_dir;
// Work around the silly timezone error // Work around the silly timezone error
@ -27,7 +26,7 @@ if ($timezone === '' || $timezone === FALSE)
} }
// Load composer autoloader // Load composer autoloader
require __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/vendor/autoload.php';
// Define base directories // Define base directories
$APP_DIR = _dir(__DIR__, 'app'); $APP_DIR = _dir(__DIR__, 'app');
@ -37,8 +36,8 @@ $CONF_DIR = _dir($APP_DIR, 'config');
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Dependency Injection setup // Dependency Injection setup
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
require _dir($APPCONF_DIR, 'base_config.php'); // $base_config require_once $APPCONF_DIR . '/base_config.php'; // $base_config
$di = require _dir($APP_DIR, 'bootstrap.php'); $di = require $APP_DIR . '/bootstrap.php';
$config = loadToml($CONF_DIR); $config = loadToml($CONF_DIR);
$config_array = array_merge($base_config, $config); $config_array = array_merge($base_config, $config);
@ -46,10 +45,9 @@ $config_array = array_merge($base_config, $config);
$container = $di($config_array); $container = $di($config_array);
// Unset 'constants' // Unset 'constants'
unset($APP_DIR); unset($APP_DIR, $APPCONF_DIR);
unset($CONF_DIR);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Dispatch to the current route // Dispatch to the current route
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
$container->get('dispatcher')->__invoke(); $container->get('dispatcher')();

View File

@ -18,7 +18,10 @@ namespace Aviat\AnimeClient;
use Yosymfony\Toml\Toml; use Yosymfony\Toml\Toml;
define('SRC_DIR', realpath(__DIR__)); if ( ! defined('SRC_DIR'))
{
\define('SRC_DIR', \realpath(__DIR__));
}
const SESSION_SEGMENT = 'Aviat\AnimeClient\Auth'; const SESSION_SEGMENT = 'Aviat\AnimeClient\Auth';
const DEFAULT_CONTROLLER = 'Aviat\AnimeClient\Controller\Index'; const DEFAULT_CONTROLLER = 'Aviat\AnimeClient\Controller\Index';
@ -29,35 +32,39 @@ const NOT_FOUND_METHOD = 'notFound';
const ERROR_MESSAGE_METHOD = 'errorPage'; const ERROR_MESSAGE_METHOD = 'errorPage';
const SRC_DIR = SRC_DIR; const SRC_DIR = SRC_DIR;
/**
* Load configuration options from .toml files if ( ! \function_exists('Aviat\AnimeClient\loadToml'))
*
* @param string $path - Path to load config
* @return array
*/
function loadToml(string $path): array
{ {
$output = []; /**
$files = glob("{$path}/*.toml"); * Load configuration options from .toml files
*
foreach ($files as $file) * @param string $path - Path to load config
* @return array
*/
function loadToml(string $path): array
{ {
$key = str_replace('.toml', '', basename($file)); $output = [];
$toml = file_get_contents($file); $files = glob("{$path}/*.toml");
$config = Toml::Parse($toml);
if ($key === 'config') foreach ($files as $file)
{ {
foreach($config as $name => $value) $key = str_replace('.toml', '', basename($file));
$toml = file_get_contents($file);
$config = Toml::parse($toml);
if ($key === 'config')
{ {
$output[$name] = $value; foreach($config as $name => $value)
{
$output[$name] = $value;
}
continue;
} }
continue; $output[$key] = $config;
} }
$output[$key] = $config; return $output;
} }
}
return $output;
}

View File

@ -16,19 +16,17 @@
namespace Aviat\AnimeClient; namespace Aviat\AnimeClient;
use const Aviat\AnimeClient\SESSION_SEGMENT;
use function Aviat\Ion\_dir; use function Aviat\Ion\_dir;
use Aviat\AnimeClient\API\JsonAPI;
use Aviat\Ion\Di\{ContainerAware, ContainerInterface}; use Aviat\Ion\Di\{ContainerAware, ContainerInterface};
use Aviat\Ion\Exception\DoubleRenderException;
use Aviat\Ion\View\{HtmlView, HttpView, JsonView}; use Aviat\Ion\View\{HtmlView, HttpView, JsonView};
use InvalidArgumentException; use InvalidArgumentException;
/** /**
* Controller base, defines output methods * Controller base, defines output methods
* *
* @property Response object $response * @property $response Response object
*/ */
class Controller { class Controller {
@ -96,6 +94,8 @@ class Controller {
* Constructor * Constructor
* *
* @param ContainerInterface $container * @param ContainerInterface $container
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
*/ */
public function __construct(ContainerInterface $container) public function __construct(ContainerInterface $container)
{ {
@ -122,7 +122,7 @@ class Controller {
// Set a 'previous' flash value for better redirects // Set a 'previous' flash value for better redirects
$serverParams = $this->request->getServerParams(); $serverParams = $this->request->getServerParams();
if (array_key_exists('HTTP_REFERER', $serverParams)) if (array_key_exists('HTTP_REFERER', $serverParams) && false === stripos($serverParams['HTTP_REFERER'], 'login'))
{ {
$this->session->setFlash('previous', $serverParams['HTTP_REFERER']); $this->session->setFlash('previous', $serverParams['HTTP_REFERER']);
} }
@ -146,6 +146,8 @@ class Controller {
* Set the current url in the session as the target of a future redirect * Set the current url in the session as the target of a future redirect
* *
* @param string|null $url * @param string|null $url
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return void * @return void
*/ */
public function setSessionRedirect(string $url = NULL) public function setSessionRedirect(string $url = NULL)
@ -159,16 +161,17 @@ class Controller {
$util = $this->container->get('util'); $util = $this->container->get('util');
$doubleFormPage = $serverParams['HTTP_REFERER'] === $this->request->getUri(); $doubleFormPage = $serverParams['HTTP_REFERER'] === $this->request->getUri();
$isLoginPage = (bool) strpos($serverParams['HTTP_REFERER'], 'login');
// Don't attempt to set the redirect url if // Don't attempt to set the redirect url if
// the page is one of the form type pages, // the page is one of the form type pages,
// and the previous page is also a form type page_segments // and the previous page is also a form type page_segments
if ($doubleFormPage) if ($doubleFormPage || $isLoginPage)
{ {
return; return;
} }
if (is_null($url)) if (null === $url)
{ {
$url = $util->isViewPage() $url = $util->isViewPage()
? $this->request->url->get() ? $this->request->url->get()
@ -181,6 +184,9 @@ class Controller {
/** /**
* Redirect to the url previously set in the session * Redirect to the url previously set in the session
* *
* @throws InvalidArgumentException
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return void * @return void
*/ */
public function sessionRedirect() public function sessionRedirect()
@ -204,6 +210,8 @@ class Controller {
* @param string $template * @param string $template
* @param array $data * @param array $data
* @throws InvalidArgumentException * @throws InvalidArgumentException
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return string * @return string
*/ */
protected function loadPartial($view, string $template, array $data = []) protected function loadPartial($view, string $template, array $data = [])
@ -235,6 +243,9 @@ class Controller {
* @param HtmlView $view * @param HtmlView $view
* @param string $template * @param string $template
* @param array $data * @param array $data
* @throws InvalidArgumentException
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return void * @return void
*/ */
protected function renderFullPage($view, string $template, array $data) protected function renderFullPage($view, string $template, array $data)
@ -260,6 +271,11 @@ class Controller {
/** /**
* 404 action * 404 action
* *
* @param string $title
* @param string $message
* @throws InvalidArgumentException
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return void * @return void
*/ */
public function notFound( public function notFound(
@ -280,6 +296,9 @@ class Controller {
* @param string $title * @param string $title
* @param string $message * @param string $message
* @param string $long_message * @param string $long_message
* @throws InvalidArgumentException
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return void * @return void
*/ */
public function errorPage(int $httpCode, string $title, string $message, string $long_message = "") public function errorPage(int $httpCode, string $title, string $message, string $long_message = "")
@ -330,7 +349,7 @@ class Controller {
/** /**
* Helper for consistent page titles * Helper for consistent page titles
* *
* @param string ...$parts Title segements * @param string[] ...$parts Title segments
* @return string * @return string
*/ */
public function formatTitle(string ...$parts) : string public function formatTitle(string ...$parts) : string
@ -344,6 +363,9 @@ class Controller {
* @param HtmlView $view * @param HtmlView $view
* @param string $type * @param string $type
* @param string $message * @param string $message
* @throws InvalidArgumentException
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return string * @return string
*/ */
protected function showMessage($view, string $type, string $message): string protected function showMessage($view, string $type, string $message): string
@ -361,11 +383,14 @@ class Controller {
* @param array $data * @param array $data
* @param HtmlView|null $view * @param HtmlView|null $view
* @param int $code * @param int $code
* @throws InvalidArgumentException
* @throws \Aviat\Ion\Di\ContainerException
* @throws \Aviat\Ion\Di\NotFoundException
* @return void * @return void
*/ */
protected function outputHTML(string $template, array $data = [], $view = NULL, int $code = 200) protected function outputHTML(string $template, array $data = [], $view = NULL, int $code = 200)
{ {
if (is_null($view)) if (null === $view)
{ {
$view = new HtmlView($this->container); $view = new HtmlView($this->container);
} }
@ -379,6 +404,7 @@ class Controller {
* *
* @param mixed $data * @param mixed $data
* @param int $code - the http status code * @param int $code - the http status code
* @throws DoubleRenderException
* @return void * @return void
*/ */
protected function outputJSON($data = 'Empty response', int $code = 200) protected function outputJSON($data = 'Empty response', int $code = 200)

View File

@ -273,8 +273,6 @@ class Manga extends Controller {
); );
} }
// dump($data);
foreach($data['included'] as $included) foreach($data['included'] as $included)
{ {
if ($included['type'] === 'characters') if ($included['type'] === 'characters')