A code clean up commit.
This commit is contained in:
@@ -51,7 +51,7 @@ if (!file_exists(__DIR__ . '/../vendor/autoload.php')) {
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
try {
|
||||
$app = (new App\Libs\Initializer())->boot();
|
||||
$app = new App\Libs\Initializer()->boot();
|
||||
} catch (Throwable $e) {
|
||||
$message = strtr(
|
||||
'CLI: Exception [{kind}] was thrown unhandled during CLI boot context. Error [{message} @ {file}:{line}].',
|
||||
|
||||
@@ -247,7 +247,7 @@ return (function () {
|
||||
|
||||
$checkTaskTimer = function (string $timer, string $default): string {
|
||||
try {
|
||||
$isValid = (new CronExpression($timer))->getNextRunDate()->getTimestamp() >= 0;
|
||||
$isValid = new CronExpression($timer)->getNextRunDate()->getTimestamp() >= 0;
|
||||
return $isValid ? $timer : $default;
|
||||
} catch (Throwable) {
|
||||
return $default;
|
||||
|
||||
@@ -183,7 +183,7 @@ return (function () {
|
||||
$value = substr($value, 1, -1);
|
||||
}
|
||||
|
||||
$status = (new CronExpression($value))->getNextRunDate()->getTimestamp() >= 0;
|
||||
$status = new CronExpression($value)->getNextRunDate()->getTimestamp() >= 0;
|
||||
|
||||
if (!$status) {
|
||||
throw new ValidationException('Invalid cron expression. The next run date is in the past.');
|
||||
|
||||
@@ -239,7 +239,7 @@ return (function (): array {
|
||||
|
||||
MemoryMapper::class => [
|
||||
'class' => function (iLogger $logger, iDB $db, CacheInterface $cache): iImport {
|
||||
return (new MemoryMapper(logger: $logger, db: $db, cache: $cache))
|
||||
return new MemoryMapper(logger: $logger, db: $db, cache: $cache)
|
||||
->setOptions(options: Config::get('mapper.import.opts', []));
|
||||
},
|
||||
'args' => [
|
||||
@@ -251,7 +251,7 @@ return (function (): array {
|
||||
|
||||
DirectMapper::class => [
|
||||
'class' => function (iLogger $logger, iDB $db, CacheInterface $cache): iImport {
|
||||
return (new DirectMapper(logger: $logger, db: $db, cache: $cache))
|
||||
return new DirectMapper(logger: $logger, db: $db, cache: $cache)
|
||||
->setOptions(options: Config::get('mapper.import.opts', []));
|
||||
},
|
||||
'args' => [
|
||||
|
||||
@@ -57,7 +57,7 @@ try {
|
||||
$_SERVER['X_REQUEST_ID'] = bin2hex(random_bytes(16));
|
||||
}
|
||||
|
||||
$app = (new App\Libs\Initializer())->boot();
|
||||
$app = new App\Libs\Initializer()->boot();
|
||||
} catch (Throwable $e) {
|
||||
$out = fn($message) => inContainer() ? fwrite(STDERR, $message) : syslog(LOG_ERR, $message);
|
||||
|
||||
@@ -81,7 +81,7 @@ try {
|
||||
}
|
||||
|
||||
try {
|
||||
(new Emitter())($app->http());
|
||||
new Emitter()($app->http());
|
||||
} catch (Throwable $e) {
|
||||
$out = fn($message) => inContainer() ? fwrite(STDERR, $message) : syslog(LOG_ERR, $message);
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@ final class Ignore
|
||||
}
|
||||
|
||||
#[Get(Index::URL . '/{name:backend}/ignore[/]', name: 'backend.ignoredIds')]
|
||||
public function ignoredIds(iRequest $request, array $args = []): iResponse
|
||||
public function ignoredIds(string $name): iResponse
|
||||
{
|
||||
if (null === ($name = ag($args, 'name'))) {
|
||||
if (empty($name)) {
|
||||
return api_error('Invalid value for name path parameter.', Status::BAD_REQUEST);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ final class Library
|
||||
use APITraits;
|
||||
|
||||
#[Get(BackendsIndex::URL . '/{name:backend}/library[/]', name: 'backend.library')]
|
||||
public function listLibraries(iRequest $request, array $args = []): iResponse
|
||||
public function listLibraries(string $name): iResponse
|
||||
{
|
||||
if (null === ($name = ag($args, 'name'))) {
|
||||
if (empty($name)) {
|
||||
return api_error('Invalid value for name path parameter.', Status::BAD_REQUEST);
|
||||
}
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ final class Index
|
||||
|
||||
private function download(string $filePath): iResponse
|
||||
{
|
||||
$mime = (new finfo(FILEINFO_MIME_TYPE))->file($filePath);
|
||||
$mime = new finfo(FILEINFO_MIME_TYPE)->file($filePath);
|
||||
|
||||
return api_response(Status::OK, Stream::make($filePath, 'r'), headers: [
|
||||
'Content-Type' => false === $mime ? 'application/octet-stream' : $mime,
|
||||
|
||||
@@ -68,7 +68,7 @@ final class Backup
|
||||
return api_response(Status::OK);
|
||||
}
|
||||
|
||||
$mime = (new finfo(FILEINFO_MIME_TYPE))->file($filePath);
|
||||
$mime = new finfo(FILEINFO_MIME_TYPE)->file($filePath);
|
||||
|
||||
return api_response(Status::OK, Stream::make($filePath, 'r'), headers: [
|
||||
'Content-Type' => false === $mime ? 'application/octet-stream' : $mime,
|
||||
|
||||
@@ -64,9 +64,8 @@ final class Env
|
||||
}
|
||||
|
||||
#[Get(self::URL . '/{key}[/]', name: 'system.env.view')]
|
||||
public function envView(iRequest $request, array $args = []): iResponse
|
||||
public function envView(string $key): iResponse
|
||||
{
|
||||
$key = strtoupper((string)ag($args, 'key', ''));
|
||||
if (empty($key)) {
|
||||
return api_error('Invalid value for key path parameter.', Status::BAD_REQUEST);
|
||||
}
|
||||
|
||||
@@ -254,13 +254,19 @@ final class Guids
|
||||
]), Status::BAD_REQUEST);
|
||||
}
|
||||
|
||||
foreach (ag($this->getData(), 'links', []) as $link) {
|
||||
if ($link['type'] === $client && $link['map']['from'] === $params->get('map.from')) {
|
||||
return api_error(r("The client '{client}' map.from '{from}' is already exists.", [
|
||||
$exists = array_any(
|
||||
ag($this->getData(), 'links', []),
|
||||
fn($link) => $link['type'] === $client && $link['map']['from'] === $params->get('map.from')
|
||||
);
|
||||
|
||||
if (true === $exists) {
|
||||
return api_error(
|
||||
r("The client '{client}' map.from '{from}' is already exists.", [
|
||||
'client' => $client,
|
||||
'from' => $params->get('map.from')
|
||||
]), Status::BAD_REQUEST);
|
||||
}
|
||||
]),
|
||||
Status::BAD_REQUEST
|
||||
);
|
||||
}
|
||||
|
||||
$link = [
|
||||
|
||||
@@ -31,9 +31,6 @@ final class Integrity
|
||||
|
||||
private bool $fromCache = false;
|
||||
|
||||
/**
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct(private readonly iCache $cache)
|
||||
{
|
||||
set_time_limit(0);
|
||||
|
||||
@@ -12,7 +12,6 @@ use App\Libs\Enums\Http\Status;
|
||||
use App\Libs\Traits\APITraits;
|
||||
use Psr\Http\Message\ResponseInterface as iResponse;
|
||||
use Psr\Http\Message\ServerRequestInterface as iRequest;
|
||||
use Psr\SimpleCache\InvalidArgumentException;
|
||||
|
||||
final class Parity
|
||||
{
|
||||
@@ -25,7 +24,6 @@ final class Parity
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
#[Get(self::URL . '[/]', name: 'system.parity')]
|
||||
public function __invoke(iRequest $request): iResponse
|
||||
@@ -107,7 +105,6 @@ final class Parity
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
#[Delete(self::URL . '[/]', name: 'system.parity.delete')]
|
||||
public function deleteRecords(iRequest $request): iResponse
|
||||
|
||||
@@ -128,9 +128,9 @@ final class Suppressor
|
||||
}
|
||||
|
||||
#[Delete(self::URL . '/{id:\w{11}}[/]', name: 'system.suppressor.delete')]
|
||||
public function deleteSuppressor(iRequest $request, array $args = []): iResponse
|
||||
public function deleteSuppressor(string $id): iResponse
|
||||
{
|
||||
if (null === ($id = ag($args, 'id')) || empty($id)) {
|
||||
if (empty($id)) {
|
||||
return api_error('Invalid suppressor id.', Status::BAD_REQUEST);
|
||||
}
|
||||
|
||||
@@ -144,9 +144,9 @@ final class Suppressor
|
||||
}
|
||||
|
||||
#[Get(self::URL . '/{id:\w{11}}[/]', name: 'system.suppressor.view')]
|
||||
public function viewSuppressor(iRequest $request, array $args = []): iResponse
|
||||
public function viewSuppressor(string $id): iResponse
|
||||
{
|
||||
if (null === ($id = ag($args, 'id')) || empty($id)) {
|
||||
if (empty($id)) {
|
||||
return api_error('Invalid suppressor id.', Status::BAD_REQUEST);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ use App\Model\Events\EventStatus;
|
||||
use Cron\CronExpression;
|
||||
use Psr\Http\Message\ResponseInterface as iResponse;
|
||||
use Psr\Http\Message\ServerRequestInterface as iRequest;
|
||||
use Psr\SimpleCache\InvalidArgumentException;
|
||||
|
||||
final class Tasks
|
||||
{
|
||||
@@ -25,9 +24,6 @@ final class Tasks
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
#[Get(self::URL . '[/]', name: 'tasks.index')]
|
||||
public function tasksIndex(): iResponse
|
||||
{
|
||||
@@ -55,9 +51,6 @@ final class Tasks
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
#[Route(['GET', 'POST', 'DELETE'], self::URL . '/{id:[a-zA-Z0-9_-]+}/queue[/]', name: 'tasks.task.queue')]
|
||||
public function taskQueue(iRequest $request, string $id): iResponse
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Backends\Common;
|
||||
|
||||
final class Response
|
||||
final readonly class Response
|
||||
{
|
||||
/**
|
||||
* Wrap clients responses into easy to consume object.
|
||||
@@ -15,10 +15,10 @@ final class Response
|
||||
* @param mixed $extra An array that can contain anything. Should be rarely used.
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly bool $status,
|
||||
public readonly mixed $response = null,
|
||||
public readonly Error|null $error = null,
|
||||
public readonly array $extra = [],
|
||||
public bool $status,
|
||||
public mixed $response = null,
|
||||
public Error|null $error = null,
|
||||
public array $extra = [],
|
||||
) {
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ class GetIdentifier
|
||||
return $this->tryResponse(
|
||||
context: $context,
|
||||
fn: function () use ($context, $opts) {
|
||||
$info = (new GetInfo($this->http, $this->logger, $this->cache))(context: $context, opts: $opts);
|
||||
$info = new GetInfo($this->http, $this->logger, $this->cache)(context: $context, opts: $opts);
|
||||
|
||||
if (false === $info->status) {
|
||||
return $info;
|
||||
|
||||
@@ -52,7 +52,7 @@ class GetVersion
|
||||
return $this->tryResponse(
|
||||
context: $context,
|
||||
fn: function () use ($context, $opts) {
|
||||
$info = (new GetInfo($this->http, $this->logger, $this->cache))(context: $context, opts: $opts);
|
||||
$info = new GetInfo($this->http, $this->logger, $this->cache)(context: $context, opts: $opts);
|
||||
|
||||
if (false === $info->status) {
|
||||
return $info;
|
||||
|
||||
@@ -13,7 +13,6 @@ use App\Backends\Jellyfin\JellyfinActionTrait;
|
||||
use App\Backends\Jellyfin\JellyfinClient;
|
||||
use App\Backends\Jellyfin\JellyfinGuid;
|
||||
use App\Libs\Database\DatabaseInterface as iDB;
|
||||
use App\Libs\Exceptions\Backends\RuntimeException;
|
||||
use App\Libs\Options;
|
||||
use JsonException;
|
||||
use Psr\Log\LoggerInterface as iLogger;
|
||||
@@ -72,7 +71,6 @@ class SearchQuery
|
||||
*
|
||||
* @throws ExceptionInterface When the request fails.
|
||||
* @throws JsonException When the response is not valid JSON.
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
private function search(Context $context, string $query, int $limit = 25, array $opts = []): Response
|
||||
{
|
||||
|
||||
@@ -37,7 +37,7 @@ final class GetIdentifier
|
||||
return $this->tryResponse(
|
||||
context: $context,
|
||||
fn: function () use ($context, $opts) {
|
||||
$info = (new GetInfo($this->http, $this->logger, $this->cache))(context: $context, opts: $opts);
|
||||
$info = new GetInfo($this->http, $this->logger, $this->cache)(context: $context, opts: $opts);
|
||||
|
||||
if (false === $info->status) {
|
||||
return $info;
|
||||
|
||||
@@ -37,7 +37,7 @@ final class GetVersion
|
||||
return $this->tryResponse(
|
||||
context: $context,
|
||||
fn: function () use ($context, $opts) {
|
||||
$info = (new GetInfo($this->http, $this->logger, $this->cache))(context: $context, opts: $opts);
|
||||
$info = new GetInfo($this->http, $this->logger, $this->cache)(context: $context, opts: $opts);
|
||||
|
||||
if (false === $info->status) {
|
||||
return $info;
|
||||
|
||||
@@ -12,7 +12,6 @@ use App\Backends\Common\Response;
|
||||
use App\Backends\Plex\PlexActionTrait;
|
||||
use App\Backends\Plex\PlexGuid;
|
||||
use App\Libs\Database\DatabaseInterface as iDB;
|
||||
use App\Libs\Exceptions\Backends\RuntimeException;
|
||||
use App\Libs\Options;
|
||||
use JsonException;
|
||||
use Psr\Log\LoggerInterface as iLogger;
|
||||
@@ -58,7 +57,6 @@ final class SearchQuery
|
||||
*
|
||||
* @throws ExceptionInterface if the request failed
|
||||
* @throws JsonException if the response cannot be parsed
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
private function search(Context $context, string $query, int $limit = 25, array $opts = []): Response
|
||||
{
|
||||
|
||||
@@ -22,7 +22,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface as iHttp;
|
||||
#[Cli(command: self::ROUTE)]
|
||||
final class DiscoverCommand extends Command
|
||||
{
|
||||
public const ROUTE = 'plex:discover';
|
||||
public const string ROUTE = 'plex:discover';
|
||||
|
||||
public function __construct(private iHttp $http, protected iLogger $logger)
|
||||
{
|
||||
|
||||
@@ -270,7 +270,7 @@ class Command extends BaseCommand
|
||||
|
||||
if (!empty($list)) {
|
||||
array_pop($list);
|
||||
(new Table($output))
|
||||
new Table($output)
|
||||
->setStyle(name: 'box')
|
||||
->setHeaders(
|
||||
array_map(
|
||||
|
||||
@@ -22,7 +22,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
#[Cli(command: self::ROUTE)]
|
||||
class InfoCommand extends Command
|
||||
{
|
||||
public const ROUTE = 'backend:info';
|
||||
public const string ROUTE = 'backend:info';
|
||||
|
||||
/**
|
||||
* Configures the command.
|
||||
|
||||
@@ -24,7 +24,7 @@ use Symfony\Component\Console\Question\ConfirmationQuestion;
|
||||
#[Cli(command: self::ROUTE)]
|
||||
final class IgnoreCommand extends Command
|
||||
{
|
||||
public const ROUTE = 'backend:library:ignore';
|
||||
public const string ROUTE = 'backend:library:ignore';
|
||||
|
||||
public function __construct(private LoggerInterface $logger)
|
||||
{
|
||||
|
||||
@@ -20,7 +20,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
#[Cli(command: self::ROUTE)]
|
||||
final class ListCommand extends Command
|
||||
{
|
||||
public const ROUTE = 'backend:library:list';
|
||||
public const string ROUTE = 'backend:library:list';
|
||||
|
||||
/**
|
||||
* Configures the command.
|
||||
|
||||
@@ -29,7 +29,7 @@ use Throwable;
|
||||
#[Cli(command: self::ROUTE)]
|
||||
class RestoreCommand extends Command
|
||||
{
|
||||
public const ROUTE = 'backend:restore';
|
||||
public const string ROUTE = 'backend:restore';
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
@@ -213,7 +213,7 @@ class RestoreCommand extends Command
|
||||
],
|
||||
]);
|
||||
|
||||
$mapper = (new RestoreMapper($this->logger, $file))->loadData();
|
||||
$mapper = new RestoreMapper($this->logger, $file)->loadData();
|
||||
|
||||
$this->logger->notice('SYSTEM: Loading restore data is complete.', [
|
||||
'memory' => [
|
||||
|
||||
@@ -21,9 +21,9 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
#[Cli(command: self::ROUTE)]
|
||||
final class SessionsCommand extends Command
|
||||
{
|
||||
public const ROUTE = 'backend:users:sessions';
|
||||
public const string ROUTE = 'backend:users:sessions';
|
||||
|
||||
private const REMAP_FIELDS = [
|
||||
private const array REMAP_FIELDS = [
|
||||
'user_name' => 'User',
|
||||
'item_title' => 'Title',
|
||||
'item_type' => 'Type',
|
||||
|
||||
@@ -19,7 +19,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
#[Cli(command: self::ROUTE)]
|
||||
class VersionCommand extends Command
|
||||
{
|
||||
public const ROUTE = 'backend:version';
|
||||
public const string ROUTE = 'backend:version';
|
||||
|
||||
/**
|
||||
* Configures the command.
|
||||
|
||||
@@ -137,7 +137,7 @@ final class AddCommand extends Command
|
||||
return $answer;
|
||||
});
|
||||
|
||||
return (new QuestionHelper())->ask($input, $output, $question);
|
||||
return new QuestionHelper()->ask($input, $output, $question);
|
||||
})();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
#[Cli(command: self::ROUTE)]
|
||||
final class ListCommand extends Command
|
||||
{
|
||||
public const ROUTE = 'config:list';
|
||||
public const string ROUTE = 'config:list';
|
||||
|
||||
/**
|
||||
* Configures the command.
|
||||
|
||||
@@ -151,7 +151,7 @@ final class ViewCommand extends Command
|
||||
$mode = $input->getOption('output');
|
||||
|
||||
if ('table' === $mode) {
|
||||
(new Table($output))->setStyle('box')
|
||||
new Table($output)->setStyle('box')
|
||||
->setHeaders(['Backend', 'Data (Filter: ' . (empty($filter) ? 'None' : $filter) . ')']
|
||||
)->setRows($rows)
|
||||
->render();
|
||||
|
||||
@@ -10,6 +10,7 @@ use App\Libs\Container;
|
||||
use App\Libs\Database\DatabaseInterface as iDB;
|
||||
use App\Libs\Entity\StateInterface as iState;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
use Psr\SimpleCache\InvalidArgumentException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
@@ -24,7 +25,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
#[Cli(command: self::ROUTE)]
|
||||
class QueueCommand extends Command
|
||||
{
|
||||
public const ROUTE = 'db:queue';
|
||||
public const string ROUTE = 'db:queue';
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
@@ -73,7 +74,7 @@ class QueueCommand extends Command
|
||||
* @param OutputInterface $output The output object.
|
||||
*
|
||||
* @return int The command's exit code.
|
||||
* @throws \Psr\Cache\InvalidArgumentException If the cache key is invalid.
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function runCommand(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
@@ -81,7 +82,7 @@ class QueueCommand extends Command
|
||||
$item = Container::get(iState::class)::fromArray(['id' => $id]);
|
||||
|
||||
if (null === ($item = $this->db->get($item))) {
|
||||
$output->writeln(sprintf('<error>Record id \'%d\' does not exists.</error>', $id));
|
||||
$output->writeln(r("<error>Record id '{id}' does not exist.</error>", ['id' => $id]));
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
@@ -99,7 +100,7 @@ class QueueCommand extends Command
|
||||
|
||||
if (null !== ($id = $input->getOption('remove'))) {
|
||||
if (!array_key_exists($id, $queue)) {
|
||||
$output->writeln(sprintf('<error>Record id \'%d\' does not exists in the queue.</error>', $id));
|
||||
$output->writeln(r("<error>Record id '{id}' does not exist in the queue.</error>", ['id' => $id]));
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
|
||||
@@ -521,7 +521,7 @@ class ImportCommand extends Command
|
||||
],
|
||||
];
|
||||
|
||||
(new Table($output))->setHeaders(array_keys($a[0]))->setStyle('box')->setRows(array_values($a))->render();
|
||||
new Table($output)->setHeaders(array_keys($a[0]))->setStyle('box')->setRows(array_values($a))->render();
|
||||
|
||||
if (false === $input->getOption('dry-run')) {
|
||||
$configFile->persist();
|
||||
|
||||
@@ -317,7 +317,7 @@ final class LogsCommand extends Command
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
if (!$input->getOption('no-interaction')) {
|
||||
if (false === $input->getOption('no-interaction')) {
|
||||
if (function_exists('stream_isatty') && defined('STDERR')) {
|
||||
$tty = stream_isatty(STDERR);
|
||||
} else {
|
||||
@@ -325,12 +325,9 @@ final class LogsCommand extends Command
|
||||
}
|
||||
|
||||
if (false === $tty) {
|
||||
$output->writeln('<error>ERROR: This command flag require interaction.</error>');
|
||||
$output->writeln('<error>ERROR: no interactive session found.</error>');
|
||||
$output->writeln(
|
||||
'<comment>If you are running this tool inside docker, you have to enable interaction using "-ti" flag</comment>'
|
||||
);
|
||||
$output->writeln(
|
||||
'<comment>For example: docker exec -ti watchstate console config:manage my_server</comment>'
|
||||
'<comment>to clear log without interactive session, pass</comment> [<flag>-n, --no-interaction</flag>] flag.'
|
||||
);
|
||||
return self::FAILURE;
|
||||
}
|
||||
@@ -343,12 +340,12 @@ final class LogsCommand extends Command
|
||||
),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
$confirmClear = $this->getHelper('question')->ask($input, $output, $question);
|
||||
$confirmClear = $this->getHelper('question')->ask($input, $output, $question);
|
||||
|
||||
if (true !== (bool)$confirmClear) {
|
||||
return self::SUCCESS;
|
||||
if (true !== (bool)$confirmClear) {
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
$file->openFile('w');
|
||||
|
||||
@@ -18,7 +18,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
#[Cli(command: self::ROUTE)]
|
||||
final class MaintenanceCommand extends Command
|
||||
{
|
||||
public const ROUTE = 'system:db:maintenance';
|
||||
public const string ROUTE = 'system:db:maintenance';
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
|
||||
@@ -19,7 +19,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
#[Cli(command: self::ROUTE)]
|
||||
final class MakeCommand extends Command
|
||||
{
|
||||
public const ROUTE = 'system:db:make';
|
||||
public const string ROUTE = 'system:db:make';
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
|
||||
@@ -19,7 +19,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
#[Cli(command: self::ROUTE)]
|
||||
final class MigrationsCommand extends Command
|
||||
{
|
||||
public const ROUTE = 'system:db:migrations';
|
||||
public const string ROUTE = 'system:db:migrations';
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
|
||||
@@ -20,7 +20,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
#[Cli(command: self::ROUTE)]
|
||||
final class PHPCommand extends Command
|
||||
{
|
||||
public const ROUTE = 'system:php';
|
||||
public const string ROUTE = 'system:php';
|
||||
|
||||
/**
|
||||
* Configures the command.
|
||||
|
||||
@@ -187,7 +187,7 @@ final class PruneCommand extends Command
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
private function cleanUp()
|
||||
private function cleanUp(): void
|
||||
{
|
||||
$before = makeDate(strtotime('-7 DAYS'));
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ final class ReportCommand extends Command
|
||||
$this->getBackends($input, $output);
|
||||
|
||||
$output->writeln(PHP_EOL . '<info>[ Log suppression ]</info>' . PHP_EOL);
|
||||
$this->getSuppressor($input, $output);
|
||||
$this->getSuppressor($output);
|
||||
|
||||
$output->writeln('<info>[ Tasks ]</info>' . PHP_EOL);
|
||||
$this->getTasks($output);
|
||||
@@ -419,7 +419,7 @@ final class ReportCommand extends Command
|
||||
);
|
||||
}
|
||||
|
||||
private function getSuppressor(iInput $input, ConsoleOutput $output): void
|
||||
private function getSuppressor(ConsoleOutput $output): void
|
||||
{
|
||||
$suppressFile = Config::get('path') . '/config/suppress.yaml';
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace App\Commands\System;
|
||||
use App\Command;
|
||||
use App\Libs\Attributes\Route\Cli;
|
||||
use Psr\SimpleCache\CacheInterface as iCache;
|
||||
use Psr\SimpleCache\InvalidArgumentException;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Helper\TableSeparator;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
@@ -52,6 +53,7 @@ final class RoutesCommand extends Command
|
||||
* @param OutputInterface $output The output interface object.
|
||||
*
|
||||
* @return int The exit code of the command execution.
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function runCommand(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
@@ -63,6 +65,9 @@ final class RoutesCommand extends Command
|
||||
return $this->showHttp($input, $output);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function showHttp(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$list = [];
|
||||
|
||||
@@ -21,7 +21,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
#[Cli(command: self::ROUTE)]
|
||||
final class ServerCommand extends Command
|
||||
{
|
||||
public const ROUTE = 'system:server';
|
||||
public const string ROUTE = 'system:server';
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
|
||||
@@ -22,7 +22,7 @@ use Symfony\Component\Console\Output\OutputInterface as iOutput;
|
||||
#[Cli(command: self::ROUTE)]
|
||||
final class TinkerCommand extends Command
|
||||
{
|
||||
public const ROUTE = 'system:tinker';
|
||||
public const string ROUTE = 'system:tinker';
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
|
||||
@@ -949,7 +949,7 @@ final class DBLayer implements LoggerAwareInterface
|
||||
$attempts = (int)ag($options, 'attempts', 0);
|
||||
if (true === str_contains(strtolower($e->getMessage()), 'database is locked')) {
|
||||
if ($attempts >= $this->retry) {
|
||||
throw (new DBLayerException($e->getMessage(), (int)$e->getCode(), $e))
|
||||
throw new DBLayerException($e->getMessage(), (int)$e->getCode(), $e)
|
||||
->setFile($e->getFile())
|
||||
->setLine($e->getLine());
|
||||
}
|
||||
@@ -983,7 +983,7 @@ final class DBLayer implements LoggerAwareInterface
|
||||
throw $e;
|
||||
}
|
||||
|
||||
throw (new DBLayerException($e->getMessage(), (int)$e->getCode(), $e))
|
||||
throw new DBLayerException($e->getMessage(), (int)$e->getCode(), $e)
|
||||
->setInfo($this->last['sql'], $this->last['bind'], $e->errorInfo ?? [], $e->getCode())
|
||||
->setFile($e->getFile())
|
||||
->setLine($e->getLine());
|
||||
|
||||
@@ -516,7 +516,7 @@ final class PDOAdapter implements iDB
|
||||
*/
|
||||
public function ensureIndex(array $opts = []): mixed
|
||||
{
|
||||
return (new PDOIndexer($this->db, $this->logger))->ensureIndex($opts);
|
||||
return new PDOIndexer($this->db, $this->logger)->ensureIndex($opts);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -524,7 +524,7 @@ final class PDOAdapter implements iDB
|
||||
*/
|
||||
public function migrateData(string $version, iLogger|null $logger = null): mixed
|
||||
{
|
||||
return (new PDODataMigration($this->db, $logger ?? $this->logger))->automatic();
|
||||
return new PDODataMigration($this->db, $logger ?? $this->logger)->automatic();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -532,7 +532,7 @@ final class PDOAdapter implements iDB
|
||||
*/
|
||||
public function isMigrated(): bool
|
||||
{
|
||||
return (new PDOMigrations($this->db, $this->logger))->isMigrated();
|
||||
return new PDOMigrations($this->db, $this->logger)->isMigrated();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -540,7 +540,7 @@ final class PDOAdapter implements iDB
|
||||
*/
|
||||
public function makeMigration(string $name, array $opts = []): mixed
|
||||
{
|
||||
return (new PDOMigrations($this->db, $this->logger))->make($name);
|
||||
return new PDOMigrations($this->db, $this->logger)->make($name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -548,7 +548,7 @@ final class PDOAdapter implements iDB
|
||||
*/
|
||||
public function maintenance(array $opts = []): mixed
|
||||
{
|
||||
return (new PDOMigrations($this->db, $this->logger))->runMaintenance();
|
||||
return new PDOMigrations($this->db, $this->logger)->runMaintenance();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -352,11 +352,7 @@ final class StateEntity implements iState
|
||||
return [];
|
||||
}
|
||||
|
||||
$list = [];
|
||||
|
||||
foreach ($this->parent as $key => $val) {
|
||||
$list[$key] = $val . '/' . $this->season . '/' . $this->episode;
|
||||
}
|
||||
$list = array_map(fn($val) => $val . '/' . $this->season . '/' . $this->episode, $this->parent);
|
||||
|
||||
return array_intersect_key($list, Guid::getSupported());
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ final class Initializer
|
||||
{
|
||||
if (null === $request) {
|
||||
$factory = new Psr17Factory();
|
||||
$request = (new ServerRequestCreator($factory, $factory, $factory, $factory))->fromGlobals();
|
||||
$request = new ServerRequestCreator($factory, $factory, $factory, $factory)->fromGlobals();
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -318,7 +318,7 @@ final class Initializer
|
||||
return $response;
|
||||
}
|
||||
|
||||
return (new ServeStatic())->serve($request)->withHeader('Access-Control-Allow-Origin', '*')
|
||||
return new ServeStatic()->serve($request)->withHeader('Access-Control-Allow-Origin', '*')
|
||||
->withHeader('Access-Control-Allow-Credentials', 'true');
|
||||
}
|
||||
|
||||
@@ -629,7 +629,7 @@ final class Initializer
|
||||
$refer = '-';
|
||||
|
||||
if (true === ag_exists($request->getServerParams(), 'HTTP_REFERER')) {
|
||||
$refer = (new Uri(ag($request->getServerParams(), 'HTTP_REFERER')))
|
||||
$refer = new Uri(ag($request->getServerParams(), 'HTTP_REFERER'))
|
||||
->withQuery('')->withFragment('')->withUserInfo('');
|
||||
}
|
||||
|
||||
|
||||
@@ -66,10 +66,8 @@ final class APIKeyRequiredMiddleware implements MiddlewareInterface
|
||||
return api_error('API key is required to access the API.', Status::BAD_REQUEST);
|
||||
}
|
||||
|
||||
foreach ($tokens as $token) {
|
||||
if (true === $this->validate($token)) {
|
||||
return $handler->handle($request);
|
||||
}
|
||||
if (array_any($tokens, fn($token) => true === $this->validate($token))) {
|
||||
return $handler->handle($request);
|
||||
}
|
||||
|
||||
return api_error('incorrect API key.', Status::FORBIDDEN);
|
||||
|
||||
@@ -55,7 +55,7 @@ final class Server
|
||||
self::CONFIG_PORT => 8080,
|
||||
self::CONFIG_ROUTER => null,
|
||||
self::CONFIG_ROOT => realpath(__DIR__ . '/../../public'),
|
||||
self::CONFIG_PHP => $classExists ? (new PhpExecutableFinder())->find(false) : PHP_BINARY,
|
||||
self::CONFIG_PHP => $classExists ? new PhpExecutableFinder()->find(false) : PHP_BINARY,
|
||||
self::CONFIG_ENV => array_replace_recursive($_ENV, getenv()),
|
||||
self::CONFIG_THREADS => 1,
|
||||
];
|
||||
|
||||
@@ -390,7 +390,11 @@ final class Stream implements StreamInterface, Stringable, LoggerAwareInterface
|
||||
return in_array(get_resource_type($resource), self::ALLOWED_RESOURCE_TYPES, true);
|
||||
}
|
||||
|
||||
if (extension_loaded('gd') && true === ($resource instanceof \GdImage)) {
|
||||
if (!extension_loaded('gd')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (true === ($resource instanceof \GdImage)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ final readonly class StreamedBody implements StreamInterface
|
||||
{
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->getContents();
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ if (!function_exists('makeDate')) {
|
||||
$date = $date->format(DateTimeInterface::ATOM);
|
||||
}
|
||||
|
||||
return (new Date($date))->setTimezone($tz);
|
||||
return new Date($date)->setTimezone($tz);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -886,7 +886,7 @@ if (false === function_exists('makeIgnoreId')) {
|
||||
};
|
||||
}
|
||||
|
||||
$id = (new Uri($url))->withPath('')->withFragment('')->withPort(null);
|
||||
$id = new Uri($url)->withPath('')->withFragment('')->withPort(null);
|
||||
return $id->withQuery($filterQuery($id->getQuery()));
|
||||
}
|
||||
}
|
||||
@@ -1664,7 +1664,7 @@ if (!function_exists('isTaskWorkerRunning')) {
|
||||
}
|
||||
|
||||
try {
|
||||
$pid = trim((string)(new Stream($pidFile)));
|
||||
$pid = trim((string)new Stream($pidFile));
|
||||
} catch (Throwable $e) {
|
||||
return ['status' => false, 'message' => $e->getMessage()];
|
||||
}
|
||||
@@ -1732,7 +1732,7 @@ if (!function_exists('restartTaskWorker')) {
|
||||
|
||||
if (true === file_exists($pidFile)) {
|
||||
try {
|
||||
$pid = trim((string)(new Stream($pidFile)));
|
||||
$pid = trim((string)new Stream($pidFile));
|
||||
} catch (Throwable $e) {
|
||||
return ['status' => false, 'restartable' => true, 'message' => $e->getMessage()];
|
||||
}
|
||||
@@ -1833,7 +1833,7 @@ if (!function_exists('getMimeType')) {
|
||||
if (!function_exists('getExtension')) {
|
||||
function getExtension(string $filename): string
|
||||
{
|
||||
return (new SplFileInfo($filename))->getExtension();
|
||||
return new SplFileInfo($filename)->getExtension();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ abstract class BasicModel implements jsonSerializable
|
||||
{
|
||||
$props = [];
|
||||
|
||||
$reflect = (new ReflectionObject($this))->getProperties(ReflectionProperty::IS_PUBLIC);
|
||||
$reflect = new ReflectionObject($this)->getProperties(ReflectionProperty::IS_PUBLIC);
|
||||
|
||||
foreach ($reflect as $src) {
|
||||
$value = $src->getValue($this);
|
||||
@@ -204,7 +204,7 @@ abstract class BasicModel implements jsonSerializable
|
||||
|
||||
self::$_props[$className] = [];
|
||||
|
||||
$reflect = (new ReflectionObject($this))->getProperties(ReflectionProperty::IS_PUBLIC);
|
||||
$reflect = new ReflectionObject($this)->getProperties(ReflectionProperty::IS_PUBLIC);
|
||||
|
||||
foreach ($reflect as $src) {
|
||||
$prop = $src->getType();
|
||||
@@ -264,7 +264,7 @@ abstract class BasicModel implements jsonSerializable
|
||||
|
||||
self::$_columns[$className] = [];
|
||||
|
||||
foreach ((new ReflectionObject($this))->getConstants() as $key => $val) {
|
||||
foreach (new ReflectionObject($this)->getConstants() as $key => $val) {
|
||||
if (!str_starts_with($key, 'COLUMN_')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,6 @@ final class ArrayTransformer
|
||||
|
||||
public function __invoke(TransformType $type, mixed $data): string|array
|
||||
{
|
||||
return (new JSONTransformer(isAssoc: true, nullable: $this->nullable))(type: $type, data: $data);
|
||||
return new JSONTransformer(isAssoc: true, nullable: $this->nullable)(type: $type, data: $data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ final class Event extends EntityTable
|
||||
return false;
|
||||
}
|
||||
|
||||
return (new EntityValidation($this))->isValid();
|
||||
return new EntityValidation($this)->isValid();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class EmbyGuidTest extends TestCase
|
||||
private function getClass(): EmbyGuid
|
||||
{
|
||||
$this->handler->clear();
|
||||
return (new EmbyGuid($this->logger))->withContext(
|
||||
return new EmbyGuid($this->logger)->withContext(
|
||||
new Context(
|
||||
clientName: EmbyClient::CLIENT_NAME,
|
||||
backendName: 'test_emby',
|
||||
|
||||
@@ -54,7 +54,7 @@ class JellyfinGuidTest extends TestCase
|
||||
private function getClass(): JellyfinGuid
|
||||
{
|
||||
$this->handler->clear();
|
||||
return (new JellyfinGuid($this->logger))->withContext(
|
||||
return new JellyfinGuid($this->logger)->withContext(
|
||||
new Context(
|
||||
clientName: JellyfinClient::CLIENT_NAME,
|
||||
backendName: 'test_jellyfin',
|
||||
|
||||
@@ -58,7 +58,7 @@ class GetLibrariesListTest extends TestCase
|
||||
]);
|
||||
|
||||
$client = new MockHttpClient($resp);
|
||||
$response = (new GetLibrariesList($client, $this->logger))($this->context);
|
||||
$response = new GetLibrariesList($client, $this->logger)($this->context);
|
||||
|
||||
$this->assertTrue($response->status);
|
||||
$this->assertNull($response->error);
|
||||
|
||||
@@ -54,7 +54,7 @@ class PlexGuidTest extends TestCase
|
||||
private function getClass(): PlexGuid
|
||||
{
|
||||
$this->handler->clear();
|
||||
return (new PlexGuid($this->logger))->withContext(
|
||||
return new PlexGuid($this->logger)->withContext(
|
||||
new Context(
|
||||
clientName: PlexClient::CLIENT_NAME,
|
||||
backendName: 'test_plex',
|
||||
|
||||
@@ -119,7 +119,7 @@ class DBLayerTest extends TestCase
|
||||
$this->db->exec($cmd);
|
||||
}
|
||||
|
||||
(new PDOAdapter(new Logger('test'), $this->db))->migrations('up');
|
||||
new PDOAdapter(new Logger('test'), $this->db)->migrations('up');
|
||||
|
||||
return $db->query(sql: 'SELECT * FROM test WHERE zid = :id');
|
||||
},
|
||||
|
||||
@@ -23,7 +23,7 @@ class EmitterTest extends TestCase
|
||||
{
|
||||
$this->headers = [];
|
||||
$this->body = '';
|
||||
$this->emitter = (new Emitter())
|
||||
$this->emitter = new Emitter()
|
||||
->withHeaderFunc(function ($header, $replace, $status) {
|
||||
$this->headers[] = [
|
||||
'header' => $header,
|
||||
|
||||
@@ -389,7 +389,7 @@ class HelpersTest extends TestCase
|
||||
$entity = new StateEntity($movieData);
|
||||
$stream = new Stream(fopen('php://memory', 'w+'));
|
||||
$factory = new Psr17Factory();
|
||||
$request = (new ServerRequestCreator($factory, $factory, $factory, $factory))
|
||||
$request = new ServerRequestCreator($factory, $factory, $factory, $factory)
|
||||
->fromArrays(['REQUEST_METHOD' => 'GET']);
|
||||
saveWebhookPayload(entity: $entity, request: $request, file: $stream);
|
||||
|
||||
@@ -416,7 +416,7 @@ class HelpersTest extends TestCase
|
||||
|
||||
$factory = new Psr17Factory();
|
||||
|
||||
$request = (new ServerRequestCreator($factory, $factory, $factory, $factory))
|
||||
$request = new ServerRequestCreator($factory, $factory, $factory, $factory)
|
||||
->fromArrays(server: ['REQUEST_METHOD' => 'GET']);
|
||||
$request = $request->withBody(Stream::create(json_encode($movieData)))
|
||||
->withParsedBody($movieData)
|
||||
@@ -430,7 +430,7 @@ class HelpersTest extends TestCase
|
||||
$content = json_decode($data, associative: true);
|
||||
|
||||
$factory2 = new Psr17Factory();
|
||||
$fromFile = (new ServerRequestCreator($factory2, $factory2, $factory2, $factory2))
|
||||
$fromFile = new ServerRequestCreator($factory2, $factory2, $factory2, $factory2)
|
||||
->fromArrays(server: ag($content, 'server'), body: ag($content, 'body'));
|
||||
$fromFile = $fromFile
|
||||
->withAttribute('foo', 'bar')
|
||||
@@ -851,7 +851,7 @@ class HelpersTest extends TestCase
|
||||
public function test_getClientIp(): void
|
||||
{
|
||||
$factory = new Psr17Factory();
|
||||
$request = (new ServerRequestCreator($factory, $factory, $factory, $factory))
|
||||
$request = new ServerRequestCreator($factory, $factory, $factory, $factory)
|
||||
->fromArrays(['REQUEST_METHOD' => 'GET', 'REMOTE_ADDR' => '1.2.3.4']);
|
||||
|
||||
$this->assertSame(
|
||||
@@ -861,7 +861,7 @@ class HelpersTest extends TestCase
|
||||
);
|
||||
|
||||
$factory = new Psr17Factory();
|
||||
$request = (new ServerRequestCreator($factory, $factory, $factory, $factory))
|
||||
$request = new ServerRequestCreator($factory, $factory, $factory, $factory)
|
||||
->fromArrays([
|
||||
'REQUEST_METHOD' => 'GET',
|
||||
'REMOTE_ADDR' => '1.2.3.4',
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
<?php
|
||||
/** @noinspection PhpVoidFunctionResultUsedInspection */
|
||||
|
||||
/** @noinspection PhpMultipleClassDeclarationsInspection */
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
@@ -12,6 +9,7 @@ use App\Libs\TestCase;
|
||||
use Monolog\Handler\TestHandler;
|
||||
use Monolog\Level;
|
||||
use Monolog\Logger;
|
||||
use Throwable;
|
||||
|
||||
class LogSuppressorTest extends TestCase
|
||||
{
|
||||
@@ -42,7 +40,7 @@ class LogSuppressorTest extends TestCase
|
||||
parent::setUp();
|
||||
|
||||
$this->handler = new TestHandler(level: Level::Info);
|
||||
$this->suppressor = (new LogSuppressor($this->testData))->withHandler($this->handler);
|
||||
$this->suppressor = new LogSuppressor($this->testData)->withHandler($this->handler);
|
||||
$this->logger = new Logger('test', handlers: [$this->suppressor]);
|
||||
}
|
||||
|
||||
@@ -140,6 +138,10 @@ class LogSuppressorTest extends TestCase
|
||||
$this->suppressor->handleBatch($records);
|
||||
$this->assertCount(1, $this->handler->getRecords());
|
||||
|
||||
$this->assertNull($this->suppressor->close(), 'Close should not throw an error.');
|
||||
try {
|
||||
$this->suppressor->close();
|
||||
} catch (Throwable) {
|
||||
$this->fail('Close should not throw an error.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class APIKeyRequiredMiddlewareTest extends TestCase
|
||||
|
||||
public function test_internal_request()
|
||||
{
|
||||
$result = (new APIKeyRequiredMiddleware())->process(
|
||||
$result = new APIKeyRequiredMiddleware()->process(
|
||||
request: $this->getRequest()->withAttribute('INTERNAL_REQUEST', true),
|
||||
handler: $this->getHandler()
|
||||
);
|
||||
@@ -34,7 +34,7 @@ class APIKeyRequiredMiddlewareTest extends TestCase
|
||||
|
||||
public function test_options_request()
|
||||
{
|
||||
$result = (new APIKeyRequiredMiddleware())->process(
|
||||
$result = new APIKeyRequiredMiddleware()->process(
|
||||
request: $this->getRequest(method: Method::OPTIONS),
|
||||
handler: $this->getHandler()
|
||||
);
|
||||
@@ -57,7 +57,7 @@ class APIKeyRequiredMiddlewareTest extends TestCase
|
||||
|
||||
foreach ($routes as $route) {
|
||||
$uri = parseConfigValue($route);
|
||||
$result = (new APIKeyRequiredMiddleware())->process(
|
||||
$result = new APIKeyRequiredMiddleware()->process(
|
||||
request: $this->getRequest(uri: $uri),
|
||||
handler: $this->getHandler()
|
||||
);
|
||||
@@ -66,7 +66,7 @@ class APIKeyRequiredMiddlewareTest extends TestCase
|
||||
|
||||
foreach ($routesSemiOpen as $route) {
|
||||
$uri = parseConfigValue($route);
|
||||
$result = (new APIKeyRequiredMiddleware())->process(
|
||||
$result = new APIKeyRequiredMiddleware()->process(
|
||||
request: $this->getRequest(uri: $uri),
|
||||
handler: $this->getHandler()
|
||||
);
|
||||
@@ -77,7 +77,7 @@ class APIKeyRequiredMiddlewareTest extends TestCase
|
||||
|
||||
foreach ($routesSemiOpen as $route) {
|
||||
$uri = parseConfigValue($route);
|
||||
$result = (new APIKeyRequiredMiddleware())->process(
|
||||
$result = new APIKeyRequiredMiddleware()->process(
|
||||
request: $this->getRequest(uri: $uri)->withoutHeader('Authorization'),
|
||||
handler: $this->getHandler()
|
||||
);
|
||||
@@ -90,7 +90,7 @@ class APIKeyRequiredMiddlewareTest extends TestCase
|
||||
|
||||
foreach ($routesSemiOpen as $route) {
|
||||
$uri = parseConfigValue($route);
|
||||
$result = (new APIKeyRequiredMiddleware())->process(
|
||||
$result = new APIKeyRequiredMiddleware()->process(
|
||||
request: $this->getRequest(uri: $uri)->withHeader('Authorization', 'Bearer api'),
|
||||
handler: $this->getHandler()
|
||||
);
|
||||
@@ -104,7 +104,7 @@ class APIKeyRequiredMiddlewareTest extends TestCase
|
||||
Config::save('api.key', 'api_test_token');
|
||||
foreach ($routesSemiOpen as $route) {
|
||||
$uri = parseConfigValue($route);
|
||||
$result = (new APIKeyRequiredMiddleware())->process(
|
||||
$result = new APIKeyRequiredMiddleware()->process(
|
||||
request: $this->getRequest(uri: $uri, query: ['apikey' => 'api_test_token'])->withHeader(
|
||||
'X-apikey',
|
||||
'api_test_token'
|
||||
|
||||
@@ -16,7 +16,7 @@ class AddCorsMiddlewareTest extends TestCase
|
||||
|
||||
public function test_response()
|
||||
{
|
||||
$result = (new AddCorsMiddleware())->process(
|
||||
$result = new AddCorsMiddleware()->process(
|
||||
request: $this->getRequest(),
|
||||
handler: $this->getHandler(new Response(Status::OK))
|
||||
);
|
||||
|
||||
@@ -15,7 +15,7 @@ class ExceptionHandlerMiddlewareTest extends TestCase
|
||||
/** @noinspection PhpUnhandledExceptionInspection */
|
||||
public function test_response()
|
||||
{
|
||||
$result = (new ExceptionHandlerMiddleware())->process(
|
||||
$result = new ExceptionHandlerMiddleware()->process(
|
||||
request: $this->getRequest(),
|
||||
handler: $this->getHandler(
|
||||
fn() => throw new \RuntimeException('Test Exception', 404)
|
||||
|
||||
@@ -17,9 +17,9 @@ class NoAccessLogMiddlewareTest extends TestCase
|
||||
|
||||
public function test_response_not_internal_request()
|
||||
{
|
||||
$result = (new NoAccessLogMiddleware())->process(
|
||||
$result = new NoAccessLogMiddleware()->process(
|
||||
request: $this->getRequest(),
|
||||
handler: $this->getHandler((new Response(Status::OK)))
|
||||
handler: $this->getHandler(new Response(Status::OK))
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
@@ -32,9 +32,9 @@ class NoAccessLogMiddlewareTest extends TestCase
|
||||
{
|
||||
Config::save('api.logInternal', true);
|
||||
|
||||
$result = (new NoAccessLogMiddleware())->process(
|
||||
$result = new NoAccessLogMiddleware()->process(
|
||||
request: $this->getRequest()->withAttribute('INTERNAL_REQUEST', true),
|
||||
handler: $this->getHandler((new Response(Status::OK)))
|
||||
handler: $this->getHandler(new Response(Status::OK))
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
@@ -43,9 +43,9 @@ class NoAccessLogMiddlewareTest extends TestCase
|
||||
);
|
||||
|
||||
Config::save('api.logInternal', false);
|
||||
$result = (new NoAccessLogMiddleware())->process(
|
||||
$result = new NoAccessLogMiddleware()->process(
|
||||
request: $this->getRequest()->withAttribute('INTERNAL_REQUEST', true),
|
||||
handler: $this->getHandler((new Response(Status::OK)))
|
||||
handler: $this->getHandler(new Response(Status::OK))
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
|
||||
@@ -20,7 +20,7 @@ class ParseJsonBodyMiddlewareTest extends TestCase
|
||||
public function test_exceptions()
|
||||
{
|
||||
$this->checkException(
|
||||
closure: fn() => (new ParseJsonBodyMiddleware())->process(
|
||||
closure: fn() => new ParseJsonBodyMiddleware()->process(
|
||||
request: $this->getRequest(method: 'NOT_OK')->withBody(
|
||||
Stream::create(json_encode(['key' => 'test']))
|
||||
)->withHeader('Content-Type', 'application/json'),
|
||||
@@ -32,7 +32,7 @@ class ParseJsonBodyMiddlewareTest extends TestCase
|
||||
);
|
||||
|
||||
$this->checkException(
|
||||
closure: fn() => (new ParseJsonBodyMiddleware())->process(
|
||||
closure: fn() => new ParseJsonBodyMiddleware()->process(
|
||||
request: $this->getRequest(Method::POST)->withBody(
|
||||
Stream::create(json_encode(['key' => 'test']) . 'invalid json')
|
||||
)->withHeader('Content-Type', 'application/json'),
|
||||
@@ -48,7 +48,7 @@ class ParseJsonBodyMiddlewareTest extends TestCase
|
||||
{
|
||||
$mutatedRequest = null;
|
||||
|
||||
(new ParseJsonBodyMiddleware())->process(
|
||||
new ParseJsonBodyMiddleware()->process(
|
||||
request: $this->getRequest(Method::GET)->withBody(
|
||||
Stream::create(json_encode(['key' => 'test']))
|
||||
)->withHeader('Content-Type', 'application/json'),
|
||||
@@ -63,7 +63,7 @@ class ParseJsonBodyMiddlewareTest extends TestCase
|
||||
|
||||
$mutatedRequest = null;
|
||||
|
||||
(new ParseJsonBodyMiddleware())->process(
|
||||
new ParseJsonBodyMiddleware()->process(
|
||||
request: $this->getRequest(Method::POST)->withBody(
|
||||
Stream::create('')
|
||||
)->withHeader('Content-Type', 'application/json'),
|
||||
@@ -76,7 +76,7 @@ class ParseJsonBodyMiddlewareTest extends TestCase
|
||||
$this->assertCount(0, $mutatedRequest->getParsedBody(), 'Parsed body should be empty.');
|
||||
$this->assertSame([], $mutatedRequest->getParsedBody(), 'Parsed body should be null.');
|
||||
|
||||
(new ParseJsonBodyMiddleware())->process(
|
||||
new ParseJsonBodyMiddleware()->process(
|
||||
request: $this->getRequest(Method::POST)->withBody(
|
||||
Stream::create(json_encode(['key' => 'test']))
|
||||
),
|
||||
@@ -95,7 +95,7 @@ class ParseJsonBodyMiddlewareTest extends TestCase
|
||||
|
||||
public function test_correct_mutation()
|
||||
{
|
||||
(new ParseJsonBodyMiddleware())->process(
|
||||
new ParseJsonBodyMiddleware()->process(
|
||||
request: $this->getRequest(Method::POST)->withBody(
|
||||
Stream::create(json_encode(['key' => 'test']))
|
||||
)->withHeader('Content-Type', 'application/json'),
|
||||
|
||||
@@ -40,7 +40,7 @@ class ServeStaticTest extends TestCase
|
||||
$this->checkException(
|
||||
closure: function () {
|
||||
Config::save('webui.path', '/nonexistent');
|
||||
return (new ServeStatic())->serve($this->createRequest('GET', '/nonexistent'));
|
||||
return new ServeStatic()->serve($this->createRequest('GET', '/nonexistent'));
|
||||
},
|
||||
reason: 'If file does not exist, A NotFoundException should be thrown.',
|
||||
exception: \League\Route\Http\Exception\BadRequestException::class,
|
||||
@@ -66,7 +66,7 @@ class ServeStaticTest extends TestCase
|
||||
|
||||
// -- Check for invalid root static path.
|
||||
$this->checkException(
|
||||
closure: fn() => (new ServeStatic('/nonexistent'))->serve($this->createRequest('GET', '/test.html')),
|
||||
closure: fn() => new ServeStatic('/nonexistent')->serve($this->createRequest('GET', '/test.html')),
|
||||
reason: 'Should throw exception if the static path does not exist.',
|
||||
exception: \League\Route\Http\Exception\BadRequestException::class,
|
||||
exceptionMessage: 'The static path',
|
||||
|
||||
@@ -364,11 +364,11 @@ class StateEntityTest extends TestCase
|
||||
public function test_hasRelativeGuid(): void
|
||||
{
|
||||
$this->assertTrue(
|
||||
(new StateEntity($this->testEpisode))->hasRelativeGuid(),
|
||||
new StateEntity($this->testEpisode)->hasRelativeGuid(),
|
||||
'When entity is episode, and only if has supported GUIDs hasRelativeGuid() returns true'
|
||||
);
|
||||
$this->assertFalse(
|
||||
(new StateEntity($this->testMovie))->hasRelativeGuid(),
|
||||
new StateEntity($this->testMovie)->hasRelativeGuid(),
|
||||
'When entity is movie, hasRelativeGuid() returns false regardless'
|
||||
);
|
||||
|
||||
@@ -401,7 +401,7 @@ class StateEntityTest extends TestCase
|
||||
{
|
||||
$this->assertSame(
|
||||
[],
|
||||
(new StateEntity($this->testMovie))->getRelativeGuids(),
|
||||
new StateEntity($this->testMovie)->getRelativeGuids(),
|
||||
'When entity is movie, getRelativeGuids() returns empty array regardless'
|
||||
);
|
||||
$this->assertSame(
|
||||
@@ -409,7 +409,7 @@ class StateEntityTest extends TestCase
|
||||
'guid_imdb' => 'tt510/1/2',
|
||||
'guid_tvdb' => '520/1/2'
|
||||
],
|
||||
(new StateEntity($this->testEpisode))->getRelativeGuids(),
|
||||
new StateEntity($this->testEpisode)->getRelativeGuids(),
|
||||
'When entity is episode, and has supported GUIDs, getRelativeGuids() returns list of all supported GUIDs'
|
||||
);
|
||||
|
||||
@@ -454,7 +454,7 @@ class StateEntityTest extends TestCase
|
||||
);
|
||||
|
||||
$this->assertSame([],
|
||||
(new StateEntity($this->testMovie))->getRelativePointers(),
|
||||
new StateEntity($this->testMovie)->getRelativePointers(),
|
||||
'When entity is movie, getRelativePointers() returns empty array regardless.'
|
||||
);
|
||||
|
||||
|
||||
@@ -245,13 +245,13 @@ class UriTest extends TestCase
|
||||
|
||||
$this->assertSame(
|
||||
'http://user:pass@host:81/path',
|
||||
(string)(new Uri('http://user:pass@host:81'))->withPath('path'),
|
||||
(string)new Uri('http://user:pass@host:81')->withPath('path'),
|
||||
'The string should be http://user:pass@host:81/path'
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'http:/path',
|
||||
(string)(new Uri('http://host:81'))->withHost('')->withPath('//path'),
|
||||
(string)new Uri('http://host:81')->withHost('')->withPath('//path'),
|
||||
'The string should be http:/path'
|
||||
);
|
||||
}
|
||||
@@ -259,7 +259,7 @@ class UriTest extends TestCase
|
||||
public function test_customUrls()
|
||||
{
|
||||
foreach ($this->customUrls as $url) {
|
||||
$this->assertSame($url, (string)(new Uri($url)), "The URL should be $url");
|
||||
$this->assertSame($url, (string)new Uri($url), "The URL should be $url");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ use Monolog\Handler\TestHandler;
|
||||
use Monolog\Logger;
|
||||
use PDO;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Random\RandomException;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
@@ -61,7 +60,6 @@ abstract class MapperAbstract extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RandomException
|
||||
*/
|
||||
public function test_loadData_null_date_conditions(): void
|
||||
{
|
||||
@@ -87,7 +85,6 @@ abstract class MapperAbstract extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RandomException
|
||||
*/
|
||||
public function test_loadData_date_conditions(): void
|
||||
{
|
||||
@@ -314,7 +311,6 @@ abstract class MapperAbstract extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RandomException
|
||||
*/
|
||||
public function test_get_conditions(): void
|
||||
{
|
||||
@@ -359,7 +355,6 @@ abstract class MapperAbstract extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RandomException
|
||||
*/
|
||||
public function test_get_fully_loaded_conditions(): void
|
||||
{
|
||||
@@ -445,7 +440,6 @@ abstract class MapperAbstract extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RandomException
|
||||
*/
|
||||
public function test_has_conditions(): void
|
||||
{
|
||||
@@ -462,7 +456,6 @@ abstract class MapperAbstract extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RandomException
|
||||
*/
|
||||
public function test_has_fully_loaded_conditions(): void
|
||||
{
|
||||
@@ -498,7 +491,6 @@ abstract class MapperAbstract extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RandomException
|
||||
*/
|
||||
public function test_getObjects_conditions(): void
|
||||
{
|
||||
@@ -524,7 +516,6 @@ abstract class MapperAbstract extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RandomException
|
||||
*/
|
||||
public function test_commit_with_no_episode_number(): void
|
||||
{
|
||||
@@ -535,7 +526,6 @@ abstract class MapperAbstract extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RandomException
|
||||
*/
|
||||
public function test_insert_with_no_episode_number(): void
|
||||
{
|
||||
@@ -546,7 +536,6 @@ abstract class MapperAbstract extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RandomException
|
||||
*/
|
||||
public function test_update_with_no_episode_number(): void
|
||||
{
|
||||
|
||||
@@ -58,7 +58,7 @@ class ServerTest extends TestCase
|
||||
'Should be equal config.'
|
||||
);
|
||||
|
||||
$c = (new Server())->getConfig();
|
||||
$c = new Server()->getConfig();
|
||||
|
||||
$this->assertSame($c[Server::CONFIG_HOST], '0.0.0.0', 'Default host has changed.');
|
||||
$this->assertSame($c[Server::CONFIG_PORT], 8080, 'Default port has changed.');
|
||||
|
||||
Reference in New Issue
Block a user