Skip to content

Commit

Permalink
$ ./vendor/bin/pint @ be
Browse files Browse the repository at this point in the history
  • Loading branch information
n0099 committed Oct 9, 2024
1 parent 1119482 commit 1725db5
Show file tree
Hide file tree
Showing 35 changed files with 103 additions and 64 deletions.
4 changes: 2 additions & 2 deletions be/config/preload.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

if (file_exists(dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__).'/var/cache/prod/App_KernelProdContainer.preload.php';
if (file_exists(dirname(__DIR__) . '/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__) . '/var/cache/prod/App_KernelProdContainer.preload.php';
}
2 changes: 1 addition & 1 deletion be/public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use App\Kernel;

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
require_once dirname(__DIR__) . '/vendor/autoload_runtime.php';

return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
Expand Down
8 changes: 4 additions & 4 deletions be/src/Controller/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public function __construct(
) {}

#[Route('/assets/{filename}', requirements: [
'filename' => /** @lang JSRegexp */'(react(|-dom|-json-view)|scheduler)\.js'
'filename' => /** @lang JSRegexp */'(react(|-dom|-json-view)|scheduler)\.js',
])]
public function getAsset(string $filename) : Response
public function getAsset(string $filename): Response
{
return new Response(
content: preg_replace_callback_array([
Expand All @@ -27,9 +27,9 @@ public function getAsset(string $filename) : Response
'@^//# sourceMappingURL=.+$@m' =>
static fn() => '',
], $this->filesystem->readFile(
$this->getParameter('kernel.project_dir') . "/public/react-json-view/$filename"
$this->getParameter('kernel.project_dir') . "/public/react-json-view/$filename",
)),
headers: ['Content-Type' => 'text/javascript']
headers: ['Content-Type' => 'text/javascript'],
);
}
}
2 changes: 1 addition & 1 deletion be/src/Controller/ForumsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class ForumsController extends AbstractController
{
public function __construct(private readonly ForumRepository $repository,) {}
public function __construct(private readonly ForumRepository $repository) {}

#[Route('/api/forums')]
public function query(): array
Expand Down
6 changes: 3 additions & 3 deletions be/src/Controller/PostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function query(Request $request): array
$this->validator->validate($request->query->all(), new Assert\Collection([
'cursor' => new Assert\Optional(new Assert\Regex( // https://stackoverflow.com/questions/475074/regex-to-parse-or-validate-base64-data
// (,|$)|,){5,6} means allow at most 5~6 parts of base64 segment or empty string to exist
'/^(([A-Za-z0-9-_]{4})*([A-Za-z0-9-_]{2,3})(,|$)|,){5,6}$/'
'/^(([A-Za-z0-9-_]{4})*([A-Za-z0-9-_]{2,3})(,|$)|,){5,6}$/',
)),
'query' => new Assert\Required(new Assert\Json()),
]));
Expand Down Expand Up @@ -112,12 +112,12 @@ public function query(Request $request): array
$fid = $result['fid'];
$authorExpGrades = collect($this->authorExpGradeRepository->getLatestOfUsers($fid, $uids))
->keyBy(fn(AuthorExpGrade $authorExpGrade) => $authorExpGrade->getUid());
$users->each(fn (User $user) => $user->setCurrentAuthorExpGrade($authorExpGrades[$user->getUid()]));
$users->each(fn(User $user) => $user->setCurrentAuthorExpGrade($authorExpGrades[$user->getUid()]));

$forumModerators = collect($this->forumModeratorRepository
->getLatestOfUsers($fid, $users->map(fn(User $user) => $user->getPortrait())))
->keyBy(fn(ForumModerator $forumModerator) => $forumModerator->getPortrait());
$users->each(fn (User $user) => $user->setCurrentForumModerator($forumModerators->get($user->getPortrait())));
$users->each(fn(User $user) => $user->setCurrentForumModerator($forumModerators->get($user->getPortrait())));
$this->stopwatch->stop('queryUserRelated');

return [
Expand Down
12 changes: 7 additions & 5 deletions be/src/Controller/SitemapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SitemapController extends AbstractController
public function __construct(
private readonly CacheInterface $cache,
private readonly ForumRepository $forumRepository,
private readonly PostRepositoryFactory $postRepositoryFactory
private readonly PostRepositoryFactory $postRepositoryFactory,
) {}

#[Route('/sitemaps/forums')]
Expand All @@ -41,7 +41,8 @@ function (ItemInterface $item) use ($threadsIdKeyByFid) {
'sitemaps/forums.xml.twig',
['threads_id_key_by_fid' => $threadsIdKeyByFid],
);
});
},
);
}

#[Route('/sitemaps/forums/{fid}/threads', requirements: ['fid' => /** @lang JSRegexp */'\d+'])]
Expand All @@ -60,10 +61,11 @@ function (ItemInterface $item) use ($fid, $cursor) {
[
'threads_id' =>
$this->postRepositoryFactory->newThread($fid)->getThreadsIdAfter($cursor, self::$maxUrls),
'base_url_fe' => $this->getParameter('app.base_url.fe')
]
'base_url_fe' => $this->getParameter('app.base_url.fe'),
],
);
});
},
);
}

private function renderXml(string $view, array $parameters): Response
Expand Down
2 changes: 1 addition & 1 deletion be/src/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function (array $acc, $paramValue, string $paramName) use ($paramConstraints): a
: $queryBuilder->andWhere("t.$paramName = ?$paramIndex")
->setParameter($paramIndex, $paramValue)];
},
[0, $this->userRepository->createQueryBuilder('t')]
[0, $this->userRepository->createQueryBuilder('t')],
)[1]->orderBy('t.uid', 'DESC');

['result' => $result, 'hasMorePages' => $hasMorePages] =
Expand Down
15 changes: 10 additions & 5 deletions be/src/DTO/User/AuthorExpGrade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php /** @noinspection PhpPropertyOnlyWrittenInspection */
<?php

/** @noinspection PhpPropertyOnlyWrittenInspection */

namespace App\DTO\User;

Expand All @@ -9,10 +11,13 @@
readonly class AuthorExpGrade
{
public function __construct(
#[ORM\Column, ORM\Id] private int $uid,
#[ORM\Column] private int $discoveredAt,
#[ORM\Column] private int $authorExpGrade)
{}
#[ORM\Column, ORM\Id]
private int $uid,
#[ORM\Column]
private int $discoveredAt,
#[ORM\Column]
private int $authorExpGrade,
) {}

#[Ignore]
public function getUid(): int
Expand Down
15 changes: 10 additions & 5 deletions be/src/DTO/User/ForumModerator.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php /** @noinspection PhpPropertyOnlyWrittenInspection */
<?php

/** @noinspection PhpPropertyOnlyWrittenInspection */

namespace App\DTO\User;

Expand All @@ -9,10 +11,13 @@
readonly class ForumModerator
{
public function __construct(
#[ORM\Column, ORM\Id] private string $portrait,
#[ORM\Column] private int $discoveredAt,
#[ORM\Column] private string $moderatorTypes)
{}
#[ORM\Column, ORM\Id]
private string $portrait,
#[ORM\Column]
private int $discoveredAt,
#[ORM\Column]
private string $moderatorTypes,
) {}

#[Ignore]
public function getPortrait(): string
Expand Down
4 changes: 3 additions & 1 deletion be/src/Entity/Forum.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php /** @noinspection PhpPropertyOnlyWrittenInspection */
<?php

/** @noinspection PhpPropertyOnlyWrittenInspection */

namespace App\Entity;

Expand Down
4 changes: 3 additions & 1 deletion be/src/Entity/LatestReplier.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php /** @noinspection PhpPropertyOnlyWrittenInspection */
<?php

/** @noinspection PhpPropertyOnlyWrittenInspection */

namespace App\Entity;

Expand Down
4 changes: 3 additions & 1 deletion be/src/Entity/Post/Content/PostContent.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php /** @noinspection PhpPropertyOnlyWrittenInspection */
<?php

/** @noinspection PhpPropertyOnlyWrittenInspection */

namespace App\Entity\Post\Content;

Expand Down
4 changes: 3 additions & 1 deletion be/src/Entity/Post/Content/ReplyContent.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php /** @noinspection PhpPropertyOnlyWrittenInspection */
<?php

/** @noinspection PhpPropertyOnlyWrittenInspection */

namespace App\Entity\Post\Content;

Expand Down
4 changes: 3 additions & 1 deletion be/src/Entity/Post/Content/SubReplyContent.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php /** @noinspection PhpPropertyOnlyWrittenInspection */
<?php

/** @noinspection PhpPropertyOnlyWrittenInspection */

namespace App\Entity\Post\Content;

Expand Down
4 changes: 3 additions & 1 deletion be/src/Entity/Post/Post.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php /** @noinspection PhpPropertyOnlyWrittenInspection */
<?php

/** @noinspection PhpPropertyOnlyWrittenInspection */

namespace App\Entity\Post;

Expand Down
4 changes: 3 additions & 1 deletion be/src/Entity/Post/Reply.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php /** @noinspection PhpPropertyOnlyWrittenInspection */
<?php

/** @noinspection PhpPropertyOnlyWrittenInspection */

namespace App\Entity\Post;

Expand Down
8 changes: 4 additions & 4 deletions be/src/Entity/Post/SubReply.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php /** @noinspection PhpPropertyOnlyWrittenInspection */
<?php

/** @noinspection PhpPropertyOnlyWrittenInspection */

namespace App\Entity\Post;

Expand Down Expand Up @@ -34,7 +36,5 @@ public function getIsMatchQuery(): bool
return true;
}

public function setIsMatchQuery(bool $isMatchQuery): void
{
}
public function setIsMatchQuery(bool $isMatchQuery): void {}
}
4 changes: 3 additions & 1 deletion be/src/Entity/Post/Thread.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php /** @noinspection PhpPropertyOnlyWrittenInspection */
<?php

