-
-
Notifications
You must be signed in to change notification settings - Fork 947
Cache invalidation for different file than edited #6797
Description
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
UserDetailedJsonModelFactoryfromallowedIn, but keep calling constructor, I will get false positive result for that factory up until runningclear-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 toallowedIn, I will still get a false negative result up until runningclear-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.