From b2efba2bfa40db92519b6b5c03488f4443704fdc Mon Sep 17 00:00:00 2001 From: n0099 Date: Mon, 16 Sep 2024 05:34:41 +0000 Subject: [PATCH] * merge all phpdoc with only one-line into single-line style * narrow the template of `EloquentBuilder<>` from `Model` to `Post` @ `App\Http\PostsQuery\IndexQuery->query()` @ be --- .../Model/Post/Content/PostContent.php | 4 +--- be/app/Eloquent/Model/Post/Reply.php | 8 ++------ be/app/Eloquent/Model/Post/SubReply.php | 8 ++------ be/app/Eloquent/Model/Post/Thread.php | 4 +--- be/app/Eloquent/ModelAttributeMaker.php | 8 ++------ be/app/Eloquent/ModelHasPublicField.php | 12 +++-------- .../Eloquent/NullableBooleanAttributeCast.php | 4 +--- be/app/Http/Middleware/DumpJsonResponse.php | 4 +--- be/app/Http/Middleware/ReCAPTCHACheck.php | 4 +--- be/app/Http/PostsQuery/BaseQuery.php | 12 +++-------- be/app/Http/PostsQuery/IndexQuery.php | 8 ++------ be/app/Http/PostsQuery/ParamsValidator.php | 4 +--- be/app/Http/PostsQuery/QueryParams.php | 20 +++++-------------- be/app/Http/PostsQuery/SearchQuery.php | 4 +--- 14 files changed, 26 insertions(+), 78 deletions(-) diff --git a/be/app/Eloquent/Model/Post/Content/PostContent.php b/be/app/Eloquent/Model/Post/Content/PostContent.php index b1e923c7..7d8297e9 100644 --- a/be/app/Eloquent/Model/Post/Content/PostContent.php +++ b/be/app/Eloquent/Model/Post/Content/PostContent.php @@ -7,9 +7,7 @@ use Illuminate\Database\Eloquent\Casts\Attribute; use TbClient\Wrapper\PostContentWrapper; -/** - * @property string $protoBufBytes - */ +/** @property string $protoBufBytes */ abstract class PostContent extends Post { protected function protoBufBytes(): Attribute diff --git a/be/app/Eloquent/Model/Post/Reply.php b/be/app/Eloquent/Model/Post/Reply.php index 03d31a74..180da91e 100644 --- a/be/app/Eloquent/Model/Post/Reply.php +++ b/be/app/Eloquent/Model/Post/Reply.php @@ -47,17 +47,13 @@ protected function geolocation(): Attribute return ModelAttributeMaker::makeProtoBufAttribute(Lbs::class); } - /** - * @psalm-return BelongsTo - */ + /** @psalm-return BelongsTo */ public function thread(): BelongsTo { return $this->belongsTo(Thread::class, 'tid', 'tid'); } - /** - * @psalm-return HasMany - */ + /** @psalm-return HasMany */ public function subReplies(): HasMany { return $this->hasMany(SubReply::class, 'pid', 'pid'); diff --git a/be/app/Eloquent/Model/Post/SubReply.php b/be/app/Eloquent/Model/Post/SubReply.php index e2eb11a2..65b02ad1 100644 --- a/be/app/Eloquent/Model/Post/SubReply.php +++ b/be/app/Eloquent/Model/Post/SubReply.php @@ -32,17 +32,13 @@ public function __construct(array $attributes = []) ]; } - /** - * @psalm-return BelongsTo - */ + /** @psalm-return BelongsTo */ public function thread(): BelongsTo { return $this->belongsTo(Thread::class, 'tid', 'tid'); } - /** - * @psalm-return BelongsTo - */ + /** @psalm-return BelongsTo */ public function reply(): BelongsTo { return $this->belongsTo(Reply::class, 'pid', 'pid'); diff --git a/be/app/Eloquent/Model/Post/Thread.php b/be/app/Eloquent/Model/Post/Thread.php index 156d5385..ecccc085 100644 --- a/be/app/Eloquent/Model/Post/Thread.php +++ b/be/app/Eloquent/Model/Post/Thread.php @@ -62,9 +62,7 @@ protected function geolocation(): Attribute return ModelAttributeMaker::makeProtoBufAttribute(Lbs::class); } - /** - * @psalm-return HasMany - */ + /** @psalm-return HasMany */ public function replies(): HasMany { return $this->hasMany(Reply::class, 'tid', 'tid'); diff --git a/be/app/Eloquent/ModelAttributeMaker.php b/be/app/Eloquent/ModelAttributeMaker.php index f8a83d58..611f6a64 100644 --- a/be/app/Eloquent/ModelAttributeMaker.php +++ b/be/app/Eloquent/ModelAttributeMaker.php @@ -14,9 +14,7 @@ class ModelAttributeMaker */ public static function makeProtoBufAttribute(string $protoBufClass): Attribute { - return Attribute::make(/** - * @param resource|null $value - */ + return Attribute::make(/** @param resource|null $value */ get: static function ($value) use ($protoBufClass): ?\stdClass { if ($value === null) { return null; @@ -29,9 +27,7 @@ public static function makeProtoBufAttribute(string $protoBufClass): Attribute )->shouldCache(); } - /** - * @return Attribute - */ + /** @return Attribute */ public static function makeResourceAttribute(): Attribute { return Attribute::make(/** diff --git a/be/app/Eloquent/ModelHasPublicField.php b/be/app/Eloquent/ModelHasPublicField.php index 0fa67f12..4409309e 100644 --- a/be/app/Eloquent/ModelHasPublicField.php +++ b/be/app/Eloquent/ModelHasPublicField.php @@ -4,19 +4,13 @@ use Illuminate\Database\Eloquent\Builder; -/** - * @template TModel - */ +/** @template TModel */ trait ModelHasPublicField { - /** - * @var list - */ + /** @var list */ protected array $publicFields = []; - /** - * @var list - */ + /** @var list */ protected array $hiddenFields = []; /** diff --git a/be/app/Eloquent/NullableBooleanAttributeCast.php b/be/app/Eloquent/NullableBooleanAttributeCast.php index 2a909bd9..f6c082e8 100644 --- a/be/app/Eloquent/NullableBooleanAttributeCast.php +++ b/be/app/Eloquent/NullableBooleanAttributeCast.php @@ -11,9 +11,7 @@ public function get($model, string $key, $value, array $attributes): bool return $value === 1; } - /** - * @psalm-return 0|1 - */ + /** @psalm-return 0|1 */ public function set($model, string $key, $value, array $attributes): int { \is_bool($value) || $value = (bool) $value; diff --git a/be/app/Http/Middleware/DumpJsonResponse.php b/be/app/Http/Middleware/DumpJsonResponse.php index 8d5aa01e..e190a45e 100644 --- a/be/app/Http/Middleware/DumpJsonResponse.php +++ b/be/app/Http/Middleware/DumpJsonResponse.php @@ -7,9 +7,7 @@ class DumpJsonResponse { - /** - * @param \Closure(Request): (\Symfony\Component\HttpFoundation\Response) $next - */ + /** @param \Closure(Request): (\Symfony\Component\HttpFoundation\Response) $next */ public function handle(Request $request, \Closure $next): mixed { $response = $next($request); diff --git a/be/app/Http/Middleware/ReCAPTCHACheck.php b/be/app/Http/Middleware/ReCAPTCHACheck.php index 0171b015..6a808a09 100644 --- a/be/app/Http/Middleware/ReCAPTCHACheck.php +++ b/be/app/Http/Middleware/ReCAPTCHACheck.php @@ -9,9 +9,7 @@ class ReCAPTCHACheck { - /** - * @param \Closure(Request): (\Symfony\Component\HttpFoundation\Response) $next - */ + /** @param \Closure(Request): (\Symfony\Component\HttpFoundation\Response) $next */ public function handle(Request $request, \Closure $next): mixed { /** @var string $secret */ diff --git a/be/app/Http/PostsQuery/BaseQuery.php b/be/app/Http/PostsQuery/BaseQuery.php index b1e5c69b..ac0a29df 100644 --- a/be/app/Http/PostsQuery/BaseQuery.php +++ b/be/app/Http/PostsQuery/BaseQuery.php @@ -112,9 +112,7 @@ protected function setResult( $this->debugbar->stopMeasure('setResult'); } - /** - * @param Collection $postsKeyByTypePluralName - */ + /** @param Collection $postsKeyByTypePluralName */ public function encodeNextCursor(Collection $postsKeyByTypePluralName): string { $encodedCursorsKeyByPostType = $postsKeyByTypePluralName @@ -169,9 +167,7 @@ public function encodeNextCursor(Collection $postsKeyByTypePluralName): string ->join(','); } - /** - * @psalm-return Collection<'reply'|'subReply'|'thread', Cursor> - */ + /** @psalm-return Collection<'reply'|'subReply'|'thread', Cursor> */ private function decodeCursor(string $encodedCursors): Collection { return collect(Helper::POST_TYPES) @@ -398,9 +394,7 @@ public function reOrderNestedPosts(Collection $nestedPosts, bool $shouldRemoveSo $sortBySortingKey = fn(Collection $posts): Collection => $posts ->sortBy(fn(Collection $i) => $i['sortingKey'], descending: $this->orderByDesc); $removeSortingKey = $shouldRemoveSortingKey - ? /** - * @psalm-return Collection - */ + ? /** @psalm-return Collection */ static fn(Collection $posts): Collection => $posts ->map(fn(Collection $i) => $i->except('sortingKey')) : static fn($i) => $i; diff --git a/be/app/Http/PostsQuery/IndexQuery.php b/be/app/Http/PostsQuery/IndexQuery.php index 5f78ce6b..ba8e3a56 100644 --- a/be/app/Http/PostsQuery/IndexQuery.php +++ b/be/app/Http/PostsQuery/IndexQuery.php @@ -13,9 +13,7 @@ class IndexQuery extends BaseQuery { - /** - * @SuppressWarnings(PHPMD.ElseExpression) - */ + /** @SuppressWarnings(PHPMD.ElseExpression) */ public function query(QueryParams $params, ?string $cursor): self { /** @var array $flatParams key by param name */ @@ -48,9 +46,7 @@ public function query(QueryParams $params, ?string $cursor): self PostFactory::getPostModelsByFid($fid)[Helper::POST_ID_TO_TYPE[$postIDName]] ->selectRaw("{$fid} AS fid, COUNT(*) AS count") ->where($postIDName, $postID)) - ->reduce(/** - * @return BuilderContract|EloquentBuilder<\Illuminate\Database\Eloquent\Model>|QueryBuilder - */ + ->reduce(/** @return BuilderContract|EloquentBuilder|QueryBuilder */ static fn( ?BuilderContract $acc, EloquentBuilder|QueryBuilder $cur, diff --git a/be/app/Http/PostsQuery/ParamsValidator.php b/be/app/Http/PostsQuery/ParamsValidator.php index 254bbf19..122339b0 100644 --- a/be/app/Http/PostsQuery/ParamsValidator.php +++ b/be/app/Http/PostsQuery/ParamsValidator.php @@ -14,9 +14,7 @@ class ParamsValidator protected array $currentPostTypes; - /** - * @param array[] $params - */ + /** @param array[] $params */ public function __construct(array $params) { self::validateParamsValue($params); diff --git a/be/app/Http/PostsQuery/QueryParams.php b/be/app/Http/PostsQuery/QueryParams.php index 7521e3d3..2eaff98a 100644 --- a/be/app/Http/PostsQuery/QueryParams.php +++ b/be/app/Http/PostsQuery/QueryParams.php @@ -6,22 +6,16 @@ class QueryParams { - /** - * @var Param[] - */ + /** @var Param[] */ protected array $params; - /** - * @param array[] $params - */ + /** @param array[] $params */ public function __construct(array $params) { $this->params = array_map(static fn($p) => new Param($p), $params); } - /** - * @psalm-return int<0, max> - */ + /** @psalm-return int<0, max> */ public function count(): int { return count($this->params); @@ -62,17 +56,13 @@ public function setUniqueParamValue(string $name, mixed $value): void $this->params[$this->getParamsIndexByName($name)[0]]->value = $value; } - /** - * @return int[] - */ + /** @return int[] */ protected function getParamsIndexByName(string $name): array { return array_keys(array_filter($this->params, static fn($p) => $p->name === $name)); } - /** - * @SuppressWarnings(PHPMD.ElseExpression) - */ + /** @SuppressWarnings(PHPMD.ElseExpression) */ public function addDefaultValueOnUniqueParams(): void { $uniqueParamsDefaultValue = [ diff --git a/be/app/Http/PostsQuery/SearchQuery.php b/be/app/Http/PostsQuery/SearchQuery.php index f59ac3a7..70d60fd1 100644 --- a/be/app/Http/PostsQuery/SearchQuery.php +++ b/be/app/Http/PostsQuery/SearchQuery.php @@ -134,9 +134,7 @@ static function (BuilderContract $newQueryWhenCacheMiss) use (&$outCachedUserQue }; } - /** - * @psalm-param array $subParams - */ + /** @psalm-param array $subParams */ private static function applyTextMatchParamOnQuery( BuilderContract $query, string $field,