Skip to content

PHPORM-316: Add annotations to query building classes #3415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
/**
* @method \MongoDB\Laravel\Query\Builder toBase()
* @template TModel of Model
* @extends EloquentBuilder<TModel>
*
* @mixin \MongoDB\Laravel\Query\Builder
*/
class Builder extends EloquentBuilder
{
Expand Down Expand Up @@ -69,7 +72,7 @@ class Builder extends EloquentBuilder
];

/**
* @return ($function is null ? AggregationBuilder : self)
* @return ($function is null ? AggregationBuilder : $this)
*
* @inheritdoc
*/
Expand Down
23 changes: 20 additions & 3 deletions src/Eloquent/DocumentModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@
use function strlen;
use function var_export;

/**
* @method static QueryBuilder query()
* @method static self sole(array $columns)
* @method static bool truncate()
* @method static QueryBuilder where(Closure|string|array|Expression $column, mixed $operator = null, mixed $value = null, string $boolean = 'and')
* @method static QueryBuilder whereBetween(string $column, iterable $values, string $boolean = null, bool $not = null)
* @method static QueryBuilder whereIn(...$parameters, mixed $values, string $boolean = null, bool $not = null)
* @method static QueryBuilder whereNot(array|Closure|Expression|string $column, $operator = null, $value = null, $boolean = 'and')
* @method static QueryBuilder whereNotIn(...$parameters)
* @method static QueryBuilder whereNotNull(...$parameters)
* @method static QueryBuilder whereNull(string $value)
* @mixin Eloquent
*/
trait DocumentModel
{
use HybridRelations;
Expand Down Expand Up @@ -553,8 +566,12 @@
return $this->parentRelation ?? null;
}

/** @inheritdoc */
public function newEloquentBuilder($query)
/**
* @param $query

Check failure on line 570 in src/Eloquent/DocumentModel.php

View workflow job for this annotation

GitHub Actions / phpcs

Missing parameter type
* @return Builder
*/
#[Override]
public function newEloquentBuilder($query): Builder
{
return new Builder($query);
}
Expand All @@ -566,7 +583,7 @@
}

/** @inheritdoc */
protected function newBaseQueryBuilder()
protected function newBaseQueryBuilder(): QueryBuilder
{
$connection = $this->getConnection();

Expand Down
4 changes: 0 additions & 4 deletions tests/Models/Anniversary.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@
use Illuminate\Database\Eloquent\Model;
use MongoDB\Laravel\Eloquent\DocumentModel;
use MongoDB\Laravel\Eloquent\Model as Eloquent;
use MongoDB\Laravel\Query\Builder;

/**
* @property string $name
* @property string $anniversary
* @mixin Eloquent
* @method static Builder create(...$values)
* @method static Builder truncate()
* @method static Eloquent sole(...$parameters)
*/
class Anniversary extends Model
{
Expand Down
6 changes: 0 additions & 6 deletions tests/Models/HiddenAnimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@

use Illuminate\Database\Eloquent\Model;
use MongoDB\Laravel\Eloquent\DocumentModel;
use MongoDB\Laravel\Eloquent\Model as Eloquent;
use MongoDB\Laravel\Query\Builder;

/**
* @property string $name
* @property string $country
* @property bool $can_be_eaten
* @mixin Eloquent
* @method static Builder create(...$values)
* @method static Builder truncate()
* @method static Eloquent sole(...$parameters)
*/
final class HiddenAnimal extends Model
{
Expand Down
Loading