@@ -40,17 +40,17 @@ public function generate(GeneratorDefinition $definition): void
40
40
private function createFluentFactoryClass (GeneratorDefinition $ definition ): PhpNamespace
41
41
{
42
42
$ namespace = new PhpNamespace ($ definition ->namespace );
43
- $ class = $ namespace ->addClass ( ' FluentFactory ' );
43
+ $ trait = $ namespace ->addTrait ( ' FluentFactoryTrait ' );
44
44
45
45
$ namespace ->addUse (self ::FACTORY_CLASS );
46
46
$ namespace ->addUse (StageInterface::class);
47
47
$ namespace ->addUse (Pipeline::class);
48
48
49
- $ class ->addProperty ('pipeline ' )
49
+ $ trait ->addProperty ('pipeline ' )
50
50
->setType ('array ' )
51
51
->setComment ('@var list<StageInterface> ' )
52
52
->setValue ([]);
53
- $ class ->addMethod ('getPipeline ' )
53
+ $ trait ->addMethod ('getPipeline ' )
54
54
->setReturnType (Pipeline::class)
55
55
->setBody (<<<'PHP'
56
56
return new Pipeline(...$this->pipeline);
@@ -62,23 +62,23 @@ private function createFluentFactoryClass(GeneratorDefinition $definition): PhpN
62
62
63
63
// Import the methods customized in the factory class
64
64
foreach ($ staticFactory ->getMethods () as $ method ) {
65
- $ this ->addMethod ($ method , $ class );
65
+ $ this ->addMethod ($ method , $ trait );
66
66
}
67
67
68
68
// Import the other methods provided by the generated trait
69
- foreach ($ staticFactory ->getTraits () as $ trait ) {
70
- $ this ->addUsesFrom ($ trait ->getName (), $ namespace );
71
- $ staticFactory = TraitType::from ($ trait ->getName ());
69
+ foreach ($ staticFactory ->getTraits () as $ usedTrait ) {
70
+ $ this ->addUsesFrom ($ usedTrait ->getName (), $ namespace );
71
+ $ staticFactory = TraitType::from ($ usedTrait ->getName ());
72
72
assert ($ staticFactory instanceof TraitType);
73
73
foreach ($ staticFactory ->getMethods () as $ method ) {
74
- $ this ->addMethod ($ method , $ class );
74
+ $ this ->addMethod ($ method , $ trait );
75
75
}
76
76
}
77
77
78
78
return $ namespace ;
79
79
}
80
80
81
- private function addMethod (Method $ factoryMethod , ClassType $ class ): void
81
+ private function addMethod (Method $ factoryMethod , TraitType $ trait ): void
82
82
{
83
83
// Non-public methods are not part of the API
84
84
if (! $ factoryMethod ->isPublic ()) {
@@ -87,11 +87,11 @@ private function addMethod(Method $factoryMethod, ClassType $class): void
87
87
88
88
// Some methods can be overridden in the class, so we skip them
89
89
// when importing the methods provided by the trait.
90
- if ($ class ->hasMethod ($ factoryMethod ->getName ())) {
90
+ if ($ trait ->hasMethod ($ factoryMethod ->getName ())) {
91
91
return ;
92
92
}
93
93
94
- $ method = $ class ->addMethod ($ factoryMethod ->getName ());
94
+ $ method = $ trait ->addMethod ($ factoryMethod ->getName ());
95
95
96
96
$ method ->setComment ($ factoryMethod ->getComment ());
97
97
$ method ->setParameters ($ factoryMethod ->getParameters ());
@@ -119,9 +119,9 @@ private function addMethod(Method $factoryMethod, ClassType $class): void
119
119
));
120
120
}
121
121
122
- private static function addUsesFrom (string $ class , PhpNamespace $ namespace ): void
122
+ private static function addUsesFrom (string $ classLike , PhpNamespace $ namespace ): void
123
123
{
124
- $ file = PhpFile::fromCode (file_get_contents ((new ReflectionClass ($ class ))->getFileName ()));
124
+ $ file = PhpFile::fromCode (file_get_contents ((new ReflectionClass ($ classLike ))->getFileName ()));
125
125
126
126
foreach ($ file ->getNamespaces () as $ ns ) {
127
127
foreach ($ ns ->getUses () as $ use ) {
0 commit comments