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

Commit 5fe7b6c

Browse files
committed
Convert class to trait
1 parent 7f8a396 commit 5fe7b6c

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

generator/src/FluentStageFactoryGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function generate(GeneratorDefinition $definition): void
4040
private function createFluentFactoryClass(GeneratorDefinition $definition): PhpNamespace
4141
{
4242
$namespace = new PhpNamespace($definition->namespace);
43-
$class = $namespace->addClass('FluentFactory');
43+
$class = $namespace->addTrait('FluentFactoryTrait');
4444

4545
$namespace->addUse(self::FACTORY_CLASS);
4646
$namespace->addUse(StageInterface::class);
@@ -78,7 +78,7 @@ private function createFluentFactoryClass(GeneratorDefinition $definition): PhpN
7878
return $namespace;
7979
}
8080

81-
private function addMethod(Method $factoryMethod, ClassType $class): void
81+
private function addMethod(Method $factoryMethod, TraitType $class): void
8282
{
8383
// Non-public methods are not part of the API
8484
if (! $factoryMethod->isPublic()) {

src/Builder/Stage/FluentFactory.php renamed to src/Builder/Stage/FluentFactoryTrait.php

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Builder/FluentPipelineFactoryTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
namespace MongoDB\Tests\Builder;
66

77
use MongoDB\Builder\Query;
8-
use MongoDB\Builder\Stage\FluentFactory;
8+
use MongoDB\Builder\Stage\FluentFactoryTrait;
99
use MongoDB\Builder\Type\Sort;
1010

1111
class FluentPipelineFactoryTest extends PipelineTestCase
1212
{
1313
public function testFluentPipelineFactory(): void
1414
{
15-
$pipeline = (new FluentFactory())
15+
$factory = new class {
16+
use FluentFactoryTrait;
17+
};
18+
$pipeline = $factory
1619
->match(x: Query::eq(1))
1720
->project(_id: false, x: true)
1821
->sort(x: Sort::Asc)

0 commit comments

Comments
 (0)