Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

Commit fa1e23b

Browse files
committed
Fix types and add docs
1 parent 5a76901 commit fa1e23b

File tree

6 files changed

+28
-12
lines changed

6 files changed

+28
-12
lines changed

psalm-baseline.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="5.20.0@3f284e96c9d9be6fe6b15c79416e1d1903dcfef4">
2+
<files psalm-version="5.21.1@8c473e2437be8b6a8fd8f630f0f11a16b114c494">
33
<file src="src/Builder/Encoder/AbstractExpressionEncoder.php">
44
<MixedAssignment>
55
<code>$val</code>
@@ -113,6 +113,14 @@
113113
<code>stdClass</code>
114114
</TooManyTemplateParams>
115115
</file>
116+
<file src="src/Builder/Stage/SortStage.php">
117+
<PropertyTypeCoercion>
118+
<code>$sort</code>
119+
</PropertyTypeCoercion>
120+
<TooManyTemplateParams>
121+
<code>stdClass</code>
122+
</TooManyTemplateParams>
123+
</file>
116124
<file src="src/Builder/Type/OutputWindow.php">
117125
<DocblockTypeContradiction>
118126
<code><![CDATA[! is_string($documents[1]) && ! is_int($documents[1])]]></code>

src/Builder/BuilderEncoder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use MongoDB\Builder\Encoder\VariableEncoder;
1616
use MongoDB\Builder\Expression\Variable;
1717
use MongoDB\Builder\Type\CombinedFieldQuery;
18-
use MongoDB\Builder\Type\Dictionnary;
18+
use MongoDB\Builder\Type\DictionaryInterface;
1919
use MongoDB\Builder\Type\ExpressionInterface;
2020
use MongoDB\Builder\Type\FieldPathInterface;
2121
use MongoDB\Builder\Type\OperatorInterface;
@@ -31,17 +31,17 @@
3131
use function array_key_exists;
3232
use function is_object;
3333

34-
/** @template-implements Encoder<stdClass|array|string, Pipeline|StageInterface|ExpressionInterface|QueryInterface> */
34+
/** @template-implements Encoder<stdClass|array|string|int, Pipeline|StageInterface|ExpressionInterface|QueryInterface> */
3535
class BuilderEncoder implements Encoder
3636
{
37-
/** @template-use EncodeIfSupported<stdClass|array|string, Pipeline|StageInterface|ExpressionInterface|QueryInterface> */
37+
/** @template-use EncodeIfSupported<stdClass|array|string|int, Pipeline|StageInterface|ExpressionInterface|QueryInterface> */
3838
use EncodeIfSupported;
3939

4040
/** @var array<class-string, class-string<ExpressionEncoder>> */
4141
private array $defaultEncoders = [
4242
Pipeline::class => PipelineEncoder::class,
4343
Variable::class => VariableEncoder::class,
44-
Dictionnary::class => DictionaryEncoder::class,
44+
DictionaryInterface::class => DictionaryEncoder::class,
4545
FieldPathInterface::class => FieldPathEncoder::class,
4646
CombinedFieldQuery::class => CombinedFieldQueryEncoder::class,
4747
QueryObject::class => QueryEncoder::class,

src/Builder/Encoder/DictionaryEncoder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44

55
namespace MongoDB\Builder\Encoder;
66

7-
use MongoDB\Builder\Type\Dictionnary;
7+
use MongoDB\Builder\Type\DictionaryInterface;
88
use MongoDB\Codec\EncodeIfSupported;
99
use MongoDB\Exception\UnsupportedValueException;
1010
use stdClass;
1111

12-
/** @template-extends AbstractExpressionEncoder<string, Dictionnary> */
12+
/** @template-extends AbstractExpressionEncoder<string|int|array|stdClass, DictionaryInterface> */
1313
class DictionaryEncoder extends AbstractExpressionEncoder
1414
{
15-
/** @template-use EncodeIfSupported<string, Dictionnary> */
15+
/** @template-use EncodeIfSupported<string|int|array|stdClass, DictionaryInterface> */
1616
use EncodeIfSupported;
1717

1818
public function canEncode(mixed $value): bool
1919
{
20-
return $value instanceof Dictionnary;
20+
return $value instanceof DictionaryInterface;
2121
}
2222

2323
public function encode(mixed $value): string|int|array|stdClass

src/Builder/Type/Dictionnary.php renamed to src/Builder/Type/DictionaryInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace MongoDB\Builder\Type;
66

7-
interface Dictionnary
7+
interface DictionaryInterface
88
{
99
public function getValue(): string|int|array;
1010
}

src/Builder/Type/Sort.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
namespace MongoDB\Builder\Type;
66

7-
enum Sort implements Dictionnary
7+
/**
8+
* Sort order can be used with $sort stage and sortBy properties
9+
*
10+
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/
11+
*/
12+
enum Sort implements DictionaryInterface
813
{
914
case Asc;
1015
case Desc;

src/Builder/Type/TimeUnit.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
namespace MongoDB\Builder\Type;
66

7-
enum TimeUnit: string implements Dictionnary
7+
/**
8+
* Values for "unit" property of stages like $derivative and $integral, and operators like $dateAdd and $dateDiff
9+
*/
10+
enum TimeUnit: string implements DictionaryInterface
811
{
912
case Year = 'year';
1013
case Quarter = 'quarter';

0 commit comments

Comments
 (0)