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

Reflection error on class_alias object definition after upgraded from 0.12.4 to 0.12.9 #2958

Closed
shulard opened this issue Feb 6, 2020 · 7 comments

Comments

@shulard
Copy link

shulard commented Feb 6, 2020

Support question

Hello,

I'm using the hoa/websocket package which rely to class_alias to simplify some class names...

For example the class Hoa\Socket\Connection\Connection is aliased to Hoa\Socket\Connection.

You can check the definition here: https://github.com/hoaproject/Socket/blob/master/Source/Connection/Connection.php#L813

After updating to phpstan 0.12.9, I got an error :

Reflection error: Hoa\Socket\Connection not found.

Before the update, the analysis hasn't any trouble with the @param and @var aliased class names.

I saw that there is a new typeAliases in the configuration but it doesn't seems to fix my issue. Here is my local phpstan.neon configuration :

includes:
	- vendor/jangregor/phpstan-prophecy/src/extension.neon
parameters:
    level: max
    inferPrivatePropertyTypeFromConstructor: true
    paths:
        - public
        - src
        - tests
    typeAliases:
        Hoa\Socket\Connection: 'Hoa\Socket\Connection\Connection'
        Hoa\Stream: 'Hoa\Stream\Stream'

Do you know how to understand this issue and fix it ?

@ondrejmirtes
Copy link
Member

Type aliases will not help you here, that's not what they are meant for.

Can you please post some minimal code using Hoa library that it will crash on? So that I can have a regression test.

@shulard
Copy link
Author

shulard commented Feb 9, 2020

Yep I can create such code. Do you want that I make a PR somewhere or I just add the code here in a comment ?

@ondrejmirtes
Copy link
Member

Just here, and as minimal as possible. I think something very close to new Server(...) will suffice. Thanks.

@ondrejmirtes
Copy link
Member

I think I fixed it, please try the latest dev-master of phpstan/phpstan (phpstan/phpstan-src@c0cb3a6, 0749384). Thank you.

@ondrejmirtes
Copy link
Member

It's possible you'll have to add a line like this to your PHPStan's bootstrap (https://github.com/phpstan/phpstan#bootstrap-file - see README):

class_exists(\Hoa\Stream::class);

All of this is just because Hoa's aliases aren't friendly to static analysis, I reported this a few days ago: hoaproject/Consistency#34

@shulard
Copy link
Author

shulard commented Feb 10, 2020

Hello !

It seems to work on the dev-master version with a bootstrap file ! Thank you for the fix, I know that Hoa has a strange alias behaviour (hidden inside a function)... I'll try to help moving forward those new packages version to allow removing this specific code !

Thank you for your help 😉.

@lock
Copy link

lock bot commented Mar 12, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Mar 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants