Skip to content

Commit

Permalink
Use this return type for builders @methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bastien-phi committed Jan 3, 2025
1 parent e153691 commit cffd1b6
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 70 deletions.
13 changes: 5 additions & 8 deletions src/Domain/Models/Output/QueryBuilderDocBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ private function attributeScopes(): Collection
->onlyInDatabase(true)
->toBase()
->map(fn (Attribute $attribute): string => sprintf(
' * @method %s where%s(%s $value)',
$this->model->queryBuilder->fqcn,
' * @method $this where%s(%s $value)',
Str::studly($attribute->name),
$this->attributeScopeValueType($attribute)
));
Expand Down Expand Up @@ -102,7 +101,7 @@ private function scopeMethods(): Collection
{
return collect($this->model->scopes)
->flatMap(fn (Method $scope): array => array_filter([
$scope->returnType($this->model->queryBuilder->fqcn)->toDocTag(),
$scope->returnType('$this')->toDocTag(),
$scope->toLinkTag(),
]));
}
Expand Down Expand Up @@ -145,13 +144,11 @@ private function resultMethods(): Collection
*/
private function softDeletesMethods(): Collection
{
$builder = $this->model->queryBuilder->fqcn;

return Collection::make([
'int restore()',
"{$builder} withTrashed(bool \$withTrashed = true)",
"{$builder} withoutTrashed()",
"{$builder} onlyTrashed()",
'$this withTrashed(bool $withTrashed = true)',
'$this withoutTrashed()',
'$this onlyTrashed()',
])
->map(static fn (string $method) => " * @method {$method}");
}
Expand Down
28 changes: 14 additions & 14 deletions tests/expected/PostQuery.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ namespace Soyhuce\NextIdeHelper\Tests\Fixtures\Blog;
use Illuminate\Database\Eloquent\Builder;

/**
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereId(int|string $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereTitle(string $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereSubtitle(string|null $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereContent(string $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereUserId(int|string $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereLikes(int|string $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereAddress(\Soyhuce\NextIdeHelper\Tests\Fixtures\Address|string|null $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereMetas(array<int,string>|string|null $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereCreatedAt(\Carbon\CarbonInterface|string $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereUpdatedAt(\Illuminate\Support\Carbon|string $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereDeletedAt(\Illuminate\Support\Carbon|string|null $value)
* @method $this whereId(int|string $value)
* @method $this whereTitle(string $value)
* @method $this whereSubtitle(string|null $value)
* @method $this whereContent(string $value)
* @method $this whereUserId(int|string $value)
* @method $this whereLikes(int|string $value)
* @method $this whereAddress(\Soyhuce\NextIdeHelper\Tests\Fixtures\Address|string|null $value)
* @method $this whereMetas(array<int,string>|string|null $value)
* @method $this whereCreatedAt(\Carbon\CarbonInterface|string $value)
* @method $this whereUpdatedAt(\Illuminate\Support\Carbon|string $value)
* @method $this whereDeletedAt(\Illuminate\Support\Carbon|string|null $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\Post create(array $attributes = [])
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostCollection|\Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\Post|null find($id, array $columns = ['*'])
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostCollection findMany($id, array $columns = ['*'])
Expand All @@ -33,8 +33,8 @@ use Illuminate\Database\Eloquent\Builder;
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\Post sole(array|string $columns = ['*'])
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\Post updateOrCreate(array $attributes, array $values = [])
* @method int restore()
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery withTrashed(bool $withTrashed = true)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery withoutTrashed()
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery onlyTrashed()
* @method $this withTrashed(bool $withTrashed = true)
* @method $this withoutTrashed()
* @method $this onlyTrashed()
*/
class PostQuery extends Builder {}
28 changes: 14 additions & 14 deletions tests/expected/PostQueryLarastan.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ namespace Soyhuce\NextIdeHelper\Tests\Fixtures\Blog;
use Illuminate\Database\Eloquent\Builder;

