-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
Copy property after applying doctrine filter #133
Conversation
Hi, thanks for the PR! Could you please add a test for it as well to ensure this is fixing the issue and preventing any regression in the future? I'll try to have a look at it this week/weekend |
@theofidry hi! Thank you for quick reply! Just added test for applying DoctrineProxyFilter only. Hope it helps to understand my case somehow. |
@theofidry , looking forward to your reply. |
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.
The use case seems legit to me, but I left a comment on the fix implementation.
src/DeepCopy/DeepCopy.php
Outdated
@@ -195,6 +196,10 @@ function ($object) { | |||
} | |||
); | |||
|
|||
if ($filter instanceof DoctrineProxyFilter) { |
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.
FYI I added the ChainableFilter
interface (#101) to avoid using directly the DoctrineProxyFilter
filter.
With that in mind, the two conditions seems redundant (and now, the second condition is now uncovered in tests, see https://coveralls.io/builds/22507096/source?filename=src%2FDeepCopy%2FDeepCopy.php#L206)
I guess that the proper fix would be to remove the $filterWasApplied
variable as I added it to avoid a possible BC break back then (but I guess there was still this bug ^^).
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.
$filterWasApplied is used to prevent recursive copy of property, if filter was applied. In other words you use filter or recursive copy. Removing $filterWasApplied breaks some fundamentals of DeepCopy.
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.
$filterWasApplied
is only use when you use the DoctrineProxyFilter
(=ChainableFilter
) without any other filter (your use case).
I added this variable to keep the same behaviour (possible BC break) as before while fixing #98.
The issue before was that when you use the DoctrineProxyFilter
with an other filter (SetNullFilter
on the ID for example), the second filter was never used (so no ID with null value).
So, I added a condition to allow ChainableFilter
(=DoctrineProxyFilter
) to apply an other filter after (with the continue).
You can reach the return
in the if ($filterWasApplied) {
condition only if there is no other filter to apply. There is already a return
statement when you apply a filter.
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.
Got it now. You say, instead of adding "continue" on DoctrineProxyFilter, we need to remove $filterWasApplied variable. So that when chainable filter applied, either recursive copy or other filter applies after. Right?
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.
Yep 👍 (sorry if it wasn't clear the first time, english is not my native language :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.
Done!
fixtures/f010/A.php
Outdated
{ | ||
$this->foo = $foo; | ||
} | ||
} |
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.
Missing EOF(end of file).
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.
fixed
fixtures/f010/B.php
Outdated
{ | ||
$this->foo = null; | ||
} | ||
} |
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.
Missing EOF(end of file).
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.
fixed
Back from holidays. Thanks for the PR! Would you mind rebasing it? |
@theofidry done! |
When DoctrineProxyFilter applied and there is no other filters for property, deep copy doesn't create recursive copy of property.