Skip to content

Commit 7abdc70

Browse files
authored
Fix return type of compound search operators (#2836)
* Fix return type of compound search operators * Improve array type for geometries
1 parent cb1f717 commit 7abdc70

File tree

6 files changed

+67
-265
lines changed

6 files changed

+67
-265
lines changed

lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/CompoundSearchOperatorInterface.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
namespace Doctrine\ODM\MongoDB\Aggregation\Stage\Search;
66

7+
use GeoJson\Geometry\LineString;
8+
use GeoJson\Geometry\MultiPolygon;
9+
use GeoJson\Geometry\Point;
10+
use GeoJson\Geometry\Polygon;
11+
use MongoDB\BSON\ObjectId;
12+
use MongoDB\BSON\UTCDateTime;
13+
714
interface CompoundSearchOperatorInterface extends SupportsCompoundableSearchOperators
815
{
916
public function must(): Compound;
@@ -13,4 +20,39 @@ public function mustNot(): Compound;
1320
public function should(?int $minimumShouldMatch = null): Compound;
1421

1522
public function filter(): Compound;
23+
24+
public function autocomplete(string $path = '', string ...$query): Autocomplete&CompoundSearchOperatorInterface;
25+
26+
public function embeddedDocument(string $path = ''): EmbeddedDocument&CompoundSearchOperatorInterface;
27+
28+
/** @param string|int|float|ObjectId|UTCDateTime|null $value */
29+
public function equals(string $path = '', $value = null): Equals&CompoundSearchOperatorInterface;
30+
31+
public function exists(string $path): Exists&CompoundSearchOperatorInterface;
32+
33+
/** @param LineString|Point|Polygon|MultiPolygon|array<string, mixed>|null $geometry */
34+
public function geoShape($geometry = null, string $relation = '', string ...$path): GeoShape&CompoundSearchOperatorInterface;
35+
36+
public function geoWithin(string ...$path): GeoWithin&CompoundSearchOperatorInterface;
37+
38+
/** @param array<string, mixed>|object $documents */
39+
public function moreLikeThis(...$documents): MoreLikeThis&CompoundSearchOperatorInterface;
40+
41+
/**
42+
* @param int|float|UTCDateTime|array<string, mixed>|Point|null $origin
43+
* @param int|float|null $pivot
44+
*/
45+
public function near($origin = null, $pivot = null, string ...$path): Near&CompoundSearchOperatorInterface;
46+
47+
public function phrase(): Phrase&CompoundSearchOperatorInterface;
48+
49+
public function queryString(string $query = '', string $defaultPath = ''): QueryString&CompoundSearchOperatorInterface;
50+
51+
public function range(): Range&CompoundSearchOperatorInterface;
52+
53+
public function regex(): Regex&CompoundSearchOperatorInterface;
54+
55+
public function text(): Text&CompoundSearchOperatorInterface;
56+
57+
public function wildcard(): Wildcard&CompoundSearchOperatorInterface;
1658
}

lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/SupportsAllSearchOperatorsTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function exists(string $path): Exists
5252
return $this->addOperator(new Exists($this->getSearchStage(), $path));
5353
}
5454

55-
/** @param LineString|Point|Polygon|MultiPolygon|array|null $geometry */
55+
/** @param LineString|Point|Polygon|MultiPolygon|array<string, mixed>|null $geometry */
5656
public function geoShape($geometry = null, string $relation = '', string ...$path): GeoShape
5757
{
5858
return $this->addOperator(new GeoShape($this->getSearchStage(), $geometry, $relation, ...$path));
@@ -70,8 +70,8 @@ public function moreLikeThis(...$documents): MoreLikeThis
7070
}
7171

7272
/**
73-
* @param int|float|UTCDateTime|array|Point|null $origin
74-
* @param int|float|null $pivot
73+
* @param int|float|UTCDateTime|array<string, mixed>|Point|null $origin
74+
* @param int|float|null $pivot
7575
*/
7676
public function near($origin = null, $pivot = null, string ...$path): Near
7777
{

lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/SupportsCompoundableOperatorsTrait.php

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -45,103 +45,79 @@ abstract protected function getAddOperatorClosure(): Closure;
4545
*/
4646
abstract protected function addOperator(SearchOperator $operator): SearchOperator;
4747

48-
/** return Autocomplete&CompoundSearchOperatorInterface */
49-
public function autocomplete(string $path = '', string ...$query): Autocomplete
48+
public function autocomplete(string $path = '', string ...$query): Autocomplete&CompoundSearchOperatorInterface
5049
{
5150
return $this->addOperator(new CompoundedAutocomplete($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), $path, ...$query));
5251
}
5352

54-
/** @return EmbeddedDocument&CompoundSearchOperatorInterface */
55-
public function embeddedDocument(string $path = ''): EmbeddedDocument
53+
public function embeddedDocument(string $path = ''): EmbeddedDocument&CompoundSearchOperatorInterface
5654
{
5755
return $this->addOperator(new CompoundedEmbeddedDocument($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), $path));
5856
}
5957

60-
/**
61-
* @param string|int|float|ObjectId|UTCDateTime|null $value
62-
*
63-
* @return Equals&CompoundSearchOperatorInterface
64-
*/
65-
public function equals(string $path = '', $value = null): Equals
58+
/** @param string|int|float|ObjectId|UTCDateTime|null $value */
59+
public function equals(string $path = '', $value = null): Equals&CompoundSearchOperatorInterface
6660
{
6761
return $this->addOperator(new CompoundedEquals($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), $path, $value));
6862
}
6963

