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

Implement ReflectionClass->getParentClassName() #1359

Merged
merged 9 commits into from
Jul 31, 2023
Merged

Conversation

clxmstaab
Copy link
Contributor

@clxmstaab clxmstaab commented Jul 31, 2023

A class can declare a parent which we cannot locate via autoloading mechanics.
For some static analysis cases its still useful to know, whether a parent class is defined - even if we can't reflect on it for some reason.

I was not able to find a API which allows me to dermine whether a class has a parent declared but only BetterReflection cannot find its definition from whether there is no parent class declared at all.

Before this PR we had to use reflection hacks to get the private property out of the class, see rectorphp/rector#8093 (comment)

@clxmstaab clxmstaab marked this pull request as draft July 31, 2023 10:19
src/Reflection/ReflectionClass.php Outdated Show resolved Hide resolved
@Ocramius Ocramius added this to the 6.11.0 milestone Jul 31, 2023
@@ -452,6 +452,14 @@ public function newInstanceArgs(array|null $args = null): object
throw new Exception\NotImplemented('Not implemented');
}

/**
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it good idea to add method to adapter?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, true, this should only be on the BetterReflection API, not on the adapter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I wasn't able to differentiate which is what and thought I need to reflect the change there. even easier if this is not required :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to call this new method from PHPStan ClassReflection. I guess this means we need it on the adapter then?

Copy link
Member

Choose a reason for hiding this comment

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

From an architectural PoV, it does not fit here: the adapter is only for mirroring the API of ext-reflection.

Anything beyond that already couples the consumer to BetterReflection, rather than ext-reflection, and should not be here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@clxmstaab PHPStan uses BR fork /~https://github.com/ondrejmirtes/BetterReflection/, so it can be implemented there.

Copy link
Member

Choose a reason for hiding this comment

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

even then, remember that the dependency is to ext-reflection, and the adapters are not supposed to deviate from that API.

@clxmstaab clxmstaab marked this pull request as ready for review July 31, 2023 10:48
Copy link
Contributor

@staabm staabm left a comment

Choose a reason for hiding this comment

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

I think this should be good to go

(sorry for mixing commits from my personal and my corporate account..)

Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

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

Thanks @staabm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants