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

Use ReflectionParameter::getType() instead of getClass() #240

Conversation

DerManoMann
Copy link

ReflectionParameter::getClass() is deprecated as of PHP 8 and will trigger a warning.

@GrahamCampbell
Copy link
Contributor

Note that this is not the same as before. You also need to resolve self to the actual class name.

@GrahamCampbell
Copy link
Contributor

@DerManoMann
Copy link
Author

That can be done like this: https://github.com/laravel/framework/blob/v7.18.0/src/Illuminate/Support/Reflector.php#L24-L30.

Updated - Thanks. I had a quick look at the tests but couldn't find an obvious place to add a test.
If it is preferred to add one I would appreciate a nudge into the right direction...

@jaapio
Copy link
Member

jaapio commented Jul 3, 2020

Hi @DerManoMann,

I think his is covered by the 3 cases below this line: https://github.com/phpDocumentor/ReflectionDocBlock/blob/master/tests/unit/DocBlock/StandardTagFactoryTest.php#L171

This part of the code is used to inject dependencies into the factory method of the tags.
Please let me know if you need any help to get this tested.

@DerManoMann
Copy link
Author

Happy to believe you @jaapio :)

There are certainly tests failing without the typehint working, so regessions are covered IMO.

Just not sure what to do about the QA workflow apparently being broken. AFAICS the break is unrelated to my change...

@jaapio
Copy link
Member

jaapio commented Jul 6, 2020

Please rebase this pr. Than ci will be fixed. I did that last week when I saw this pr failing.

`iReflectionParameter::getClass()` is deprecated as of PHP 8 and will
trigger a warning.
@jaapio
Copy link
Member

jaapio commented Jul 6, 2020

Thanks for rebasing this... If you have time it would be very nice if you could fix the failing steps. php 8 can be ignored for now since we are waiting for some external dependencies to be fixed.

@DerManoMann
Copy link
Author

sure, will try today. is there documents on how to run those tests locally, perhaps?

@jaapio
Copy link
Member

jaapio commented Jul 6, 2020

If you have docker on your local machine you can use the make file.

@DerManoMann DerManoMann force-pushed the reflectionparameter-getclass-deprecated-php8 branch 3 times, most recently from e00d5b0 to 0690553 Compare July 6, 2020 22:39
@DerManoMann DerManoMann force-pushed the reflectionparameter-getclass-deprecated-php8 branch from 0690553 to 321abc5 Compare July 6, 2020 23:00
@GrahamCampbell
Copy link
Contributor

These changes are actually not correct. They don't deal with union types properly. I'll send a replacement PR.

@jaapio
Copy link
Member

jaapio commented Jul 7, 2020

@GrahamCampbell I think you could have said this in a different way. Your help is very much appreciated, like the help of everyone else. @DerManoMann is doing a very good job here to help us move forward and I don't think we should just close this pr or superseded his contributions by creating a separate pr.
I think it would be more helpful for the project to help him improve this PR.

@GrahamCampbell
Copy link
Contributor

@jaapio Is there a bug in the original code? Could you help me understand what's going on. Why do we resolve the type using reflection and then look it up in the locator array. I think the locator is only meant to be used to look up parameter names, and not types?

@ondrejmirtes
Copy link

I don't even think that support for unions has to be added as part of this PR. A 2-step approach can be taken:

  1. Make sure we don't use any deprecated functionality when running on PHP 8.
  2. Support all the new stuff from PHP 8 like union types, static, mixed...

Even 1) as a separate release would be useful.

@GrahamCampbell
Copy link
Contributor

Line 263 of StandardTagFactory of the code on master.

@GrahamCampbell
Copy link
Contributor

Oh, I think I see what's going on...

@jaapio
Copy link
Member

jaapio commented Jul 7, 2020

This method is an internal method... it might support UnionTypes at some point. But this is NOT about reflecting types on docblock content it is just meant to be some dependency injection mechanism for tags. It has nothing to do with docblock or type resolving.

@GrahamCampbell
Copy link
Contributor

Yeh. I don't think we want to support union types in that method. Doesn't make sense for a service locator to inspect union types, other than a union with null. Tests pass on my machine, but your makefile doesn't run on PHP 8 (because phpunit isn't managed by composer). Will have to wait to see what GitHub actions says.

@jaapio
Copy link
Member

jaapio commented Jul 7, 2020

Yes you are right we don't need Uniontypes here. Since this library is only reflecting docblock which do support uniontypes since ..... I don't expect much changes to be needed to support php8 :-)

As I explained earlier to you we cannot manage PHPUnit via composer. since this library is a dependency of phpunit. PR's simply won't build with composer :-)
phpunit is installed with phive, as a phar with scoped namespaces so we are sure that phpunit is using the required version of this lib. And we are testing the version that needs to be tested. Instead of letting php mess with the autoloading, testing the wrong version.

@jaapio
Copy link
Member

jaapio commented Jul 7, 2020

All green, Think this is good to go. Thanks @DerManoMann!

@jaapio jaapio merged commit 7c87da1 into phpDocumentor:master Jul 7, 2020
@mvriel
Copy link
Member

mvriel commented Jul 7, 2020

Thanks @jaapio!

@mvriel
Copy link
Member

mvriel commented Jul 7, 2020

And most of all, thank you @DerManoMann to take the time to help us out here

@GrahamCampbell
Copy link
Contributor

#242

@GrahamCampbell
Copy link
Contributor

GrahamCampbell commented Jul 7, 2020

Tests pass on my machine, but your makefile doesn't run on PHP 8 (because phpunit isn't managed by composer).

I was referring to the replacement PR I was preparing: #242.

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.

5 participants