Skip to content

Conversation

rajyan
Copy link
Contributor

@rajyan rajyan commented Mar 9, 2022

continue;
}
if (!$fetchNode->name instanceof Node\Identifier) {
if ($fetchNode->class instanceof Node\Expr\Variable && $fetchNode->class->name === 'this') {
Copy link
Member

Choose a reason for hiding this comment

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

This isn't a general fix for this problem. For example it's not gonna fix this scenario:

$self = $this;
echo $self::HELLO;

or this:

$self = new self();
echo $self::HELLO;

The correct fix this: Acknowledge that ClassConstFetch::$class can contain either a Name or an Expr.

If it's a Name then just check the class name using $scope->resolveName(). If it's an Expr, get type using $scope->getType(). If it's a TypeWithClassName, continue and treat it the same way as the Name in ClassConstFetch::$class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your great pointers.
I didn't even know that the first example is a valid syntax! Fixing now.

@rajyan rajyan requested a review from ondrejmirtes March 9, 2022 12:49
Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

Otherwise 👍

public function testBug6758(): void
{
if (!self::$useStaticReflectionProvider) {
$this->markTestSkipped('Test requires static reflection');
Copy link
Member

Choose a reason for hiding this comment

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

Why static reflection? There's nothing special about the file.

Copy link
Contributor Author

@rajyan rajyan Mar 9, 2022

Choose a reason for hiding this comment

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

Sorry, I'm not sure about why this is need that much, but I added because it failed with

05: Class Bug6758\HelloWorld was not found while trying to analyse it - discovering symbols is probably not configured properly.
    💡 Learn more at https://phpstan.org/user-guide/discovering-symbol

without reflection in local testing.

I can run testRule() with no errors by the way...

Copy link
Member

Choose a reason for hiding this comment

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

You need to run composer dump after you add a new class.

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.
I didin't know about classmaps...

@ondrejmirtes ondrejmirtes merged commit 9338d41 into phpstan:master Mar 9, 2022
@ondrejmirtes
Copy link
Member

Thank you!

@rajyan rajyan deleted the fix/issue-6758 branch March 9, 2022 14:01
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.

Incorrect unused reporting on private class const when called using $this::PRIVATE syntax
2 participants