-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fluent builder for Laravel #67
Conversation
private function addMethod(Method $factoryMethod, PhpNamespace $namespace, ClassType $class): void | ||
{ | ||
if ($class->hasMethod($factoryMethod->getName())) { | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to throw here? What is the legitimate case where the method already exists and you'd want to NOP?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method match
is redefined in the Stage
class. The generated version from the trait must be ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted. In this case, a comment would be helpful to clarify that you're giving preference to the redefined Stage methods instead of those from the trait. And this assumes you add the Stage methods before the trait (no need to repeat that, it's clear from the order of addMethod()
calls in the generation method).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's essentially what I said in the comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, my mistake. I just realized this entire thread was incorrectly applied to the early return for non-public methods.
I see the comment below for skipping overridden methods. 👍
use MongoDB\Model\BSONArray; | ||
use stdClass; | ||
|
||
trait FluentFactoryTrait |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I converted the class to a trait, this allows to rename or change visibility of a method if necessary, and avoid issues that can be caused by inheritance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with the class/trait name replacements. Also note a suggestion to comment the addMethod()
return statement.
use function sprintf; | ||
|
||
/** | ||
* Generates a fluent factory class for aggregation pipeline stages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Generates a fluent factory class for aggregation pipeline stages. | |
* Generates a fluent factory trait for aggregation pipeline stages. |
Make a note to update other references of "class" to "trait" below. For instance, createFluentFactoryClass()
should now be createFluentFactoryTrait()
.
This very class might also be better named FluentFactoryTraitGenerator()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to keep "Stage" in the generator class name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the generated file be FluentStageFactoryTrait.php
in that case? I'll defer to you, as I'm not sure if you have future plans for more traits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file is in the Stage namespace.
<?php | ||
|
||
/** | ||
* THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this file is auto-generated, should it be labeled as such in .gitattributes
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have /src/Builder/Stage/*.php linguist-generated=true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted. I'm not sure why GitHub opted not to present that explanation for hiding the file (maybe "large diffs" take precedence).
Related to PHPORM-103
Reopen #65
Create a fluent pipeline builder that can be used like this: