Skip to content

Commit f9e40f5

Browse files
committed
A code clean up commit.
1 parent de13d52 commit f9e40f5

File tree

75 files changed

+158
-178
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+158
-178
lines changed

bin/console

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ if (!file_exists(__DIR__ . '/../vendor/autoload.php')) {
5151
require __DIR__ . '/../vendor/autoload.php';
5252

5353
try {
54-
$app = (new App\Libs\Initializer())->boot();
54+
$app = new App\Libs\Initializer()->boot();
5555
} catch (Throwable $e) {
5656
$message = strtr(
5757
'CLI: Exception [{kind}] was thrown unhandled during CLI boot context. Error [{message} @ {file}:{line}].',

config/config.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@
247247

248248
$checkTaskTimer = function (string $timer, string $default): string {
249249
try {
250-
$isValid = (new CronExpression($timer))->getNextRunDate()->getTimestamp() >= 0;
250+
$isValid = new CronExpression($timer)->getNextRunDate()->getTimestamp() >= 0;
251251
return $isValid ? $timer : $default;
252252
} catch (Throwable) {
253253
return $default;

config/env.spec.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
$value = substr($value, 1, -1);
184184
}
185185

186-
$status = (new CronExpression($value))->getNextRunDate()->getTimestamp() >= 0;
186+
$status = new CronExpression($value)->getNextRunDate()->getTimestamp() >= 0;
187187

188188
if (!$status) {
189189
throw new ValidationException('Invalid cron expression. The next run date is in the past.');

config/services.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239

240240
MemoryMapper::class => [
241241
'class' => function (iLogger $logger, iDB $db, CacheInterface $cache): iImport {
242-
return (new MemoryMapper(logger: $logger, db: $db, cache: $cache))
242+
return new MemoryMapper(logger: $logger, db: $db, cache: $cache)
243243
->setOptions(options: Config::get('mapper.import.opts', []));
244244
},
245245
'args' => [
@@ -251,7 +251,7 @@
251251

252252
DirectMapper::class => [
253253
'class' => function (iLogger $logger, iDB $db, CacheInterface $cache): iImport {
254-
return (new DirectMapper(logger: $logger, db: $db, cache: $cache))
254+
return new DirectMapper(logger: $logger, db: $db, cache: $cache)
255255
->setOptions(options: Config::get('mapper.import.opts', []));
256256
},
257257
'args' => [

public/index.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
$_SERVER['X_REQUEST_ID'] = bin2hex(random_bytes(16));
5858
}
5959

60-
$app = (new App\Libs\Initializer())->boot();
60+
$app = new App\Libs\Initializer()->boot();
6161
} catch (Throwable $e) {
6262
$out = fn($message) => inContainer() ? fwrite(STDERR, $message) : syslog(LOG_ERR, $message);
6363

@@ -81,7 +81,7 @@
8181
}
8282

8383
try {
84-
(new Emitter())($app->http());
84+
new Emitter()($app->http());
8585
} catch (Throwable $e) {
8686
$out = fn($message) => inContainer() ? fwrite(STDERR, $message) : syslog(LOG_ERR, $message);
8787

src/API/Backend/Ignore.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public function __construct()
2828
}
2929

3030
#[Get(Index::URL . '/{name:backend}/ignore[/]', name: 'backend.ignoredIds')]
31-
public function ignoredIds(iRequest $request, array $args = []): iResponse
31+
public function ignoredIds(string $name): iResponse
3232
{
33-
if (null === ($name = ag($args, 'name'))) {
33+
if (empty($name)) {
3434
return api_error('Invalid value for name path parameter.', Status::BAD_REQUEST);
3535
}
3636

src/API/Backend/Library.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ final class Library
2222
use APITraits;
2323

2424
#[Get(BackendsIndex::URL . '/{name:backend}/library[/]', name: 'backend.library')]
25-
public function listLibraries(iRequest $request, array $args = []): iResponse
25+
public function listLibraries(string $name): iResponse
2626
{
27-
if (null === ($name = ag($args, 'name'))) {
27+
if (empty($name)) {
2828
return api_error('Invalid value for name path parameter.', Status::BAD_REQUEST);
2929
}
3030

src/API/Logs/Index.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function logView(iRequest $request, array $args = []): iResponse
177177

178178
private function download(string $filePath): iResponse
179179
{
180-
$mime = (new finfo(FILEINFO_MIME_TYPE))->file($filePath);
180+
$mime = new finfo(FILEINFO_MIME_TYPE)->file($filePath);
181181

182182
return api_response(Status::OK, Stream::make($filePath, 'r'), headers: [
183183
'Content-Type' => false === $mime ? 'application/octet-stream' : $mime,

src/API/System/Backup.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function read(iRequest $request, string $filename): iResponse
6868
return api_response(Status::OK);
6969
}
7070

71-
$mime = (new finfo(FILEINFO_MIME_TYPE))->file($filePath);
71+
$mime = new finfo(FILEINFO_MIME_TYPE)->file($filePath);
7272

7373
return api_response(Status::OK, Stream::make($filePath, 'r'), headers: [
7474
'Content-Type' => false === $mime ? 'application/octet-stream' : $mime,

src/API/System/Env.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@ public function envList(iRequest $request): iResponse
6464
}
6565

6666
#[Get(self::URL . '/{key}[/]', name: 'system.env.view')]
67-
public function envView(iRequest $request, array $args = []): iResponse
67+
public function envView(string $key): iResponse
6868
{
69-
$key = strtoupper((string)ag($args, 'key', ''));
7069
if (empty($key)) {
7170
return api_error('Invalid value for key path parameter.', Status::BAD_REQUEST);
7271
}

src/API/System/Guids.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,19 @@ public function custom_client_link_add(iRequest $request, string $client): iResp
254254
]), Status::BAD_REQUEST);
255255
}
256256

257-
foreach (ag($this->getData(), 'links', []) as $link) {
258-
if ($link['type'] === $client && $link['map']['from'] === $params->get('map.from')) {
259-
return api_error(r("The client '{client}' map.from '{from}' is already exists.", [
257+
$exists = array_any(
258+
ag($this->getData(), 'links', []),
259+
fn($link) => $link['type'] === $client && $link['map']['from'] === $params->get('map.from')
260+
);
261+
262+
if (true === $exists) {
263+
return api_error(
264+
r("The client '{client}' map.from '{from}' is already exists.", [
260265
'client' => $client,
261266
'from' => $params->get('map.from')
262-
]), Status::BAD_REQUEST);
263-
}
267+
]),
268+
Status::BAD_REQUEST
269+
);
264270
}
265271

266272
$link = [

src/API/System/Integrity.php

-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ final class Integrity
3131

3232
private bool $fromCache = false;
3333

34-
/**
35-
* @throws InvalidArgumentException
36-
*/
3734
public function __construct(private readonly iCache $cache)
3835
{
3936
set_time_limit(0);

src/API/System/Parity.php

-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use App\Libs\Traits\APITraits;
1313
use Psr\Http\Message\ResponseInterface as iResponse;
1414
use Psr\Http\Message\ServerRequestInterface as iRequest;
15-
use Psr\SimpleCache\InvalidArgumentException;
1615

1716
final class Parity
1817
{
@@ -25,7 +24,6 @@ public function __construct(private readonly DBLayer $db)
2524
}
2625

2726
/**
28-
* @throws InvalidArgumentException
2927
*/
3028
#[Get(self::URL . '[/]', name: 'system.parity')]
3129
public function __invoke(iRequest $request): iResponse
@@ -107,7 +105,6 @@ public function __invoke(iRequest $request): iResponse
107105
}
108106

109107
/**
110-
* @throws InvalidArgumentException
111108
*/
112109
#[Delete(self::URL . '[/]', name: 'system.parity.delete')]
113110
public function deleteRecords(iRequest $request): iResponse

src/API/System/Suppressor.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ public function editSuppressor(iRequest $request, array $args = []): iResponse
128128
}
129129

130130
#[Delete(self::URL . '/{id:\w{11}}[/]', name: 'system.suppressor.delete')]
131-
public function deleteSuppressor(iRequest $request, array $args = []): iResponse
131+
public function deleteSuppressor(string $id): iResponse
132132
{
133-
if (null === ($id = ag($args, 'id')) || empty($id)) {
133+
if (empty($id)) {
134134
return api_error('Invalid suppressor id.', Status::BAD_REQUEST);
135135
}
136136

@@ -144,9 +144,9 @@ public function deleteSuppressor(iRequest $request, array $args = []): iResponse
144144
}
145145

146146
#[Get(self::URL . '/{id:\w{11}}[/]', name: 'system.suppressor.view')]
147-
public function viewSuppressor(iRequest $request, array $args = []): iResponse
147+
public function viewSuppressor(string $id): iResponse
148148
{
149-
if (null === ($id = ag($args, 'id')) || empty($id)) {
149+
if (empty($id)) {
150150
return api_error('Invalid suppressor id.', Status::BAD_REQUEST);
151151
}
152152

src/API/Tasks.php

-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Cron\CronExpression;
1616
use Psr\Http\Message\ResponseInterface as iResponse;
1717
use Psr\Http\Message\ServerRequestInterface as iRequest;
18-
use Psr\SimpleCache\InvalidArgumentException;
1918

2019
final class Tasks
2120
{
@@ -25,9 +24,6 @@ public function __construct(private EventsRepository $eventsRepo)
2524
{
2625
}
2726

28-
/**
29-
* @throws InvalidArgumentException
30-
*/
3127
#[Get(self::URL . '[/]', name: 'tasks.index')]
3228
public function tasksIndex(): iResponse
3329
{
@@ -55,9 +51,6 @@ public function tasksIndex(): iResponse
5551
]);
5652
}
5753

58-
/**
59-
* @throws InvalidArgumentException
60-
*/
6154
#[Route(['GET', 'POST', 'DELETE'], self::URL . '/{id:[a-zA-Z0-9_-]+}/queue[/]', name: 'tasks.task.queue')]
6255
public function taskQueue(iRequest $request, string $id): iResponse
6356
{

src/Backends/Common/Response.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace App\Backends\Common;
66

7-
final class Response
7+
final readonly class Response
88
{
99
/**
1010
* Wrap clients responses into easy to consume object.
@@ -15,10 +15,10 @@ final class Response
1515
* @param mixed $extra An array that can contain anything. Should be rarely used.
1616
*/
1717
public function __construct(
18-
public readonly bool $status,
19-
public readonly mixed $response = null,
20-
public readonly Error|null $error = null,
21-
public readonly array $extra = [],
18+
public bool $status,
19+
public mixed $response = null,
20+
public Error|null $error = null,
21+
public array $extra = [],
2222
) {
2323
}
2424

src/Backends/Jellyfin/Action/GetIdentifier.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __invoke(Context $context, array $opts = []): Response
5353
return $this->tryResponse(
5454
context: $context,
5555
fn: function () use ($context, $opts) {
56-
$info = (new GetInfo($this->http, $this->logger, $this->cache))(context: $context, opts: $opts);
56+
$info = new GetInfo($this->http, $this->logger, $this->cache)(context: $context, opts: $opts);
5757

5858
if (false === $info->status) {
5959
return $info;

src/Backends/Jellyfin/Action/GetVersion.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __invoke(Context $context, array $opts = []): Response
5252
return $this->tryResponse(
5353
context: $context,
5454
fn: function () use ($context, $opts) {
55-
$info = (new GetInfo($this->http, $this->logger, $this->cache))(context: $context, opts: $opts);
55+
$info = new GetInfo($this->http, $this->logger, $this->cache)(context: $context, opts: $opts);
5656

5757
if (false === $info->status) {
5858
return $info;

src/Backends/Jellyfin/Action/SearchQuery.php

-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use App\Backends\Jellyfin\JellyfinClient;
1414
use App\Backends\Jellyfin\JellyfinGuid;
1515
use App\Libs\Database\DatabaseInterface as iDB;
16-
use App\Libs\Exceptions\Backends\RuntimeException;
1716
use App\Libs\Options;
1817
use JsonException;
1918
use Psr\Log\LoggerInterface as iLogger;
@@ -72,7 +71,6 @@ public function __invoke(Context $context, string $query, int $limit = 25, array
7271
*
7372
* @throws ExceptionInterface When the request fails.
7473
* @throws JsonException When the response is not valid JSON.
75-
* @throws RuntimeException
7674
*/
7775
private function search(Context $context, string $query, int $limit = 25, array $opts = []): Response
7876
{

src/Backends/Plex/Action/GetIdentifier.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __invoke(Context $context, array $opts = []): Response
3737
return $this->tryResponse(
3838
context: $context,
3939
fn: function () use ($context, $opts) {
40-
$info = (new GetInfo($this->http, $this->logger, $this->cache))(context: $context, opts: $opts);
40+
$info = new GetInfo($this->http, $this->logger, $this->cache)(context: $context, opts: $opts);
4141

4242
if (false === $info->status) {
4343
return $info;

src/Backends/Plex/Action/GetVersion.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __invoke(Context $context, array $opts = []): Response
3737
return $this->tryResponse(
3838
context: $context,
3939
fn: function () use ($context, $opts) {
40-
$info = (new GetInfo($this->http, $this->logger, $this->cache))(context: $context, opts: $opts);
40+
$info = new GetInfo($this->http, $this->logger, $this->cache)(context: $context, opts: $opts);
4141

4242
if (false === $info->status) {
4343
return $info;

src/Backends/Plex/Action/SearchQuery.php

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use App\Backends\Plex\PlexActionTrait;
1313
use App\Backends\Plex\PlexGuid;
1414
use App\Libs\Database\DatabaseInterface as iDB;
15-
use App\Libs\Exceptions\Backends\RuntimeException;
1615
use App\Libs\Options;
1716
use JsonException;
1817
use Psr\Log\LoggerInterface as iLogger;
@@ -58,7 +57,6 @@ public function __invoke(Context $context, string $query, int $limit = 25, array
5857
*
5958
* @throws ExceptionInterface if the request failed
6059
* @throws JsonException if the response cannot be parsed
61-
* @throws RuntimeException
6260
*/
6361
private function search(Context $context, string $query, int $limit = 25, array $opts = []): Response
6462
{

src/Backends/Plex/Commands/DiscoverCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#[Cli(command: self::ROUTE)]
2323
final class DiscoverCommand extends Command
2424
{
25-
public const ROUTE = 'plex:discover';
25+
public const string ROUTE = 'plex:discover';
2626

2727
public function __construct(private iHttp $http, protected iLogger $logger)
2828
{

src/Command.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ protected function displayContent(array $content, OutputInterface $output, strin
270270

271271
if (!empty($list)) {
272272
array_pop($list);
273-
(new Table($output))
273+
new Table($output)
274274
->setStyle(name: 'box')
275275
->setHeaders(
276276
array_map(

src/Commands/Backend/InfoCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#[Cli(command: self::ROUTE)]
2323
class InfoCommand extends Command
2424
{
25-
public const ROUTE = 'backend:info';
25+
public const string ROUTE = 'backend:info';
2626

2727
/**
2828
* Configures the command.

src/Commands/Backend/Library/IgnoreCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#[Cli(command: self::ROUTE)]
2525
final class IgnoreCommand extends Command
2626
{
27-
public const ROUTE = 'backend:library:ignore';
27+
public const string ROUTE = 'backend:library:ignore';
2828

2929
public function __construct(private LoggerInterface $logger)
3030
{

src/Commands/Backend/Library/ListCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#[Cli(command: self::ROUTE)]
2121
final class ListCommand extends Command
2222
{
23-
public const ROUTE = 'backend:library:list';
23+
public const string ROUTE = 'backend:library:list';
2424

2525
/**
2626
* Configures the command.

src/Commands/Backend/RestoreCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#[Cli(command: self::ROUTE)]
3030
class RestoreCommand extends Command
3131
{
32-
public const ROUTE = 'backend:restore';
32+
public const string ROUTE = 'backend:restore';
3333

3434
/**
3535
* Class constructor.
@@ -213,7 +213,7 @@ protected function process(InputInterface $input, OutputInterface $output): int
213213
],
214214
]);
215215

216-
$mapper = (new RestoreMapper($this->logger, $file))->loadData();
216+
$mapper = new RestoreMapper($this->logger, $file)->loadData();
217217

218218
$this->logger->notice('SYSTEM: Loading restore data is complete.', [
219219
'memory' => [

src/Commands/Backend/Users/SessionsCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#[Cli(command: self::ROUTE)]
2222
final class SessionsCommand extends Command
2323
{
24-
public const ROUTE = 'backend:users:sessions';
24+
public const string ROUTE = 'backend:users:sessions';
2525

26-
private const REMAP_FIELDS = [
26+
private const array REMAP_FIELDS = [
2727
'user_name' => 'User',
2828
'item_title' => 'Title',
2929
'item_type' => 'Type',

0 commit comments

Comments
 (0)