-
Notifications
You must be signed in to change notification settings - Fork 74
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
Upcasting #255
Conversation
For discussion:
|
That was fast! I'll take an in-depth look as soon as I have time. As for the discussion points:
|
@codeliner @mrook tests now included |
Why not put upcast and downcast methods directly into events? These up/downcast methods are tightly coupled with event in particuar version anyway... |
@jkuchar Single Responsibility Principle |
@jkuchar because some upcasters would need information from other events (i.e., if you are merging) or emit multiple events (if you are splitting). |
/cc @codeliner |
$this->upcasters = $upcasters; | ||
} | ||
|
||
public function upcast(Message $message): array |
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.
Can you take a second look on the message?
Why is the message turned into a messages array just to foreach over it?
You wanted to return messages
, right? But $result
is returned.
Foreach can be removed in either case.
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.
You're right. I will fix this later.
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.
Sorry, you are not
right :)
At the first iteration of upcasters, you would have been right, but in the second iteration, I might have an array of messages, that may need further upcasting. see: UpcasterChainTest::it_chains_upcasts
This test would immediately break, if we would make the suggested change.
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.
ok, I see. Just a few lines of code but very tricky ;)
src/Upcasting/UpcastingIterator.php
Outdated
$messages = $this->upcaster->upcast($this->innerIterator->current()); | ||
|
||
if (empty($messages)) { | ||
$this->next(); |
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.
$this->innerIterator->next();
src/Upcasting/UpcastingIterator.php
Outdated
if (empty($messages)) { | ||
$this->next(); | ||
|
||
if ($this->valid()) { |
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.
$this->innerIterator->valid()
There is still a bug in the iterator... I am trying to fix this now. |
@codeliner I fixed the upcasting iterator |
@mrook @codeliner your thoughts in the implementation? |
@prolic looks fine for the initial implementation! |
LGTM |
👍 |
resolves #254