Skip to content
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

In string method notation #154

Open
pabloelcolombiano opened this issue Jan 7, 2022 · 6 comments
Open

In string method notation #154

pabloelcolombiano opened this issue Jan 7, 2022 · 6 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@pabloelcolombiano
Copy link
Collaborator

pabloelcolombiano commented Jan 7, 2022

Often little setters are added to a given factory. E.g.:

ArticleFactory::make()
   ->with('Authors',
      AuthorFactory()->make(10)->published()->active()->with('Address',
         AddressFactory::make()->verified()
      )
   )
   ->getEntity()

These setters could be specified in the in string notation of the with method:

ArticleFactory::make()->with('Authors::published::active[10].Address::verified')->getEntity();

Pros:

  • this makes it much easier to write

Cons:

  • we yes loose the autocompletion.
  • refactoring by the IDE is not possible

If the method is not found, possibly due to some refactoring, an exception will be raised specifiying that the provided method does not exist.

Question 1:
Do you agree on the utility of the feature?

Question 2:
If yes, what is your prefered notation? # or : or :: or -> or something else?

@pabloelcolombiano pabloelcolombiano added the enhancement New feature or request label Jan 7, 2022
@pabloelcolombiano pabloelcolombiano added this to the v2.6 milestone Jan 7, 2022
@pabloelcolombiano pabloelcolombiano changed the title Add an in string method notation In string method notation Jan 11, 2022
@pabloelcolombiano
Copy link
Collaborator Author

pabloelcolombiano commented Jan 11, 2022

Please vote as follows:

Authors::active::verified 😄 

Authors#active#verified 👍 

Authors->active->verified ❤️ 

Authors@active@verified 👎 

@pakacuda
Copy link
Collaborator

pakacuda commented Jan 11, 2022

If what you propose is feasible (mapping Authors:: and Address:: to the correct factory), wouldn't the following have the best of both worlds. To get Full autocompletion, we would have to set the return type for Authors() and Address(), but maybe worth the additional effort

ArticleFactory::make()->Authors(10)->published()->active()->Address()->verified()->getEntity()

The ucfirst letter would be the convention for a factory method in the chain. There would be a magic getter only on ucfirst method calls.
Otherwise, I would vote for 👍 just because two colon in a row might be error prone

@LordSimal
Copy link
Contributor

LordSimal commented Jan 11, 2022

I personally was never really a fan of "compressing" chained function calls into a string separated by <something>.
Therefore this is my vote for "I don't mind/care" because it wouldn't be usefull to me 😄

@pakacuda
Copy link
Collaborator

I don't think I would use it either as a string BTW

@pabloelcolombiano
Copy link
Collaborator Author

pabloelcolombiano commented Feb 1, 2022

ArticleFactory::make()->Authors(10)->published()->active()->Address()->verified()->getEntity()

This is a great idea @pakacuda. We ideally want a way to do something like this too:

ArticleFactory::make()
   ->with('Authors#published#active[10].Address#verified')
   ->with('Authors#published#inactive[10].Address#notVerified')
   ->getEntity();

Need to think about how to with the magic getter solution, but I agree that this beats the not-handy string notation solution.

@pabloelcolombiano
Copy link
Collaborator Author

ArticleFactory::make()
   ->Authors(10)->published()->active()->Address()->verified()
   ->andAuthors(10)->published()->inactive()->Address()->notVerified()
   ->getEntity()

would actually work if we introduce a root factory property. The magic getter will know that the prefix and refers to an association of the root factory property.

What do you all think of this syntax?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants