From 435dd5c024cdb20ea83ce7a54924ad2db417e190 Mon Sep 17 00:00:00 2001 From: n0099 Date: Wed, 9 Oct 2024 18:57:18 +0000 Subject: [PATCH] * fix all violations of phpcs rule * excluding rule `PSR12.ControlStructures.ControlStructureSpacing` @ .phpcs.xml $ rm phpcs.xml.dist # should be deleted in 0302713d570b05bc0d2be37fe183eca2cf478cfc * fix phpunit error `Class App\Entity\Post\Post does not have a property named unguarded` @ `App\Tests\PostsQuery\BaseQueryTest->provideNestPostsWithParent()` @ be --- be/.phpcs.xml | 1 + be/phpcs.xml.dist | 19 ------------------- be/src/Controller/PostsController.php | 3 ++- be/src/EventListener/SerializeToJson.php | 4 +++- be/src/PostsQuery/BaseQuery.php | 6 ++++-- be/src/PostsQuery/SearchQuery.php | 9 ++++++++- be/tests/PostsQuery/BaseQueryTest.php | 1 - 7 files changed, 18 insertions(+), 25 deletions(-) delete mode 100644 be/phpcs.xml.dist diff --git a/be/.phpcs.xml b/be/.phpcs.xml index 0df55239..9ebf05dd 100644 --- a/be/.phpcs.xml +++ b/be/.phpcs.xml @@ -4,6 +4,7 @@ + diff --git a/be/phpcs.xml.dist b/be/phpcs.xml.dist deleted file mode 100644 index 89195e2b..00000000 --- a/be/phpcs.xml.dist +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - bin/ - config/ - public/ - src/ - tests/ - - diff --git a/be/src/Controller/PostsController.php b/be/src/Controller/PostsController.php index 1c32f3b1..461da3a6 100644 --- a/be/src/Controller/PostsController.php +++ b/be/src/Controller/PostsController.php @@ -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}$/', )), diff --git a/be/src/EventListener/SerializeToJson.php b/be/src/EventListener/SerializeToJson.php index 014615e8..5b600d86 100644 --- a/be/src/EventListener/SerializeToJson.php +++ b/be/src/EventListener/SerializeToJson.php @@ -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) {} diff --git a/be/src/PostsQuery/BaseQuery.php b/be/src/PostsQuery/BaseQuery.php index 2c7ecb19..94872988 100644 --- a/be/src/PostsQuery/BaseQuery.php +++ b/be/src/PostsQuery/BaseQuery.php @@ -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 [ diff --git a/be/src/PostsQuery/SearchQuery.php b/be/src/PostsQuery/SearchQuery.php index b5734a0b..64fe7520 100644 --- a/be/src/PostsQuery/SearchQuery.php +++ b/be/src/PostsQuery/SearchQuery.php @@ -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)), @@ -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 diff --git a/be/tests/PostsQuery/BaseQueryTest.php b/be/tests/PostsQuery/BaseQueryTest.php index 919c1208..4273c574 100644 --- a/be/tests/PostsQuery/BaseQueryTest.php +++ b/be/tests/PostsQuery/BaseQueryTest.php @@ -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;