-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
Create common utility to handle exceptions lists #982
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 3.x #982 +/- ##
============================================
- Coverage 92.66% 89.09% -3.57%
+ Complexity 1238 1197 -41
============================================
Files 111 110 -1
Lines 3447 3073 -374
============================================
- Hits 3194 2738 -456
- Misses 253 335 +82 ☔ View full report in Codecov by Sentry. |
I like this change, but I think it would be best to have it as part of the 3.0 branch because of the difference of behavior and signatures. |
OK, then I'll handle #924 using array version. 👌 |
83796a9
to
43266a5
Compare
Type: refactoring
Breaking change: yes (protected scope)
BC:
getExceptionsList()
can be called from custom rules that would extendsStaticAccess
,TooManyMethds
,LongClassName
,ShortClassName
,LongVariable
,ShortVariable
,ShortMethodName
orUnusedLocalVariable
previously returnedarray
and will now return a object implementingIteratorAggregate
,ArrayAccess
so if user iterates over it or callisset($exceptions[$key])
the resulting behavior will be the same, but if they expect exactly an array (strong typing or using somearray_
method on it), they will need to replace$this->getExceptionList()
withiterator_to_array($this->getExceptionList())
also if they overriddengetExceptionList()
in a sub-class, they will need to wrap the returned value in a class like:Risk of BC for real users is low as users are encouraged to extends
AbstractRule
to create their own, there is little interest to extend an actual rule (BTW, they should likely befinal
in next major version, and have their methods private)Motivation: we have all the listed rules above having a
getExceptionList()
method, all with very close code:array_flip
on the list then callisset
instead ofin_array
, this variant add a fixed cost per activated rule but reduces to cost per iteration (method/class/function/variable). As per my benchmark it will benefit to each rule checking more than 13 times the exceptions list, so it would benefit to most of the projects/usages when PHPMD is given big code base, and it would make slower only analyses of very small project or partial analyze (such as a single-file check). So, in my opinion it makes sense to use theisset()
variant for all rules.,,
would in some rules generate a blank exception, in some other not, in some case whitespace around comas will be ignored but not in all rules. It sounds those differences are not wanted and just edge-case bugs. Harmonizing them would ensure a givenexceptions
could be used for any rule in the config and be handled the same way.\
with whitespace, this makes sense only for class name, so I make it as a parameter and only exceptions list meant to be checked against class name have it, other get the default value""
so only whitespace is trimmed.Apart the
$trim
parameter then now rules supportingexceptions
config will all have the same method implementation with minimum code:After dropping PHP 5.3 this can became a trait and minimize the duplicate code accros rules.
#924 will also require to add this config.