70-
/** @return Exists&CompoundSearchOperatorInterface */
71-
public function exists(string $path): Exists
64+
public function exists(string $path): Exists&CompoundSearchOperatorInterface
7265
{
7366
return $this->addOperator(new CompoundedExists($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), $path));
7467
}
7568

76-
/**
77-
* @param LineString|Point|Polygon|MultiPolygon|array|null $geometry
78-
*
79-
* @return GeoShape&CompoundSearchOperatorInterface
80-
*/
81-
public function geoShape($geometry = null, string $relation = '', string ...$path): GeoShape
69+
/** @param LineString|Point|Polygon|MultiPolygon|array<string, mixed>|null $geometry */
70+
public function geoShape($geometry = null, string $relation = '', string ...$path): GeoShape&CompoundSearchOperatorInterface
8271
{
8372
return $this->addOperator(new CompoundedGeoShape($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), $geometry, $relation, ...$path));
8473
}
8574

86-
/** @return GeoWithin&CompoundSearchOperatorInterface */
87-
public function geoWithin(string ...$path): GeoWithin
75+
public function geoWithin(string ...$path): GeoWithin&CompoundSearchOperatorInterface
8876
{
8977
return $this->addOperator(new CompoundedGeoWithin($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), ...$path));
9078
}
9179

92-
/**
93-
* @param array<string, mixed>|object $documents
94-
*
95-
* @return MoreLikeThis&CompoundSearchOperatorInterface
96-
*/
97-
public function moreLikeThis(...$documents): MoreLikeThis
80+
/** @param array<string, mixed>|object $documents */
81+
public function moreLikeThis(...$documents): MoreLikeThis&CompoundSearchOperatorInterface
9882
{
9983
return $this->addOperator(new CompoundedMoreLikeThis($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), ...$documents));
10084
}
10185

10286
/**
103-
* @param int|float|UTCDateTime|array|Point|null $origin
104-
* @param int|float|null $pivot
105-
*
106-
* @return Near&CompoundSearchOperatorInterface
87+
* @param int|float|UTCDateTime|array<string, mixed>|Point|null $origin
88+
* @param int|float|null $pivot
10789
*/
108-
public function near($origin = null, $pivot = null, string ...$path): Near
90+
public function near($origin = null, $pivot = null, string ...$path): Near&CompoundSearchOperatorInterface
10991
{
11092
return $this->addOperator(new CompoundedNear($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), $origin, $pivot, ...$path));
11193
}
11294

113-
/** @return Phrase&CompoundSearchOperatorInterface */
114-
public function phrase(): Phrase
95+
public function phrase(): Phrase&CompoundSearchOperatorInterface
11596
{
11697
return $this->addOperator(new CompoundedPhrase($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage()));
11798
}
11899

119-
/** @return QueryString&CompoundSearchOperatorInterface */
120-
public function queryString(string $query = '', string $defaultPath = ''): QueryString
100+
public function queryString(string $query = '', string $defaultPath = ''): QueryString&CompoundSearchOperatorInterface
121101
{
122102
return $this->addOperator(new CompoundedQueryString($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage(), $query, $defaultPath));
123103
}
124104

125-
/** @return Range&CompoundSearchOperatorInterface */
126-
public function range(): Range
105+
public function range(): Range&CompoundSearchOperatorInterface
127106
{
128107
return $this->addOperator(new CompoundedRange($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage()));
129108
}
130109

131-
/** @return Regex&CompoundSearchOperatorInterface */
132-
public function regex(): Regex
110+
public function regex(): Regex&CompoundSearchOperatorInterface
133111
{
134112
return $this->addOperator(new CompoundedRegex($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage()));
135113
}
136114

137-
/** @return Text&CompoundSearchOperatorInterface */
138-
public function text(): Text
115+
public function text(): Text&CompoundSearchOperatorInterface
139116
{
140117
return $this->addOperator(new CompoundedText($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage()));
141118
}
142119

143-
/** @return Wildcard&CompoundSearchOperatorInterface */
144-
public function wildcard(): Wildcard
120+
public function wildcard(): Wildcard&CompoundSearchOperatorInterface
145121
{
146122
return $this->addOperator(new CompoundedWildcard($this->getCompoundStage(), $this->getAddOperatorClosure(), $this->getSearchStage()));
147123
}

lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/SupportsGeoShapeOperator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111

1212
interface SupportsGeoShapeOperator
1313
{
14-
/** @param LineString|Point|Polygon|MultiPolygon|array|null $geometry */
14+
/** @param LineString|Point|Polygon|MultiPolygon|array<string, mixed>|null $geometry */
1515
public function geoShape($geometry = null, string $relation = '', string ...$path): GeoShape;
1616
}

lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/SupportsNearOperator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
interface SupportsNearOperator
1111
{
1212
/**
13-
* @param int|float|UTCDateTime|array|Point|null $origin
14-
* @param int|float|null $pivot
13+
* @param int|float|UTCDateTime|array<string, mixed>|Point|null $origin
14+
* @param int|float|null $pivot
1515
*/
1616
public function near($origin = null, $pivot = null, string ...$path): Near;
1717
}

0 commit comments

Comments
 (0)