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

Cache invalidation for different file than edited #6797

Closed
ondrejmirtes opened this issue Mar 11, 2022 Discussed in #6795 · 2 comments · Fixed by phpstan/phpstan-src#1427
Closed

Cache invalidation for different file than edited #6797

ondrejmirtes opened this issue Mar 11, 2022 Discussed in #6795 · 2 comments · Fixed by phpstan/phpstan-src#1427
Labels
Milestone

Comments

@ondrejmirtes
Copy link
Member

Bug report

Discussed in #6795

Originally posted by ShookTea March 11, 2022
Hi!

Recently I played a little with attributes in PHP 8 and custom rules and created a #[NonDirectMethod] attribute that accepts array of classes that can call such method (for example to enforce using factories for some classes instead of directly calling constructors).

Example usage:

class UserJsonModel
{
    #[NonDirectMethod(allowedIn: [
        UserJsonModelFactory::class,
        UserDetailedJsonModelFactory::class,
    ])]
    public function __construct(User $user)
    {
        // ...
    }
}

Then, I created custom rules for PhpStan that look for New_ and MethodCall nodes and checks if class calling such method is present in allowedIn array of attribute.

It works perfectly well, but problems arise when content of allowedIn is changed, because - as far, as I understand - only UserJsonModel class will have invalidated cache here, which brings problems:

  • if I remove UserDetailedJsonModelFactory from allowedIn, but keep calling constructor, I will get false positive result for that factory up until running clear-result-cache
  • If I create a new class, call constructor there, run analyze (which will correctly give me negative result) and then add a new class to allowedIn, I will still get a false negative result up until running clear-result-cache

I was wondering if there is some way of creating a custom extension of cache invalidation. In this scenario, such extension will see that cache for some file was invalidated, it will notice that there is a method in that file with #[NonDirectMethod] attribute and will call invalidation for files described in allowedIn attribute.

@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Mar 11, 2022
@mergeable
Copy link

mergeable bot commented Mar 11, 2022

This bug report is missing a link to reproduction on phpstan.org.

It will most likely be closed after manual review.

@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 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant