Skip to content

Commit

Permalink
* fix all violations of phpcs rule
Browse files Browse the repository at this point in the history
* excluding rule `PSR12.ControlStructures.ControlStructureSpacing` @ .phpcs.xml
$ rm phpcs.xml.dist # should be deleted in 0302713
* fix phpunit error `Class App\Entity\Post\Post does not have a property named unguarded` @ `App\Tests\PostsQuery\BaseQueryTest->provideNestPostsWithParent()`
@ be
  • Loading branch information
n0099 committed Oct 9, 2024
1 parent 1725db5 commit 435dd5c
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 25 deletions.
1 change: 1 addition & 0 deletions be/.phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<!-- https://github.com/squizlabs/PHP_CodeSniffer/issues/3291 -->
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine"/>
<exclude name="Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore"/>
<exclude name="PSR12.ControlStructures.ControlStructureSpacing" />
</rule>
<arg name="extensions" value="php" />
<!-- https://github.com/squizlabs/PHP_CodeSniffer/issues/2242 -->
Expand Down
19 changes: 0 additions & 19 deletions be/phpcs.xml.dist

This file was deleted.

3 changes: 2 additions & 1 deletion be/src/Controller/PostsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public function __construct(
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
'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}$/',
)),
Expand Down
4 changes: 3 additions & 1 deletion be/src/EventListener/SerializeToJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Symfony\Component\Serializer\SerializerInterface;

#[AsEventListener(priority: -129)] // https://github.com/symfony/twig-bridge/blob/d63fde6a6142ffbab5fe6ee252b668b9485bfc0d/EventListener/TemplateAttributeListener.php#L66
// phpcs:disable Generic.Files.LineLength
// https://github.com/symfony/twig-bridge/blob/d63fde6a6142ffbab5fe6ee252b668b9485bfc0d/EventListener/TemplateAttributeListener.php#L66
#[AsEventListener(priority: -129)]
readonly class SerializeToJson
{
public function __construct(private SerializerInterface $serializer) {}
Expand Down
6 changes: 4 additions & 2 deletions be/src/PostsQuery/BaseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,15 @@ static function (string $postIDName) use ($result): array {
->where('t.pid IN (:pids)')->setParameter('pids', $allRepliesId)
->getQuery()->getResult())
->mapWithKeys(fn(ReplyContent $content) => [$content->getPid() => $content->getContent()]);
$replies->each(fn(Reply $reply) => $reply->setContent($replyContents->get($reply->getPid())));
$replies->each(fn(Reply $reply) =>
$reply->setContent($replyContents->get($reply->getPid())));

$subReplyContents = collect($this->postRepositoryFactory->newSubReplyContent($fid)->createQueryBuilder('t')
->where('t.spid IN (:spids)')->setParameter('spids', $spids)
->getQuery()->getResult())
->mapWithKeys(fn(SubReplyContent $content) => [$content->getSpid() => $content->getContent()]);
$subReplies->each(fn(SubReply $subReply) => $subReply->setContent($subReplyContents->get($subReply->getSpid())));
$subReplies->each(fn(SubReply $subReply) =>
$subReply->setContent($subReplyContents->get($subReply->getSpid())));
$this->stopwatch->stop('parsePostContentProtoBufBytes');

return [
Expand Down
9 changes: 8 additions & 1 deletion be/src/PostsQuery/SearchQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ static function (QueryBuilder $newQueryWhenCacheMiss) use (&$outCachedUserQueryR
'tid', 'pid', 'spid',
'authorUid', 'authorExpGrade', 'latestReplierUid',
'threadViewCount', 'threadShareCount', 'threadReplyCount', 'replySubReplyCount' =>
// phpcs:disable Generic.WhiteSpace.ScopeIndent
match ($sub['range']) {
'IN' => $query->andWhere("t.$fieldNameOfNumericParams $not IN (:$sqlParamName)")
->setParameter($sqlParamName, explode(',', $value)),
Expand All @@ -123,7 +124,13 @@ static function (QueryBuilder $newQueryWhenCacheMiss) use (&$outCachedUserQueryR
},
// textMatch
'threadTitle', 'postContent' =>
self::applyTextMatchParamOnQuery($query, $name === 'threadTitle' ? 'title' : 'content', $value, $sub, $sqlParamName),
self::applyTextMatchParamOnQuery(
$query,
$name === 'threadTitle' ? 'title' : 'content',
$value,
$sub,
$sqlParamName,
),
// dateTimeRange
'postedAt', 'latestReplyPostedAt' => $whereBetween($name),
// array
Expand Down
1 change: 0 additions & 1 deletion be/tests/PostsQuery/BaseQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Tests\PostsQuery;

use App\Entity\Post\Post;
use App\Entity\Post\Reply;
use App\Entity\Post\SubReply;
use App\Entity\Post\Thread;
Expand Down

0 comments on commit 435dd5c

Please sign in to comment.