Reformat misc files

This commit is contained in:
Timothy Warren 2022-03-03 18:19:02 -05:00
parent 047ee4cb37
commit 327065498b
9 changed files with 85 additions and 91 deletions

View File

@ -16,10 +16,10 @@
use const Aviat\AnimeClient\{ use const Aviat\AnimeClient\{
ALPHA_SLUG_PATTERN, ALPHA_SLUG_PATTERN,
NUM_PATTERN, DEFAULT_CONTROLLER,
SLUG_PATTERN,
DEFAULT_CONTROLLER_METHOD, DEFAULT_CONTROLLER_METHOD,
DEFAULT_CONTROLLER NUM_PATTERN,
SLUG_PATTERN
}; };
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
@ -190,14 +190,14 @@ $routes = [
'character' => [ 'character' => [
'path' => '/character/{slug}', 'path' => '/character/{slug}',
'tokens' => [ 'tokens' => [
'slug' => SLUG_PATTERN 'slug' => SLUG_PATTERN,
] ],
], ],
'person' => [ 'person' => [
'path' => '/people/{slug}', 'path' => '/people/{slug}',
'tokens' => [ 'tokens' => [
'slug' => SLUG_PATTERN, 'slug' => SLUG_PATTERN,
] ],
], ],
'default_user_info' => [ 'default_user_info' => [
'path' => '/me', 'path' => '/me',
@ -209,8 +209,8 @@ $routes = [
'controller' => 'user', 'controller' => 'user',
'action' => 'about', 'action' => 'about',
'tokens' => [ 'tokens' => [
'username' => '.*?' 'username' => '.*?',
] ],
], ],
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Default / Shared routes // Default / Shared routes
@ -231,8 +231,8 @@ $routes = [
'controller' => 'images', 'controller' => 'images',
'tokens' => [ 'tokens' => [
'type' => SLUG_PATTERN, 'type' => SLUG_PATTERN,
'file' => '[a-z0-9\-]+\.[a-z]{3,4}' 'file' => '[a-z0-9\-]+\.[a-z]{3,4}',
] ],
], ],
'settings' => [ 'settings' => [
'path' => '/settings', 'path' => '/settings',
@ -259,8 +259,8 @@ $routes = [
'controller' => 'history', 'controller' => 'history',
'path' => '/history/{type}', 'path' => '/history/{type}',
'tokens' => [ 'tokens' => [
'type' => SLUG_PATTERN 'type' => SLUG_PATTERN,
] ],
], ],
'increment' => [ 'increment' => [
'path' => '/{controller}/increment', 'path' => '/{controller}/increment',
@ -316,7 +316,7 @@ $defaultMap = [
foreach ($routes as &$route) foreach ($routes as &$route)
{ {
foreach($defaultMap as $key => $val) foreach ($defaultMap as $key => $val)
{ {
if ( ! array_key_exists($key, $route)) if ( ! array_key_exists($key, $route))
{ {

View File

@ -20,12 +20,10 @@ use Aura\Html\HelperLocatorFactory;
use Aura\Router\RouterContainer; use Aura\Router\RouterContainer;
use Aura\Session\SessionFactory; use Aura\Session\SessionFactory;
use Aviat\AnimeClient\API\{Anilist, Kitsu}; use Aviat\AnimeClient\API\{Anilist, Kitsu};
use Aviat\AnimeClient\Component; use Aviat\AnimeClient\{Component, Model};
use Aviat\AnimeClient\Model;
use Aviat\Banker\Teller; use Aviat\Banker\Teller;
use Aviat\Ion\Config; use Aviat\Ion\Config;
use Aviat\Ion\Di\Container; use Aviat\Ion\Di\{Container, ContainerInterface};
use Aviat\Ion\Di\ContainerInterface;
use Laminas\Diactoros\ServerRequestFactory; use Laminas\Diactoros\ServerRequestFactory;
use Monolog\Formatter\JsonFormatter; use Monolog\Formatter\JsonFormatter;
use Monolog\Handler\RotatingFileHandler; use Monolog\Handler\RotatingFileHandler;
@ -74,18 +72,19 @@ return static function (array $configArray = []): Container {
$container->set('config', static fn () => new Config($configArray)); $container->set('config', static fn () => new Config($configArray));
// Create Cache Object // Create Cache Object
$container->set('cache', static function(ContainerInterface $container): CacheInterface { $container->set('cache', static function (ContainerInterface $container): CacheInterface {
$logger = $container->getLogger(); $logger = $container->getLogger();
$config = $container->get('config')->get('cache'); $config = $container->get('config')->get('cache');
return new Teller($config, $logger); return new Teller($config, $logger);
}); });
// Create Aura Router Object // Create Aura Router Object
$container->set('aura-router', static fn() => new RouterContainer); $container->set('aura-router', static fn () => new RouterContainer());
// Create Html helpers // Create Html helpers
$container->set('html-helper', static function(ContainerInterface $container) { $container->set('html-helper', static function (ContainerInterface $container) {
$htmlHelper = (new HelperLocatorFactory)->newInstance(); $htmlHelper = (new HelperLocatorFactory())->newInstance();
$helpers = [ $helpers = [
'menu' => Helper\Menu::class, 'menu' => Helper\Menu::class,
'field' => Helper\Form::class, 'field' => Helper\Form::class,
@ -94,9 +93,10 @@ return static function (array $configArray = []): Container {
foreach ($helpers as $name => $class) foreach ($helpers as $name => $class)
{ {
$htmlHelper->set($name, static function() use ($class, $container) { $htmlHelper->set($name, static function () use ($class, $container) {
$helper = new $class; $helper = new $class();
$helper->setContainer($container); $helper->setContainer($container);
return $helper; return $helper;
}); });
} }
@ -106,7 +106,7 @@ return static function (array $configArray = []): Container {
// Create Component helpers // Create Component helpers
$container->set('component-helper', static function (ContainerInterface $container) { $container->set('component-helper', static function (ContainerInterface $container) {
$helper = (new HelperLocatorFactory)->newInstance(); $helper = (new HelperLocatorFactory())->newInstance();
$components = [ $components = [
'animeCover' => Component\AnimeCover::class, 'animeCover' => Component\AnimeCover::class,
'mangaCover' => Component\MangaCover::class, 'mangaCover' => Component\MangaCover::class,
@ -119,8 +119,9 @@ return static function (array $configArray = []): Container {
foreach ($components as $name => $componentClass) foreach ($components as $name => $componentClass)
{ {
$helper->set($name, static function () use ($container, $componentClass) { $helper->set($name, static function () use ($container, $componentClass) {
$helper = new $componentClass; $helper = new $componentClass();
$helper->setContainer($container); $helper->setContainer($container);
return $helper; return $helper;
}); });
} }
@ -144,7 +145,7 @@ return static function (array $configArray = []): Container {
$container->set('util', static fn ($container) => new Util($container)); $container->set('util', static fn ($container) => new Util($container));
// Models // Models
$container->set('kitsu-model', static function(ContainerInterface $container): Kitsu\Model { $container->set('kitsu-model', static function (ContainerInterface $container): Kitsu\Model {
$requestBuilder = new Kitsu\RequestBuilder($container); $requestBuilder = new Kitsu\RequestBuilder($container);
$requestBuilder->setLogger($container->getLogger('kitsu-request')); $requestBuilder->setLogger($container->getLogger('kitsu-request'));
@ -158,9 +159,10 @@ return static function (array $configArray = []): Container {
$cache = $container->get('cache'); $cache = $container->get('cache');
$model->setCache($cache); $model->setCache($cache);
return $model; return $model;
}); });
$container->set('anilist-model', static function(ContainerInterface $container): Anilist\Model { $container->set('anilist-model', static function (ContainerInterface $container): Anilist\Model {
$requestBuilder = new Anilist\RequestBuilder($container); $requestBuilder = new Anilist\RequestBuilder($container);
$requestBuilder->setLogger($container->getLogger('anilist-request')); $requestBuilder->setLogger($container->getLogger('anilist-request'));
@ -178,9 +180,10 @@ return static function (array $configArray = []): Container {
$container->set('manga-model', static fn ($container) => new Model\Manga($container)); $container->set('manga-model', static fn ($container) => new Model\Manga($container));
$container->set('anime-collection-model', static fn ($container) => new Model\AnimeCollection($container)); $container->set('anime-collection-model', static fn ($container) => new Model\AnimeCollection($container));
$container->set('manga-collection-model', static fn ($container) => new Model\MangaCollection($container)); $container->set('manga-collection-model', static fn ($container) => new Model\MangaCollection($container));
$container->set('settings-model', static function($container) { $container->set('settings-model', static function ($container) {
$model = new Model\Settings($container->get('config')); $model = new Model\Settings($container->get('config'));
$model->setContainer($container); $model->setContainer($container);
return $model; return $model;
}); });

View File

@ -26,7 +26,7 @@ setlocale(LC_CTYPE, 'en_US');
require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/vendor/autoload.php';
Debugger::$strictMode = E_ALL & ~E_DEPRECATED; // all errors except deprecated notices Debugger::$strictMode = E_ALL & ~E_DEPRECATED; // all errors except deprecated notices
Debugger::$showBar = false; Debugger::$showBar = FALSE;
Debugger::enable(Debugger::DEVELOPMENT, __DIR__ . '/app/logs'); Debugger::enable(Debugger::DEVELOPMENT, __DIR__ . '/app/logs');
// Define base directories // Define base directories
@ -59,7 +59,7 @@ if (is_array($checkedConfig) && array_key_exists('timezone', $checkedConfig) &&
{ {
date_default_timezone_set($checkedConfig['timezone']); date_default_timezone_set($checkedConfig['timezone']);
} }
else if (is_string($timezone) && $timezone !== '') elseif (is_string($timezone) && $timezone !== '')
{ {
date_default_timezone_set($timezone); date_default_timezone_set($timezone);
} }

View File

@ -2,7 +2,8 @@
use Phinx\Migration\AbstractMigration; use Phinx\Migration\AbstractMigration;
class FirstMigration extends AbstractMigration { class FirstMigration extends AbstractMigration
{
/** /**
* Migrate up * Migrate up
*/ */
@ -16,7 +17,7 @@ class FirstMigration extends AbstractMigration {
// Add items to media table // Add items to media table
if ($this->hasTable('media')) if ($this->hasTable('media'))
{ {
foreach(['DVD & Blu-ray', 'Blu-ray', 'DVD', 'Bootleg DVD'] as $type) foreach (['DVD & Blu-ray', 'Blu-ray', 'DVD', 'Bootleg DVD'] as $type)
{ {
$this->execute('INSERT INTO "media" ("type") VALUES (\'' . $type . '\')'); $this->execute('INSERT INTO "media" ("type") VALUES (\'' . $type . '\')');
} }
@ -25,11 +26,11 @@ class FirstMigration extends AbstractMigration {
// Create anime_set table // Create anime_set table
$anime_set = $this->table('anime_set', ['id' => FALSE, 'primary_key' => ['hummingbird_id']]); $anime_set = $this->table('anime_set', ['id' => FALSE, 'primary_key' => ['hummingbird_id']]);
$anime_set->addColumn('hummingbird_id', 'biginteger') $anime_set->addColumn('hummingbird_id', 'biginteger')
->addColumn('slug', 'string', ['comment' => "URL slug used for image caching and generating links"]) ->addColumn('slug', 'string', ['comment' => 'URL slug used for image caching and generating links'])
->addColumn('title', 'string') ->addColumn('title', 'string')
->addColumn('alternate_title', 'string', ['null' => TRUE]) ->addColumn('alternate_title', 'string', ['null' => TRUE])
->addColumn('media_id', 'integer', ['default' => 3, 'null' => TRUE]) ->addColumn('media_id', 'integer', ['default' => 3, 'null' => TRUE])
->addColumn('show_type', 'string', ['default' => 'TV', 'null' => TRUE, 'comment' => "TV Series/OVA/etc"]) ->addColumn('show_type', 'string', ['default' => 'TV', 'null' => TRUE, 'comment' => 'TV Series/OVA/etc'])
->addColumn('age_rating', 'string', ['default' => 'PG13', 'null' => TRUE]) ->addColumn('age_rating', 'string', ['default' => 'PG13', 'null' => TRUE])
->addColumn('cover_image', 'string', ['null' => TRUE]) ->addColumn('cover_image', 'string', ['null' => TRUE])
->addColumn('episode_count', 'integer', ['null' => TRUE]) ->addColumn('episode_count', 'integer', ['null' => TRUE])

View File

@ -1,4 +1,4 @@
<?php <?php declare(strict_types=1);
use Phinx\Migration\AbstractMigration; use Phinx\Migration\AbstractMigration;

View File

@ -1,4 +1,4 @@
<?php <?php declare(strict_types=1);
use Phinx\Migration\AbstractMigration; use Phinx\Migration\AbstractMigration;
@ -11,7 +11,7 @@ class ReorganizeAnimeCollectionMedia extends AbstractMigration
{ {
$newLinkTable = $this->table('anime_set_media_link', [ $newLinkTable = $this->table('anime_set_media_link', [
'id' => FALSE, 'id' => FALSE,
'primary_key' => ['hummingbird_id', 'media_id'] 'primary_key' => ['hummingbird_id', 'media_id'],
]); ]);
$newLinkTable->addColumn('hummingbird_id', 'biginteger') $newLinkTable->addColumn('hummingbird_id', 'biginteger')
@ -31,6 +31,7 @@ class ReorganizeAnimeCollectionMedia extends AbstractMigration
foreach ($rows as $row) foreach ($rows as $row)
{ {
$keys = array_keys($row); $keys = array_keys($row);
foreach ($keys as $k) foreach ($keys as $k)
{ {
if (is_numeric($k)) if (is_numeric($k))
@ -49,6 +50,7 @@ class ReorganizeAnimeCollectionMedia extends AbstractMigration
// and replace those rows with the individual entries // and replace those rows with the individual entries
$linkRows = $this->fetchAll('SELECT hummingbird_id FROM anime_set_media_link WHERE media_id=1'); $linkRows = $this->fetchAll('SELECT hummingbird_id FROM anime_set_media_link WHERE media_id=1');
$insertRows = []; $insertRows = [];
foreach ($linkRows as $row) foreach ($linkRows as $row)
{ {
$insertRows[] = [ $insertRows[] = [

View File

@ -1,4 +1,4 @@
<?php <?php declare(strict_types=1);
use Phinx\Migration\AbstractMigration; use Phinx\Migration\AbstractMigration;
@ -18,6 +18,7 @@ class AnimeCollectionRefactorCleanup extends AbstractMigration
{ {
// Add some new media types // Add some new media types
$moreMediaTypes = []; $moreMediaTypes = [];
foreach ($this->newMediaTypes as $id => $medium) foreach ($this->newMediaTypes as $id => $medium)
{ {
$moreMediaTypes[] = [ $moreMediaTypes[] = [
@ -47,7 +48,7 @@ class AnimeCollectionRefactorCleanup extends AbstractMigration
$this->execute("UPDATE media SET type='Bootleg DVD' WHERE id=4"); $this->execute("UPDATE media SET type='Bootleg DVD' WHERE id=4");
// Remove the new media types // Remove the new media types
$values = array_map(fn ($medium) => "'{$medium}'", $this->newMediaTypes); $values = array_map(static fn ($medium) => "'{$medium}'", $this->newMediaTypes);
$valueList = implode(',', $values); $valueList = implode(',', $values);
$this->execute("DELETE FROM media WHERE type IN ({$valueList})"); $this->execute("DELETE FROM media WHERE type IN ({$valueList})");
} }

View File

@ -1,4 +1,4 @@
<?php <?php declare(strict_types=1);
use Phinx\Migration\AbstractMigration; use Phinx\Migration\AbstractMigration;

View File

@ -2,41 +2,27 @@
use Rector\CodeQuality\Rector\BooleanNot\SimplifyDeMorganBinaryRector; use Rector\CodeQuality\Rector\BooleanNot\SimplifyDeMorganBinaryRector;
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector; use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
use Rector\CodeQuality\Rector\For_\ForRepeatedCountToOwnVariableRector; use Rector\CodeQuality\Rector\For_\{ForRepeatedCountToOwnVariableRector, ForToForeachRector};
use Rector\CodeQuality\Rector\For_\ForToForeachRector; use Rector\CodeQuality\Rector\If_\{ConsecutiveNullCompareReturnsToNullCoalesceQueueRector, SimplifyIfElseToTernaryRector, SimplifyIfReturnBoolRector};
use Rector\CodeQuality\Rector\If_\ConsecutiveNullCompareReturnsToNullCoalesceQueueRector; use Rector\CodeQuality\Rector\Ternary\{SimplifyDuplicatedTernaryRector, SimplifyTautologyTernaryRector, SwitchNegatedTernaryRector};
use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
use Rector\CodeQuality\Rector\Ternary\SimplifyDuplicatedTernaryRector;
use Rector\CodeQuality\Rector\Ternary\SimplifyTautologyTernaryRector;
use Rector\CodeQuality\Rector\Ternary\SwitchNegatedTernaryRector;
use Rector\CodingStyle\Rector\Class_\AddArrayDefaultToArrayPropertyRector; use Rector\CodingStyle\Rector\Class_\AddArrayDefaultToArrayPropertyRector;
use Rector\CodingStyle\Rector\ClassConst\RemoveFinalFromConstRector; use Rector\CodingStyle\Rector\ClassConst\RemoveFinalFromConstRector;
use Rector\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector; use Rector\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector;
use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector; use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
use Rector\CodingStyle\Rector\FuncCall\CallUserFuncArrayToVariadicRector; use Rector\CodingStyle\Rector\FuncCall\{CallUserFuncArrayToVariadicRector, CallUserFuncToMethodCallRector, CountArrayToEmptyArrayComparisonRector};
use Rector\CodingStyle\Rector\FuncCall\CallUserFuncToMethodCallRector;
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector; use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\Core\Configuration\Option; use Rector\Core\Configuration\Option;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector; use Rector\DeadCode\Rector\ClassMethod\{RemoveUselessParamTagRector, RemoveUselessReturnTagRector};
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\DeadCode\Rector\Foreach_\RemoveUnusedForeachKeyRector; use Rector\DeadCode\Rector\Foreach_\RemoveUnusedForeachKeyRector;
use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector; use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector;
use Rector\DeadCode\Rector\Switch_\RemoveDuplicatedCaseInSwitchRector; use Rector\DeadCode\Rector\Switch_\RemoveDuplicatedCaseInSwitchRector;
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector; use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector;
use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector; use Rector\EarlyReturn\Rector\If_\{ChangeIfElseValueAssignToEarlyReturnRector, RemoveAlwaysElseRector};
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector;
use Rector\Php74\Rector\Property\RestoreDefaultNullToNullableTypePropertyRector; use Rector\Php74\Rector\Property\RestoreDefaultNullToNullableTypePropertyRector;
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
use Rector\Restoration\Rector\Property\MakeTypedPropertyNullableIfCheckedRector; use Rector\Restoration\Rector\Property\MakeTypedPropertyNullableIfCheckedRector;
use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\LevelSetList;
use Rector\TypeDeclaration\Rector\ClassMethod\AddArrayParamDocTypeRector; use Rector\TypeDeclaration\Rector\ClassMethod\{AddArrayParamDocTypeRector, AddArrayReturnDocTypeRector, AddMethodCallBasedStrictParamTypeRector, ParamTypeByMethodCallTypeRector, ParamTypeByParentCallTypeRector};
use Rector\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector;
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByParentCallTypeRector;
use Rector\TypeDeclaration\Rector\Closure\AddClosureReturnTypeRector; use Rector\TypeDeclaration\Rector\Closure\AddClosureReturnTypeRector;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector; use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
@ -45,7 +31,8 @@ if ( ! function_exists('walk_array'))
{ {
function walk_array(callable $method, array $items): void function walk_array(callable $method, array $items): void
{ {
foreach ($items as $item) { foreach ($items as $item)
{
$method($item); $method($item);
} }
} }
@ -53,8 +40,8 @@ if ( ! function_exists('walk_array'))
return static function (ContainerConfigurator $config): void { return static function (ContainerConfigurator $config): void {
$parameters = $config->parameters(); $parameters = $config->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, false); $parameters->set(Option::AUTO_IMPORT_NAMES, FALSE);
$parameters->set(Option::IMPORT_SHORT_CLASSES, false); $parameters->set(Option::IMPORT_SHORT_CLASSES, FALSE);
$parameters->set(Option::SKIP, [ $parameters->set(Option::SKIP, [
ReadOnlyPropertyRector::class, ReadOnlyPropertyRector::class,
RestoreDefaultNullToNullableTypePropertyRector::class, RestoreDefaultNullToNullableTypePropertyRector::class,