Skip to content

Commit

Permalink
* merge all phpdoc with only one-line into single-line style
Browse files Browse the repository at this point in the history
* narrow the template of `EloquentBuilder<>` from `Model` to `Post` @ `App\Http\PostsQuery\IndexQuery->query()`
@ be
  • Loading branch information
n0099 committed Sep 16, 2024
1 parent 2e6af85 commit b2efba2
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 78 deletions.
4 changes: 1 addition & 3 deletions be/app/Eloquent/Model/Post/Content/PostContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions be/app/Eloquent/Model/Post/Reply.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,13 @@ protected function geolocation(): Attribute
return ModelAttributeMaker::makeProtoBufAttribute(Lbs::class);
}

/**
* @psalm-return BelongsTo<Thread>
*/
/** @psalm-return BelongsTo<Thread> */
public function thread(): BelongsTo
{
return $this->belongsTo(Thread::class, 'tid', 'tid');
}

/**
* @psalm-return HasMany<SubReply>
*/
/** @psalm-return HasMany<SubReply> */
public function subReplies(): HasMany
{
return $this->hasMany(SubReply::class, 'pid', 'pid');
Expand Down
8 changes: 2 additions & 6 deletions be/app/Eloquent/Model/Post/SubReply.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@ public function __construct(array $attributes = [])
];
}

/**
* @psalm-return BelongsTo<Thread>
*/
/** @psalm-return BelongsTo<Thread> */
public function thread(): BelongsTo
{
return $this->belongsTo(Thread::class, 'tid', 'tid');
}

/**
* @psalm-return BelongsTo<Reply>
*/
/** @psalm-return BelongsTo<Reply> */
public function reply(): BelongsTo
{
return $this->belongsTo(Reply::class, 'pid', 'pid');
Expand Down
4 changes: 1 addition & 3 deletions be/app/Eloquent/Model/Post/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ protected function geolocation(): Attribute
return ModelAttributeMaker::makeProtoBufAttribute(Lbs::class);
}

/**
* @psalm-return HasMany<Reply>
*/
/** @psalm-return HasMany<Reply> */
public function replies(): HasMany
{
return $this->hasMany(Reply::class, 'tid', 'tid');
Expand Down
8 changes: 2 additions & 6 deletions be/app/Eloquent/ModelAttributeMaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,9 +27,7 @@ public static function makeProtoBufAttribute(string $protoBufClass): Attribute
)->shouldCache();
}

/**
* @return Attribute<string, void>
*/
/** @return Attribute<string, void> */
public static function makeResourceAttribute(): Attribute
{
return Attribute::make(/**
Expand Down
12 changes: 3 additions & 9 deletions be/app/Eloquent/ModelHasPublicField.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@

use Illuminate\Database\Eloquent\Builder;

/**
* @template TModel
*/
/** @template TModel */
trait ModelHasPublicField
{
/**
* @var list<string>
*/
/** @var list<string> */
protected array $publicFields = [];

/**
* @var list<string>
*/
/** @var list<string> */
protected array $hiddenFields = [];

/**
Expand Down
4 changes: 1 addition & 3 deletions be/app/Eloquent/NullableBooleanAttributeCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions be/app/Http/Middleware/DumpJsonResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions be/app/Http/Middleware/ReCAPTCHACheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
12 changes: 3 additions & 9 deletions be/app/Http/PostsQuery/BaseQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ protected function setResult(
$this->debugbar->stopMeasure('setResult');
}

/**
* @param Collection<string, Post> $postsKeyByTypePluralName
*/
/** @param Collection<string, Post> $postsKeyByTypePluralName */
public function encodeNextCursor(Collection $postsKeyByTypePluralName): string

Check warning on line 116 in be/app/Http/PostsQuery/BaseQuery.php

View workflow job for this annotation

GitHub Actions / runs-on (windows-latest) / phpmd

BaseQuery.php: The method encodeNextCursor() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. (CyclomaticComplexity, Code Size Rules)
{
$encodedCursorsKeyByPostType = $postsKeyByTypePluralName
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<array-key, Collection>
*/
? /** @psalm-return Collection<array-key, Collection> */
static fn(Collection $posts): Collection => $posts
->map(fn(Collection $i) => $i->except('sortingKey'))
: static fn($i) => $i;
Expand Down
8 changes: 2 additions & 6 deletions be/app/Http/PostsQuery/IndexQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

class IndexQuery extends BaseQuery
{
/**
* @SuppressWarnings(PHPMD.ElseExpression)
*/
/** @SuppressWarnings(PHPMD.ElseExpression) */
public function query(QueryParams $params, ?string $cursor): self

Check warning on line 17 in be/app/Http/PostsQuery/IndexQuery.php

View workflow job for this annotation

GitHub Actions / runs-on (windows-latest) / phpmd

IndexQuery.php: The method query() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. (CyclomaticComplexity, Code Size Rules)

Check warning on line 17 in be/app/Http/PostsQuery/IndexQuery.php

View workflow job for this annotation

GitHub Actions / runs-on (windows-latest) / phpmd

IndexQuery.php: The method query() has an NPath complexity of 400. The configured NPath complexity threshold is 200. (NPathComplexity, Code Size Rules)
{
/** @var array<string, mixed> $flatParams key by param name */
Expand Down Expand Up @@ -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<Post>|QueryBuilder */
static fn(
?BuilderContract $acc,
EloquentBuilder|QueryBuilder $cur,
Expand Down
4 changes: 1 addition & 3 deletions be/app/Http/PostsQuery/ParamsValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ class ParamsValidator

protected array $currentPostTypes;

/**
* @param array[] $params
*/
/** @param array[] $params */
public function __construct(array $params)
{
self::validateParamsValue($params);
Expand Down
20 changes: 5 additions & 15 deletions be/app/Http/PostsQuery/QueryParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 = [
Expand Down
4 changes: 1 addition & 3 deletions be/app/Http/PostsQuery/SearchQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ static function (BuilderContract $newQueryWhenCacheMiss) use (&$outCachedUserQue
};
}

/**
* @psalm-param array<string, mixed> $subParams
*/
/** @psalm-param array<string, mixed> $subParams */
private static function applyTextMatchParamOnQuery(
BuilderContract $query,
string $field,
Expand Down

0 comments on commit b2efba2

Please sign in to comment.