/** @noinspection PhpPropertyOnlyWrittenInspection */

namespace App\Entity\Post;

Expand Down
4 changes: 3 additions & 1 deletion be/src/Entity/Revision/AuthorExpGrade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php /** @noinspection PhpPropertyOnlyWrittenInspection */
<?php

/** @noinspection PhpPropertyOnlyWrittenInspection */

namespace App\Entity\Revision;

Expand Down
4 changes: 3 additions & 1 deletion be/src/Entity/Revision/ForumModerator.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php /** @noinspection PhpPropertyOnlyWrittenInspection */
<?php

/** @noinspection PhpPropertyOnlyWrittenInspection */

namespace App\Entity\Revision;

Expand Down
4 changes: 3 additions & 1 deletion be/src/Entity/TimestampedEntity.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php /** @noinspection PhpPropertyOnlyWrittenInspection */
<?php

/** @noinspection PhpPropertyOnlyWrittenInspection */

namespace App\Entity;

Expand Down
4 changes: 3 additions & 1 deletion be/src/Entity/User.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php /** @noinspection PhpPropertyOnlyWrittenInspection */
<?php

/** @noinspection PhpPropertyOnlyWrittenInspection */

namespace App\Entity;

Expand Down
4 changes: 2 additions & 2 deletions be/src/EventListener/ExceptionToJsonResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public function __invoke(ExceptionEvent $event): void
// https://github.com/symfony/serializer/blob/7.1/Normalizer/ConstraintViolationListNormalizer.php
$this->serializer->serialize([
'errorCode' => 40000,
'errorInfo' => $exception->getViolations()
], 'json')
'errorInfo' => $exception->getViolations(),
], 'json'),
));
}
}
Expand Down
2 changes: 1 addition & 1 deletion be/src/EventListener/SerializeToJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __construct(private SerializerInterface $serializer) {}
public function __invoke(ViewEvent $event): void
{
$event->setResponse(JsonResponse::fromJsonString(
$this->serializer->serialize($event->getControllerResult(), 'json')
$this->serializer->serialize($event->getControllerResult(), 'json'),
));
}
}
4 changes: 2 additions & 2 deletions be/src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function boot(): void
/** @see CollectionMacroServiceProvider::register() */
collect([
'recursive' => Recursive::class,
])->reject(fn ($class, $macro) => Collection::hasMacro($macro))
->each(fn ($class, $macro) => Collection::macro($macro, (new $class())()));
])->reject(fn($class, $macro) => Collection::hasMacro($macro))
->each(fn($class, $macro) => Collection::macro($macro, (new $class())()));
}
}
3 changes: 2 additions & 1 deletion be/src/PostsQuery/BaseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ protected function setResult(
$comparisons = $cursors->keys()->map(
fn(string $fieldName): Expr\Comparison => $this->orderByDesc
? $qb->expr()->lt("t.$fieldName", ":cursor_$fieldName")
: $qb->expr()->gt("t.$fieldName", ":cursor_$fieldName"));
: $qb->expr()->gt("t.$fieldName", ":cursor_$fieldName"),
);
$qb->andWhere($qb->expr()->orX(...$comparisons));
$cursors->mapWithKeys(fn($fieldValue, string $fieldName) =>
$qb->setParameter("cursor_$fieldName", $fieldValue)); // prevent overwriting existing param
Expand Down
2 changes: 1 addition & 1 deletion be/src/PostsQuery/IndexQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(
Stopwatch $stopwatch,
CursorCodec $cursorCodec,
private readonly PostRepositoryFactory $postRepositoryFactory,
private readonly ForumRepository $forumRepository
private readonly ForumRepository $forumRepository,
) {
parent::__construct($normalizer, $stopwatch, $cursorCodec, $postRepositoryFactory);
}
Expand Down
10 changes: 5 additions & 5 deletions be/src/PostsQuery/SearchQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct(
Stopwatch $stopwatch,
CursorCodec $cursorCodec,
private readonly PostRepositoryFactory $postRepositoryFactory,
private readonly UserRepository $userRepository
private readonly UserRepository $userRepository,
) {
parent::__construct($normalizer, $stopwatch, $cursorCodec, $postRepositoryFactory);
}
Expand Down Expand Up @@ -118,7 +118,7 @@ static function (QueryBuilder $newQueryWhenCacheMiss) use (&$outCachedUserQueryR
default => $query->andWhere(
"t.$fieldNameOfNumericParams "
. ($sub['not'] ? $inverseRangeOfNumericParams : $sub['range'])
. " :$sqlParamName"
. " :$sqlParamName",
)->setParameter($sqlParamName, $value),
},
// textMatch
Expand Down Expand Up @@ -146,7 +146,7 @@ static function (QueryBuilder $newQueryWhenCacheMiss) use (&$outCachedUserQueryR
$value,
$sub,
$sqlParamName,
))
)),
),
'authorGender', 'latestReplierGender' =>
$query->andWhere("t.{$userTypeOfUserParams}Uid $not IN (:$sqlParamName)")
Expand All @@ -155,7 +155,7 @@ static function (QueryBuilder $newQueryWhenCacheMiss) use (&$outCachedUserQueryR
$getAndCacheUserQuery($this->userRepository->createQueryBuilder('t')
->select('t.uid')
->andWhere("t.gender = :{$sqlParamName}_gender")
->setParameter("{$sqlParamName}_gender", $value))
->setParameter("{$sqlParamName}_gender", $value)),
),
'authorManagerType' =>
$value === 'NULL'
Expand Down Expand Up @@ -188,7 +188,7 @@ private static function applyTextMatchParamOnQuery(
}
$query = $query->setParameter(
"{$sqlParamName}_$keywordIndex",
$subParams['matchBy'] === 'implicit' ? "%$keyword%" : $keyword
$subParams['matchBy'] === 'implicit' ? "%$keyword%" : $keyword,
);
}
return $query;
Expand Down
6 changes: 4 additions & 2 deletions be/src/Repository/Post/PostRepository.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php /** @noinspection PhpMultipleClassDeclarationsInspection */
<?php

/** @noinspection PhpMultipleClassDeclarationsInspection */

namespace App\Repository\Post;

Expand Down Expand Up @@ -28,7 +30,7 @@ public function __construct(
) {
parent::__construct($registry, $postRepositoryClass);
$entityManager->getClassMetadata($postRepositoryClass)->setPrimaryTable([
'name' => "\"tbmc_f{$fid}_" . $this->getTableNameSuffix() . '"'
'name' => "\"tbmc_f{$fid}_" . $this->getTableNameSuffix() . '"',
]);
}

Expand Down
Loading

0 comments on commit 1725db5

Please sign in to comment.