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

Changes to method/property attributes are not reflected in ExportedNodeResolver and therefore cache does not get invalidated #7413

Closed
olsavmic opened this issue Jun 6, 2022 · 3 comments

Comments

@olsavmic
Copy link

olsavmic commented Jun 6, 2022

Bug report

Changing method/property attributes does not trigger analysis of dependent files because PHP Attributes are not taken into account in src/Dependency/ExportedNodeResolver.php.

Although questionable, attributes are part of public API in my opinion (even though accessible only via reflection), especially for tools like PHPStan where I expect migration from annotations to attributes in the near future (PHPStorm already pushes usage of #[Deprecated], #[ArrayShape],...)

Current behaviour makes it impossible to write rules that disallow calling #[Deprecated] methods whereas the same example with @deprecated works properly.

Let's assume we have a rule that forbids calling methods that are deprecated.
Then following will happen with current behaviour.

Code snippet that reproduces the problem

<?php declare(strict_types = 1);

class Foo
{
	/**
	 * @deprecated
	 */
	public static function bar(): void
	{
	}
}

class Foo2
{
	#[Deprecated]
	public static function bar(): void
	{
	}
}
		
class C
{
    public function test(): void 
    {
        // Removing @deprecated annotation will correctly "invalidate" cache
        // and therefore not trigger an error
        Foo::bar();
        // Removing [#Deprecated] attribute will NOT "invalidate" cache 
        // and therefore error will still be there even though it's now OK to call the method
        Foo2::bar();
    }
}
@mergeable
Copy link

mergeable bot commented Jun 6, 2022

This bug report is missing a link to reproduction at phpstan.org/try.

It will most likely be closed after manual review.

@ondrejmirtes
Copy link
Member

Duplicate of #6797.

This is a pretty easy contribution, feel free to send a PR :)

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 16, 2022
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