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

entity generator - ignore trait properties and methods #632

Merged
merged 11 commits into from Jul 7, 2013
Merged

entity generator - ignore trait properties and methods #632

merged 11 commits into from Jul 7, 2013

Conversation

Padam87
Copy link
Contributor

@Padam87 Padam87 commented Mar 26, 2013

@doctrinebot
Copy link

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DDC-2372

@Padam87
Copy link
Contributor Author

Padam87 commented Mar 26, 2013

I'm not sure if this is the right solution, but modifying the ClassMetadataInfo because of this felt like a bad idea. That would change trait handling entirely.

if (class_exists($metadata->name)) {
$reflClass = new \ReflectionClass($metadata->name);

foreach ($reflClass->getTraits() as $trait) {
Copy link
Member

Choose a reason for hiding this comment

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

Please don't bump the requirement to 5.4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, forgot about that. I will add an if (method_exists($reflClass, 'getTraits'))

@stof
Copy link
Member

stof commented Mar 27, 2013

This should be tested

@Padam87
Copy link
Contributor Author

Padam87 commented Mar 28, 2013

@pamil You're welcome :)

Sorry guys, i don't have the time right now, but I will create some unit test this weekend.

@beberlei
Copy link
Member

Can you remove the code duplication, extract the code into their own methods and try to add a test?

@Padam87
Copy link
Contributor Author

Padam87 commented Mar 30, 2013

Fixed the code duplication, and created a unit test.

Ran into some trouble with the test, I had to use a real entity, couldn't create a traited entity from ClassMetadata.

? new \ReflectionClass($metadata->name)
: $metadata->reflClass;

if (method_exists($reflClass, 'getTraits')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I'd prefer this check:

if (PHP_VERSION_ID >= 50400) {

@beberlei
Copy link
Member

beberlei commented Apr 6, 2013

Why did you put code into sandbox?

@Padam87
Copy link
Contributor Author

Padam87 commented Apr 6, 2013

@beberlei Wasn't sure where to put the entities for the test, and that seemed to be the place you guys have used. Where should I put them?

(Could not create an entity from class metadata, like the rest of the tests do, because of the trait.)

@stof
Copy link
Member

stof commented Apr 6, 2013

@Padam87 the testsuite already contains lots of models: https://github.com/doctrine/doctrine2/tree/master/tests/Doctrine/Tests/Models

*/
public function testTraitPropertiesAndMethodsAreNotDuplicated()
{
if (PHP_VERSION_ID >= 50400) {
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO better mark test skipped in other case

Copy link
Member

Choose a reason for hiding this comment

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

indeed

@Padam87
Copy link
Contributor Author

Padam87 commented May 31, 2013

up

@jmonday
Copy link

jmonday commented Jun 13, 2013

Hello all. I was just wondering if anyone had any updates on this. I just ran into this issue tonight. Thanks!

? new \ReflectionClass($metadata->name)
: $metadata->reflClass;

if (PHP_VERSION_ID >= 50400) {
Copy link
Member

Choose a reason for hiding this comment

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

You can move this check at the beginning of the method and return early

@Padam87
Copy link
Contributor Author

Padam87 commented Jul 7, 2013

@Ocramius @beberlei Can you merge this? Really annoying bug... :) Do I need to modify something?

guilhermeblanco added a commit that referenced this pull request Jul 7, 2013
entity generator - ignore trait properties and methods
@guilhermeblanco guilhermeblanco merged commit 78fc129 into doctrine:master Jul 7, 2013
@AlexanderParker
Copy link

I just tested this and it definitely helped fix my issue of classes with traits having the trait properties and methods copied into their body.

However, any subclasses of that class still get the properties and methods copied into them. This causes null value errors when saving child entities unless you manually remove the properties and methods from the child class.

Can anyone else confirm this?

@Padam87
Copy link
Contributor Author

Padam87 commented Aug 20, 2013

@AlexanderParker You are right, in that case, the problem still exists. On it.

@AlexanderParker
Copy link

@Padam87, your fix in #763 seems to have worked. Thanks for looking at this so quickly.

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.

None yet

10 participants