-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[ObjectMapper] Map a collection of objects #60615
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
base: 7.4
Are you sure you want to change the base?
Conversation
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.
Because this is a new feature, don't forget to add a line in the changelog of the component! Also, don't forget to check fabbot which will provide some automated feedback on the code style.
} | ||
} | ||
|
||
if (!empty($exceptions)) { |
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 avoid using empty()
in Symfony, this may be replaced by:
if (!empty($exceptions)) { | |
if ($exceptions) { |
interface MapMultipleInterface | ||
{ | ||
/** | ||
* @template T of object |
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 this annotation be on the class instead of the method, so devs can use @implements MapMultipleInterface<Something>
? I'm not sure this works well if the template definition is on the method
|
||
self::assertInstanceOf(D::class, $target[0]); | ||
$firstTarget = $target[0]; | ||
assert($firstTarget instanceof D); |
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 don't use assert()
, also the instance is already checked above with self::assertInstanceOf(D::class, $target[0]);
self::assertInstanceOf(D::class, $target[1]); | ||
$secondTarget = $target[1]; | ||
assert($secondTarget instanceof D); |
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.
Same here
self::assertEquals('foo2', $secondTarget->baz); | ||
self::assertEquals('bar2', $secondTarget->bat); |
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 use self::assertSame
wherever possible 🙂
|
||
self::fail('Mapping of second source element should have thrown!'); | ||
} catch (MapMultipleAggregateException $ex) { | ||
self::assertEquals('Mapping source collection has failed.', $ex->getMessage()); |
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.
self::assertEquals('Mapping source collection has failed.', $ex->getMessage()); | |
self::assertSame('Mapping source collection has failed.', $ex->getMessage()); |
(Same for the occurrences below)
self::assertCount(1, $target, 'Mapping first source collection object should have passed!'); | ||
self::assertInstanceOf(D::class, $target[0]); | ||
$firstTarget = $target[0]; | ||
assert($firstTarget instanceof D); |
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.
Same as above, this is needed 🙂
Add functionality to map multiple source objects to the specified target type.
This is my 1st PR to Symfony. Looking forward to all kinds of feedback.