Skip to content
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

Merged
merged 6 commits into from
Jan 9, 2020
Merged

Conversation

amatoenot
Copy link

When DoctrineProxyFilter applied and there is no other filters for property, deep copy doesn't create recursive copy of property.

@theofidry
Copy link
Collaborator

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

@amatoenot
Copy link
Author

amatoenot commented Mar 31, 2019

@theofidry hi! Thank you for quick reply! Just added test for applying DoctrineProxyFilter only. Hope it helps to understand my case somehow.

@amatoenot
Copy link
Author

@theofidry , looking forward to your reply.

Copy link
Contributor

@fsevestre fsevestre left a 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.

@@ -195,6 +196,10 @@ function ($object) {
}
);

if ($filter instanceof DoctrineProxyFilter) {
Copy link
Contributor

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 ^^).

Copy link
Author

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.

Copy link
Contributor

@fsevestre fsevestre Apr 15, 2019

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.

Copy link
Author

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?

Copy link
Contributor

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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

{
$this->foo = $foo;
}
}
Copy link
Contributor

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).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

{
$this->foo = null;
}
}
Copy link
Contributor

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).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@theofidry
Copy link
Collaborator

Back from holidays. Thanks for the PR! Would you mind rebasing it?

@amatoenot
Copy link
Author

@theofidry done!

@theofidry theofidry changed the title don't count DoctrineProxyFilter Copy property after applying doctrine filter Jan 9, 2020
@theofidry theofidry merged commit 0ef5985 into myclabs:2.x Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants