You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
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.
The text was updated successfully, but these errors were encountered:
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:
Then, I created custom rules for PhpStan that look for
New_
andMethodCall
nodes and checks if class calling such method is present inallowedIn
array of attribute.It works perfectly well, but problems arise when content of
allowedIn
is changed, because - as far, as I understand - onlyUserJsonModel
class will have invalidated cache here, which brings problems:UserDetailedJsonModelFactory
fromallowedIn
, but keep calling constructor, I will get false positive result for that factory up until runningclear-result-cache
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 inallowedIn
attribute.The text was updated successfully, but these errors were encountered: