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
Allow to merge models #6
Conversation
I like having a merge function, even on multiple objects and to make it traverse down hence I dislike it's replacing the parsing method. I'd rather like to keep it as two concepts: parse for everything that comes from json and merge which takes objects. The strategy would (at the moment) come down to an $info->merge($anotherInfo, true); And then in public function merge(Info $info, $overwrite = false) {
$this->url = ($overwrite && !Text::create($info->getUrl())->isEmpty()) || empty($this->url) ? $info->getUrl() : $this->url;
// ...
} well, the "getting the value part" could be extracted into its own method which takes 3 arguments: Your comments on that? |
@gossi I would just replace the function signature by Do you want me to work on that ? |
Great. Yes, I can merge it by monday and make a release, I will be on holidays afterwards. AFAIK: empty() also checks for |
@gossi i know but if a value isn't exactly I'm especially thinking about integer values that could be |
Ah, yes; You are right, good one. |
@gossi After all, I'm not so sure it's a good idea to merge objects as it causes many reference problems. It's much easier to merge an array in an object. Edit: always instantiating new objects should fix this. Edit 2: I pushed some changes, this is a bit long to do... |
@@ -59,19 +60,38 @@ private function parseType(Map $data) { | |||
$this->collectionFormat = $data->get('collectionFormat'); | |||
$this->default = $data->get('default'); | |||
$this->maximum = $data->get('maximum'); | |||
$this->exclusiveMaximum = $data->has('exclusiveMaximum') && $data->get('exclusiveMaximum'); | |||
$this->exclusiveMaximum = $data->get('exclusiveMaximum'); |
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 should probably do something like:
$this->exclusiveMaximum = $data->get('exclusiveMaximum', false);
anyway the default value would be null
and as such not bool
.
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.
Yes but if you set false
in your model, you don't know if the user already defined that value or not whereas with null
:)
The code so far looks good to me. I made a comment on one line, where you replaced some old code ( Apart form that, are your original concerns about objects resolved? |
@gossi I don't think i'll have the time to finish this soon :/ This is much longer than what i first thought... |
easy. I would have a released a version for you before my holidays. But you can still use your own branch, so no worries. |
This PR would allow to merge models with two different strategies:
PREFER_ORIGINAL
which would keep the original fields except if they aren't defined yet.PREFER_EXTERNAL
which would use the provided fields when they are available.This is useful when you want to merge different documentations or in my case to merge the output of different libraries generating the doc of an app.