-
-
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
Implement LongMethodName #1045
base: master
Are you sure you want to change the base?
Implement LongMethodName #1045
Conversation
5aacc5d
to
2c4a806
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1045 +/- ##
============================================
+ Coverage 92.53% 92.58% +0.04%
- Complexity 1239 1244 +5
============================================
Files 111 112 +1
Lines 3404 3424 +20
============================================
+ Hits 3150 3170 +20
Misses 254 254 ☔ View full report in Codecov by Sentry. |
c298eb2
to
9ba3709
Compare
e40380d
to
9526335
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for the new rule.
Reviewed code-only, didn't test it.
} | ||
|
||
/** | ||
* @return list<string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think list
is supported by all API doc tools:
https://docs.phpdoc.org/3.0/guide/guides/types.html#supported-types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list
is now supported for years by PHPStorm, Plsam, PHPStan and Phan, it adds an interesting precision that keys of an array $value
are strictly equal to range(0, count($value)-1)
(I.E. being ordered integer sequence starting at 0, see array_is_list). Such as the result of explode
, array_values
, array_keys
.
IMO giving the benefit to the majority of tools who support it worth to drop other tools supports (which should fallback if they don't know how to read the annotation: to array
if the return type is specified, else to mixed
).
/** | ||
* Utility class to handle rule exceptions property | ||
*/ | ||
class ExceptionProperty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is quite a lot of code to replace a few lines previously. Not sure what to feel about it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will make getExceptionList()
to disappear completely in the next version and we can simply make exceptions
available and working the same way for all the rule.
So on the next version it's more feature with way less (redundant) code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And introduce it now creates an easier step for people who created custom routes to prepare for upgrade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would need more discussion as it's a bit more opinionated but other types of config could also be shared so to make them also working the same way across different rules and auto-discoverable and auto-documented.
For instance with attributes (but would need to drop PHP <= 7):
class LongMethodName extends AbstractRule
{
#[ConfigProperty(description: 'Comma-separated list of exceptions')]
protected ExceptionProperty $exceptions;
#[ConfigProperty(description: 'Maximum length for a method or function name')]
protected Threshold $maximum;
}
Without dropping PHP version, it can be dependency-injection:
class LongMethodName extends AbstractRule
{
public function __construct(
/** Comma-separated list of exceptions */
ExceptionProperty $exceptions,
/** Maximum length for a method or function name */
Threshold $maximum,
) {
}
}
/** | ||
* @return array<string, int> | ||
*/ | ||
public function flip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there any less technical name to express what we actually want to achieve or what we actually get back from this method?
Also, not having doc blocks, doesn't help either. 😞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
array_flip is a micro-optimization so index and isset() can be used instead of in_array(). However if we plan to support pattern everywhere we allow exceptions, then we would no longer need it in next major version.
7610a25
to
b8cdf88
Compare
b8cdf88
to
13e8a14
Compare
</description> | ||
<priority>3</priority> | ||
<properties> | ||
<property name="maximum" description="Maximum length for a method or function name" value="20"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking a look at https://github.com/phpmd/phpmd/actions/runs/7159958473/job/19493792510?pr=1045#step:9:1769
I guess 20 might be a little short for a default value.
Type: feature
Issue: Resolves Fix #486
Breaking change: no