Repository navigation
Trait support - #9
Conversation
This also inadvertently enables passing an InterfaceBuilder. We don't really want that. Perhaps there's a better way?
Also updates the main builder test and fixes Property/ConstantBuilder classes rejecting the call to `end()` when used with traits.
|
Looks good so far :)
This is probably acceptable, in cases where we know we return a more specific type we can add a virtual method declaration (e.g.
For sure, although the builders don't worry as much as the updaters. The updating code can be broadly refactored, as currently it is very loose and clumsy, and I'm sure some mistakes will be duplicated in the trait updater. Perhaps a first step woul be to create an abstract |
Fixes phpactor/phpactor#726, but relies on phpactor/code-builder#9 to get the underlying trait() method added with all its supporting code.
Thanks! That's a welcome and much need sanity check so I know I'm not going down a completely wrong path
That's pretty much exactly what I was thinking, but I didn't want to go ahead if you preferred a simple copy approach. I'll work on this later today and see what I can come up with |
Begin refactoring common ClassUpdater and TraitUpdater methods into a single unified ClassLikeUpdater. Move resolvePropertyName() to abstract updater Move second foreach loop. First is causing havoc
fd59c4a to
cf66d90
Compare
Been trying to move just the foreach loop, but everything results in failed tests. Moving the entire method is finally passing with some slightly looser type hinting which can be cleaned up in the next commit. Only 2 lines differ between trait and class so this *should* be fine. Handle Class and Trait constants together Now that things pass, we can lump everything back into one method and use a switch to diffrentiate between Class and Trait declarations. The other option here is `if $classNode instanceof TraitDeclaration elseif ... else throw exception`. Either would work equally well.
Much of this is the same as updateConstants, but let's take it one step at a time. All tests are still passing, which is a miracle in itself. Remove unnecessary use statements Fix PEBKAC
|
First stage of the Attempts at moving the first To avoid any issues, I first want to add some tests to |
|
👍 looks good so far :) |
These tests could've been done by modifying the `provideProperties()` method and altering the templates based on the test it's providing for which happens to be the first and only parameter* to providers methods Such a "feature" would also require changing NOWDOC to HEREDOC though, which in turn would mean escaping all the `$`s and making it unreadable. * The parameter is entirely undocumented - I discovered it by calling `func_get_args()` in the provider. It probably can't be relied on.
Moves `updateConstants` back into the concrete `ClassUpdater`, and removes the call to it from the `TraitUpdater`.
Rather than having an ugly switch, this lets the concrete classes define the members and memberDeclarations themselves. Almost good to go now. Would probably be better with an `openBrace` or `startPoint` method returning `$node->classMembers->openBrace`, instead of the generic `members` but It's only used once and I couldn't decide what to call it.
Fixes phpactor/phpactor#726, but relies on phpactor/code-builder#9 to get the underlying trait() method added with all its supporting code.
|
@dantleech All done! I've submitted phpactor/code-transform#23 which connects the dots if you want to try it locally. Otherwise, we should pretty much be good to go. I've also uncommented the Let me know if there's anything I've missed! |
|
Looks perfect :) Just left a comment about potentially duplicated tests |
|
Thanks for the feedback :) After replying to that comment, I took another look at the tests. I've gone ahead and removed most of the duplicates, leaving behind:
...which should hopefully keep all bases covered. I've also updated phpactor/code-transform#23 to get rid of the variable method. |
|
Awesome! thanks for all your work on this. This library is far from being perfect, but I think this is a nice step in the right direction. |
Adds underlying Trait prototypes, builders etc required for phpactor/phpactor#726.
Todo
ClassLikeUpdaterabstract classTraitUpdaterandClassUpdatercode toClassLikeUpdaterupdatePropertiesmethodAdapter\WorseReflection\WorseBuilderFactoryTestAdapter\UpdaterTestCaseNotes
ClassFootoClassLikeFooin order to receiveTrait-related objects. Might need to rework this to avoid acceptingInterface-related things where we don't want them.ClassBuilderandTraitBuilder, along withClassUpdaterandTraitUpdatershare many similarities. Could probably refactor these too to avoid too much duplication potentially causing issues down the line.