/**
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereId(int|string $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereTitle(string $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereSubtitle(string|null $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereContent(string $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereUserId(int|string $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereLikes(string $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereAddress(string|null $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereMetas(array|string|null $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereCreatedAt(\Illuminate\Support\Carbon|string $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereUpdatedAt(\Illuminate\Support\Carbon|string $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery whereDeletedAt(\Illuminate\Support\Carbon|string|null $value)
* @method $this whereId(int|string $value)
* @method $this whereTitle(string $value)
* @method $this whereSubtitle(string|null $value)
* @method $this whereContent(string $value)
* @method $this whereUserId(int|string $value)
* @method $this whereLikes(string $value)
* @method $this whereAddress(string|null $value)
* @method $this whereMetas(array|string|null $value)
* @method $this whereCreatedAt(\Illuminate\Support\Carbon|string $value)
* @method $this whereUpdatedAt(\Illuminate\Support\Carbon|string $value)
* @method $this whereDeletedAt(\Illuminate\Support\Carbon|string|null $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\Post create(array $attributes = [])
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostCollection<int, \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\Post>|\Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\Post|null find($id, array $columns = ['*'])
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostCollection<int, \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\Post> findMany($id, array $columns = ['*'])
Expand All @@ -33,9 +33,9 @@ use Illuminate\Database\Eloquent\Builder;
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\Post sole(array|string $columns = ['*'])
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\Post updateOrCreate(array $attributes, array $values = [])
* @method int restore()
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery withTrashed(bool $withTrashed = true)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery withoutTrashed()
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\PostQuery onlyTrashed()
* @method $this withTrashed(bool $withTrashed = true)
* @method $this withoutTrashed()
* @method $this onlyTrashed()
* @template TModelClass of \Soyhuce\NextIdeHelper\Tests\Fixtures\Blog\Post
* @extends \Illuminate\Database\Eloquent\Builder<TModelClass>
*/
Expand Down
34 changes: 17 additions & 17 deletions tests/expected/_ide_models.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures
{
/**
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__CommentQuery whereId(int|string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__CommentQuery whereContent(string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__CommentQuery whereCommentableType(string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__CommentQuery whereCommentableId(int|string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__CommentQuery whereCreatedAt(\Illuminate\Support\Carbon|string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__CommentQuery whereUpdatedAt(\Illuminate\Support\Carbon|string $value)
* @method $this whereId(int|string $value)
* @method $this whereContent(string $value)
* @method $this whereCommentableType(string $value)
* @method $this whereCommentableId(int|string $value)
* @method $this whereCreatedAt(\Illuminate\Support\Carbon|string $value)
* @method $this whereUpdatedAt(\Illuminate\Support\Carbon|string $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Comment create(array $attributes = [])
* @method \Illuminate\Database\Eloquent\Collection|\Soyhuce\NextIdeHelper\Tests\Fixtures\Comment|null find($id, array $columns = ['*'])
* @method \Illuminate\Database\Eloquent\Collection findMany($id, array $columns = ['*'])
Expand All @@ -31,17 +31,17 @@ namespace IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures
}

/**
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereId(int|string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereEmail(string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery wherePassword(string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereAddress(\Soyhuce\NextIdeHelper\Tests\Fixtures\Address|string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereName(string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereRole(\Soyhuce\NextIdeHelper\Tests\Fixtures\Role|string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereNullableName(string|null $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereRememberToken(string|null $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereCreatedAt(\Illuminate\Support\Carbon|string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereUpdatedAt(\Carbon\CarbonImmutable|string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereEmailDomain(string $domain, ?string $area = null)
* @method $this whereId(int|string $value)
* @method $this whereEmail(string $value)
* @method $this wherePassword(string $value)
* @method $this whereAddress(\Soyhuce\NextIdeHelper\Tests\Fixtures\Address|string $value)
* @method $this whereName(string $value)
* @method $this whereRole(\Soyhuce\NextIdeHelper\Tests\Fixtures\Role|string $value)
* @method $this whereNullableName(string|null $value)
* @method $this whereRememberToken(string|null $value)
* @method $this whereCreatedAt(\Illuminate\Support\Carbon|string $value)
* @method $this whereUpdatedAt(\Carbon\CarbonImmutable|string $value)
* @method $this whereEmailDomain(string $domain, ?string $area = null)
* @see project://Fixtures/User.php L76
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\User create(array $attributes = [])
* @method \Illuminate\Database\Eloquent\Collection|\Soyhuce\NextIdeHelper\Tests\Fixtures\User|null find($id, array $columns = ['*'])
Expand Down
34 changes: 17 additions & 17 deletions tests/expected/_ide_modelsLarastan.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures
{
/**
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__CommentQuery whereId(int|string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__CommentQuery whereContent(string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__CommentQuery whereCommentableType(string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__CommentQuery whereCommentableId(int|string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__CommentQuery whereCreatedAt(\Illuminate\Support\Carbon|string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__CommentQuery whereUpdatedAt(\Illuminate\Support\Carbon|string $value)
* @method $this whereId(int|string $value)
* @method $this whereContent(string $value)
* @method $this whereCommentableType(string $value)
* @method $this whereCommentableId(int|string $value)
* @method $this whereCreatedAt(\Illuminate\Support\Carbon|string $value)
* @method $this whereUpdatedAt(\Illuminate\Support\Carbon|string $value)
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\Comment create(array $attributes = [])
* @method \Illuminate\Database\Eloquent\Collection<int, \Soyhuce\NextIdeHelper\Tests\Fixtures\Comment>|\Soyhuce\NextIdeHelper\Tests\Fixtures\Comment|null find($id, array $columns = ['*'])
* @method \Illuminate\Database\Eloquent\Collection<int, \Soyhuce\NextIdeHelper\Tests\Fixtures\Comment> findMany($id, array $columns = ['*'])
Expand All @@ -33,17 +33,17 @@ namespace IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures
}

/**
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereId(int|string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereEmail(string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery wherePassword(string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereAddress(\Soyhuce\NextIdeHelper\Tests\Fixtures\Address|string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereName(string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereRole(\Soyhuce\NextIdeHelper\Tests\Fixtures\Role|string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereNullableName(string|null $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereRememberToken(string|null $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereCreatedAt(\Illuminate\Support\Carbon|string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereUpdatedAt(\Carbon\CarbonImmutable|string $value)
* @method \IdeHelper\Soyhuce\NextIdeHelper\Tests\Fixtures\__UserQuery whereEmailDomain(string $domain, ?string $area = null)
* @method $this whereId(int|string $value)
* @method $this whereEmail(string $value)
* @method $this wherePassword(string $value)
* @method $this whereAddress(\Soyhuce\NextIdeHelper\Tests\Fixtures\Address|string $value)
* @method $this whereName(string $value)
* @method $this whereRole(\Soyhuce\NextIdeHelper\Tests\Fixtures\Role|string $value)
* @method $this whereNullableName(string|null $value)
* @method $this whereRememberToken(string|null $value)
* @method $this whereCreatedAt(\Illuminate\Support\Carbon|string $value)
* @method $this whereUpdatedAt(\Carbon\CarbonImmutable|string $value)
* @method $this whereEmailDomain(string $domain, ?string $area = null)
* @see project://Fixtures/User.php L76
* @method \Soyhuce\NextIdeHelper\Tests\Fixtures\User create(array $attributes = [])
* @method \Illuminate\Database\Eloquent\Collection<int, \Soyhuce\NextIdeHelper\Tests\Fixtures\User>|\Soyhuce\NextIdeHelper\Tests\Fixtures\User|null find($id, array $columns = ['*'])
Expand Down

0 comments on commit cffd1b6

Please sign in to comment.