I found in my project that I had a couple of t() statements that were not being detected by the DrupalPractice standard.
I did some digging and it turns out that the detection of global function calls currently only considers services, and ignores any classes (such as controllers and forms) that are not services but still have access to the container since they implement DependencyInjectionInterface.
Also, t() is actually a special case, since this is no longer reliant on injecting a service, but can be accessed in any class through the StringTranslationTrait, regardless of whether the class has access to the container or not.
Comments
Comment #2
pfrenssenComment #3
pfrenssenhttps://github.com/pfrenssen/coder/pull/46
Comment #5
klausiCommitted, thanks!
Comment #6
klausiSorry messed up the commit author, but at least I can give you credit here.
Comment #7
pfrenssenNo problem about the commit credit, thanks for the quick action!
Comment #8
amitaibuI'm not 100% sure if this is this PR , but suddenly I get this warning on my Drupal 7 (not 8)
Comment #9
klausiI think this code should be guarded by project version detection and not trigger on Drupal 7. Any chance you can show a bit of code that triggers the false positive?
Comment #10
amitaibuSure, here's the code - https://gist.github.com/amitaibu/6ee81811090fb2007b7e9d689799be82 (class, and the info file of the module)
Comment #11
klausiMarking as active to check back when I have time.
Comment #13
klausiImplemented a fix to exclude Drupal 7 and lower from this sniff.
You can also just disable this sniff for your Drupal 7 projects anyway because it does not make sense there.