3333 */
3434class Builder
3535{
36- /**
37- * The DocumentManager instance for this query
38- */
39- private DocumentManager $ dm ;
40-
4136 /**
4237 * The ClassMetadata instance.
4338 */
44- private ClassMetadata $ class ;
39+ private readonly ClassMetadata $ class ;
4540
4641 /** @var class-string */
4742 private ?string $ hydrationClass = null ;
4843
4944 /**
5045 * The Collection instance.
5146 */
52- private Collection $ collection ;
47+ private readonly Collection $ collection ;
5348
5449 /** @var Stage[] */
5550 private array $ stages = [];
@@ -61,9 +56,8 @@ class Builder
6156 *
6257 * @param class-string $documentName
6358 */
64- public function __construct (DocumentManager $ dm , string $ documentName )
59+ public function __construct (private readonly DocumentManager $ dm , string $ documentName )
6560 {
66- $ this ->dm = $ dm ;
6761 $ this ->class = $ this ->dm ->getClassMetadata ($ documentName );
6862 $ this ->collection = $ this ->dm ->getDocumentCollection ($ documentName );
6963 }
@@ -212,9 +206,8 @@ public function fill(): Stage\Fill
212206 * @see https://docs.mongodb.com/manual/reference/operator/aggregation/geoNear/
213207 *
214208 * @param float|array<string, mixed>|Point $x
215- * @param float $y
216209 */
217- public function geoNear ($ x , $ y = null ): Stage \GeoNear
210+ public function geoNear (float | array | Point $ x , ? float $ y = null ): Stage \GeoNear
218211 {
219212 $ stage = new Stage \GeoNear ($ this , $ x , $ y );
220213
@@ -491,7 +484,7 @@ public function redact(): Stage\Redact
491484 * @param string|mixed[]|Expr|null $expression Optional. A replacement expression that
492485 * resolves to a document.
493486 */
494- public function replaceRoot ($ expression = null ): Stage \ReplaceRoot
487+ public function replaceRoot (string | array | Expr | null $ expression = null ): Stage \ReplaceRoot
495488 {
496489 $ stage = new Stage \ReplaceRoot ($ this , $ this ->dm , $ this ->class , $ expression );
497490
@@ -511,7 +504,7 @@ public function replaceRoot($expression = null): Stage\ReplaceRoot
511504 * @param string|mixed[]|Expr|null $expression Optional. A replacement expression that
512505 * resolves to a document.
513506 */
514- public function replaceWith ($ expression = null ): Stage \ReplaceWith
507+ public function replaceWith (string | array | Expr | null $ expression = null ): Stage \ReplaceWith
515508 {
516509 $ stage = new Stage \ReplaceWith ($ this , $ this ->dm , $ this ->class , $ expression );
517510
@@ -608,7 +601,7 @@ public function skip(int $skip): Stage\Skip
608601 * @param int|string|null $order Field order (if one field is specified)
609602 * @phpstan-param SortShape|string $fieldName Field name or array of field/order pairs
610603 */
611- public function sort ($ fieldName , $ order = null ): Stage \Sort
604+ public function sort (array | string $ fieldName , int | string | null $ order = null ): Stage \Sort
612605 {
613606 $ fields = is_array ($ fieldName ) ? $ fieldName : [$ fieldName => $ order ];
614607 // fixme: move to sort stage
0 commit comments