Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 1 addition & 2 deletions src/APM/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public static function createForFailedCommand(CommandStartedEvent $startedEvent,
return $instance;
}

/** @param CommandSucceededEvent|CommandFailedEvent $finishedEvent */
private static function checkRequestIds(CommandStartedEvent $startedEvent, $finishedEvent): void
private static function checkRequestIds(CommandStartedEvent $startedEvent, CommandSucceededEvent|CommandFailedEvent $finishedEvent): void
{
if ($startedEvent->getRequestId() !== $finishedEvent->getRequestId()) {
throw new LogicException('Cannot create APM command for events with different request IDs');
Expand Down
6 changes: 1 addition & 5 deletions src/Aggregation/Stage.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@
*/
abstract class Stage
{
/** @var Builder */
protected $builder;

public function __construct(Builder $builder)
public function __construct(protected Builder $builder)
{
$this->builder = $builder;
}

/**
Expand Down
14 changes: 4 additions & 10 deletions src/Aggregation/Stage/AbstractBucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
*/
abstract class AbstractBucket extends Stage
{
/** @var Bucket\AbstractOutput|null */
protected $output;
protected ?Bucket\AbstractOutput $output = null;

/** @var Expr|array<string, mixed>|string */
protected $groupBy;
protected Expr|array|string $groupBy;

public function __construct(Builder $builder, private DocumentManager $dm, private ClassMetadata $class)
{
Expand All @@ -41,7 +40,7 @@ public function __construct(Builder $builder, private DocumentManager $dm, priva
*
* @param array<string, mixed>|Expr|string $expression
*/
public function groupBy($expression): static
public function groupBy(array|Expr|string $expression): static
{
$this->groupBy = $expression;

Expand Down Expand Up @@ -71,12 +70,7 @@ abstract protected function getExtraPipelineFields(): array;
*/
abstract protected function getStageName(): string;

/**
* @param array|mixed|string $expression
*
* @return array|mixed|string
*/
private function convertExpression($expression)
private function convertExpression(mixed $expression): mixed
{
if (is_array($expression)) {
return array_map($this->convertExpression(...), $expression);
Expand Down
11 changes: 3 additions & 8 deletions src/Aggregation/Stage/AbstractReplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
abstract class AbstractReplace extends Operator
{
/** @param string|mixed[]|Expr|null $expression */
final public function __construct(Builder $builder, protected DocumentManager $dm, protected ClassMetadata $class, protected $expression = null)
final public function __construct(Builder $builder, protected DocumentManager $dm, protected ClassMetadata $class, protected string|array|Expr|null $expression = null)
{
Operator::__construct($builder);
}
Expand All @@ -30,17 +30,12 @@ private function getDocumentPersister(): DocumentPersister
}

/** @return array<string, mixed>|string */
protected function getReplaceExpression()
protected function getReplaceExpression(): array|string
{
return $this->expression !== null ? $this->convertExpression($this->expression) : $this->expr->getExpression();
}

/**
* @param mixed[]|string|mixed $expression
*
* @return mixed[]|string|mixed
*/
private function convertExpression($expression)
private function convertExpression(mixed $expression): mixed
{
if (is_array($expression)) {
return array_map($this->convertExpression(...), $expression);
Expand Down
16 changes: 4 additions & 12 deletions src/Aggregation/Stage/Bucket/AbstractOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ abstract class AbstractOutput extends Stage implements GroupAccumulatorOperators
{
use ProvidesGroupAccumulatorOperators;

/** @var Stage\AbstractBucket */
protected $bucket;

private Expr $expr;

public function __construct(Builder $builder, Stage\AbstractBucket $bucket)
public function __construct(Builder $builder, protected Stage\AbstractBucket $bucket)
{
parent::__construct($builder);

$this->bucket = $bucket;
$this->expr = $builder->expr();
$this->expr = $builder->expr();
}

public function getExpression(): array
Expand All @@ -43,11 +39,9 @@ public function getExpression(): array
* @see https://docs.mongodb.com/manual/meta/aggregation-quick-reference/#aggregation-expressions
* @see Expr::expression
*
* @param mixed|Expr $value
*
* @return $this
*/
public function expression($value): static
public function expression(mixed $value): static
{
$this->expr->expression($value);

Expand All @@ -59,11 +53,9 @@ public function expression($value): static
*
* @see Expr::field
*
* @param string $fieldName
*
* @return $this
*/
public function field($fieldName): static
public function field(string $fieldName): static
{
$this->expr->field($fieldName);

Expand Down
11 changes: 0 additions & 11 deletions src/Aggregation/Stage/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Doctrine\ODM\MongoDB\Aggregation\Stage;

use Doctrine\ODM\MongoDB\Aggregation\Builder;
use Doctrine\ODM\MongoDB\Aggregation\Expr;
use Doctrine\ODM\MongoDB\Aggregation\Operator\GroupAccumulatorOperators;
use Doctrine\ODM\MongoDB\Aggregation\Operator\ProvidesGroupAccumulatorOperators;
Expand All @@ -18,16 +17,6 @@ class Group extends Operator implements GroupAccumulatorOperators
{
use ProvidesGroupAccumulatorOperators;

/** @var Expr */
protected $expr;

public function __construct(Builder $builder)
{
parent::__construct($builder);

$this->expr = $builder->expr();
}

/** @phpstan-return GroupStageExpression */
public function getExpression(): array
{
Expand Down
57 changes: 18 additions & 39 deletions src/Aggregation/Stage/MatchStage.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/
class MatchStage extends Stage
{
/** @var Expr */
protected $query;
protected Expr $query;

public function __construct(Builder $builder)
{
Expand All @@ -26,7 +25,7 @@ public function __construct(Builder $builder)
$this->query = $this->expr();
}

public function __clone()
public function __clone(): void
{
$this->query = clone $this->query;
}
Expand All @@ -43,7 +42,7 @@ public function __clone()
* @param mixed[]|Expr $expression
* @param mixed[]|Expr ...$expressions
*/
public function addAnd($expression, ...$expressions): static
public function addAnd(array|Expr $expression, array|Expr ...$expressions): static
{
$this->query->addAnd(...func_get_args());

Expand All @@ -62,7 +61,7 @@ public function addAnd($expression, ...$expressions): static
* @param mixed[]|Expr $expression
* @param mixed[]|Expr ...$expressions
*/
public function addNor($expression, ...$expressions): static
public function addNor(array|Expr $expression, array|Expr ...$expressions): static
{
$this->query->addNor(...func_get_args());

Expand All @@ -81,7 +80,7 @@ public function addNor($expression, ...$expressions): static
* @param mixed[]|Expr $expression
* @param mixed[]|Expr ...$expressions
*/
public function addOr($expression, ...$expressions): static
public function addOr(array|Expr $expression, array|Expr ...$expressions): static
{
$this->query->addOr(...func_get_args());

Expand Down Expand Up @@ -114,7 +113,7 @@ public function all(array $values): static
*
* @param mixed[]|Expr $expression
*/
public function elemMatch($expression): static
public function elemMatch(array|Expr $expression): static
{
$this->query->elemMatch($expression);

Expand All @@ -125,10 +124,8 @@ public function elemMatch($expression): static
* Specify an equality match for the current field.
*
* @see Expr::equals()
*
* @param mixed $value
*/
public function equals($value): static
public function equals(mixed $value): static
{
$this->query->equals($value);

Expand Down Expand Up @@ -180,7 +177,7 @@ public function field(string $field): static
*
* @param array<string, mixed>|Geometry $geometry
*/
public function geoIntersects($geometry): static
public function geoIntersects(array|Geometry $geometry): static
{
$this->query->geoIntersects($geometry);

Expand Down Expand Up @@ -272,7 +269,7 @@ public function geoWithinCenterSphere(float $x, float $y, float $radius): static
* @param array{int|float, int|float} $point3 Third point of the polygon
* @param array{int|float, int|float} ...$points Additional points of the polygon
*/
public function geoWithinPolygon($point1, $point2, $point3, ...$points): static
public function geoWithinPolygon(array $point1, array $point2, array $point3, array ...$points): static
{
$this->query->geoWithinPolygon(...func_get_args());

Expand All @@ -295,10 +292,8 @@ public function getExpression(): ?array
*
* @see Expr::gt()
* @see https://docs.mongodb.com/manual/reference/operator/gt/
*
* @param mixed $value
*/
public function gt($value): static
public function gt(mixed $value): static
{
$this->query->gt($value);

Expand All @@ -310,10 +305,8 @@ public function gt($value): static
*
* @see Expr::gte()
* @see https://docs.mongodb.com/manual/reference/operator/gte/
*
* @param mixed $value
*/
public function gte($value): static
public function gte(mixed $value): static
{
$this->query->gte($value);

Expand Down Expand Up @@ -362,10 +355,8 @@ public function language(string $language): static
*
* @see Expr::lte()
* @see https://docs.mongodb.com/manual/reference/operator/lte/
*
* @param mixed $value
*/
public function lt($value): static
public function lt(mixed $value): static
{
$this->query->lt($value);

Expand All @@ -377,10 +368,8 @@ public function lt($value): static
*
* @see Expr::lte()
* @see https://docs.mongodb.com/manual/reference/operator/lte/
*
* @param mixed $value
*/
public function lte($value): static
public function lte(mixed $value): static
{
$this->query->lte($value);

Expand All @@ -392,11 +381,8 @@ public function lte($value): static
*
* @see Expr::mod()
* @see https://docs.mongodb.com/manual/reference/operator/mod/
*
* @param float|int $divisor
* @param float|int $remainder
*/
public function mod($divisor, $remainder = 0): static
public function mod(float|int $divisor, float|int $remainder = 0): static
{
$this->query->mod($divisor, $remainder);

Expand All @@ -414,7 +400,7 @@ public function mod($divisor, $remainder = 0): static
*
* @param mixed[]|Expr $expression
*/
public function not($expression): static
public function not(array|Expr $expression): static
{
$this->query->not($expression);

Expand All @@ -426,10 +412,8 @@ public function not($expression): static
*
* @see Expr::notEqual()
* @see https://docs.mongodb.com/manual/reference/operator/ne/
*
* @param mixed $value
*/
public function notEqual($value): static
public function notEqual(mixed $value): static
{
$this->query->notEqual($value);

Expand Down Expand Up @@ -458,11 +442,8 @@ public function notIn(array $values): static
* and $lt criteria on the upper bound. The upper bound is not inclusive.
*
* @see Expr::range()
*
* @param mixed $start
* @param mixed $end
*/
public function range($start, $end): static
public function range(mixed $start, mixed $end): static
{
$this->query->range($start, $end);

Expand Down Expand Up @@ -511,10 +492,8 @@ public function text(string $search): static
*
* @see Expr::type()
* @see https://docs.mongodb.com/manual/reference/operator/type/
*
* @param int|string $type
*/
public function type($type): static
public function type(int|string $type): static
{
$this->query->type($type);

Expand Down
7 changes: 3 additions & 4 deletions src/Aggregation/Stage/Operator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ abstract class Operator extends Stage implements
TrigonometryOperators,
TypeOperators
{
/** @var Expr */
protected $expr;
protected Expr $expr;

public function __construct(Builder $builder)
{
Expand Down Expand Up @@ -94,7 +93,7 @@ public function add($expression1, $expression2, ...$expressions): static
* @param mixed[]|Expr $expression
* @param mixed[]|Expr ...$expressions
*/
public function addAnd($expression, ...$expressions): static
public function addAnd(array|Expr $expression, array|Expr ...$expressions): static
{
$this->expr->addAnd(...func_get_args());

Expand All @@ -110,7 +109,7 @@ public function addAnd($expression, ...$expressions): static
* @param mixed[]|Expr $expression
* @param mixed[]|Expr ...$expressions
*/
public function addOr($expression, ...$expressions): static
public function addOr(array|Expr $expression, array|Expr ...$expressions): static
{
$this->expr->addOr(...func_get_args());

Expand Down
Loading