-
-
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
Allow to configure PHPMD with php or yaml file #1058
base: 3.x
Are you sure you want to change the base?
Conversation
67d9440
to
2bedff3
Compare
Note: the src/conf/phpmd.schema.json file is what allow auto-completion in IDEs: To be automatically applied to Then to be associated to relevant file names in the catalog: |
src/test/resources/files/rulesets/phpmd.yml is an example of how it would look to configure rule with a YAML file. It would work the same by providing JSON file or PHP file returning the same array structure. |
$options = new CommandLineOptions([__FILE__, 'app', 'sarif']); | ||
|
||
$args = [__FILE__, 'text', 'design']; | ||
new CommandLineOptions($args); | ||
self::assertSame('cleancode,codesize,controversial,design,naming,unusedcode', $options->getRuleSets()); | ||
self::assertSame('sarif', $options->getReportFormat()); | ||
self::assertSame('app', $options->getInputPath()); | ||
|
||
$options = new CommandLineOptions([__FILE__, 'app']); | ||
|
||
self::assertSame('cleancode,codesize,controversial,design,naming,unusedcode', $options->getRuleSets()); | ||
self::assertSame('text', $options->getReportFormat()); | ||
self::assertSame('app', $options->getInputPath()); | ||
|
||
$options = new CommandLineOptions([__FILE__]); | ||
|
||
self::assertSame('cleancode,codesize,controversial,design,naming,unusedcode', $options->getRuleSets()); | ||
self::assertSame('text', $options->getReportFormat()); | ||
self::assertSame('src', $options->getInputPath()); |
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.
Arguments would all become optional:
See the default values on https://github.com/phpmd/phpmd/pull/1058/files#diff-d7bddc86dbcab23cca1d846c4d63a3957de2b6d196f6e4527e18161ff908118b
0 => [file_exists('src') ? 'src' : '.', 'text', $this->getDefaultConfig()], | ||
1 => ['text', $this->getDefaultConfig()], | ||
2 => [$this->getDefaultConfig()], | ||
default => [], |
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.
- input path would fallback to "src" if it's exist, "." else
- report format would fallback to "text"
- ruleset would fallback to first config file found by
getDefaultConfig
, or "all" if no file provided.
|
||
$validator = new ArgumentsValidator($hasImplicitArguments, $originalArguments, $arguments); | ||
|
||
$this->ruleSets = (string)array_pop($arguments); | ||
$ruleSets = (string)array_pop($arguments); | ||
$this->ruleSets = $ruleSets === 'all' ? InternalRuleSet::getNamesConcatenated() : $ruleSets; |
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.
"all" would be a shorthand for all internal rulesets from PHPMD:
cleancode,codesize,controversial,design,naming,unusedcode
dabeb46
to
51c1a92
Compare
799e1db
to
5173ebb
Compare
51c1a92
to
0439441
Compare
0439441
to
7775855
Compare
Not using XML is a big improvement in my book. I prefer the PHP option personally. @kylekatarnls I think now is a good point to rebase this so it's ready for merging. |
…ti-format-support # Conflicts: # composer.json # src/main/php/PHPMD/RuleSetFactory.php # src/main/php/PHPMD/TextUI/CommandLineOptions.php # src/test/php/PHPMD/RuleSetFactoryTest.php # src/test/php/PHPMD/RuleSetTest.php # src/test/php/PHPMD/TextUI/CommandLineOptionsTest.php
fa728ee
to
c7d924c
Compare
c7d924c
to
2be8831
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 3.x #1058 +/- ##
============================================
+ Coverage 92.15% 92.22% +0.07%
- Complexity 1278 1297 +19
============================================
Files 107 109 +2
Lines 3378 3448 +70
============================================
+ Hits 3113 3180 +67
- Misses 265 268 +3 ☔ View full report in Codecov by Sentry. |
*/ | ||
public function getMetric($name) | ||
public function getMetric(string $name): null|float|int |
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 doesn't cover numeric-string, i think that might be used some times, though I'm not 100% sure.
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.
We should not use string to represent numbers, they all come from getNodeMetrics
from PDepend, I will make a PR to ensure/enforce them.
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 checked them all, no string https://github.com/pdepend/pdepend/pull/826/files
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 was wrong, npath is a numeric string, it sounds it was to support integer numbers bigger than 64 bits.
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.
We could add a php64 requirement in composer.
314aee6
to
2b5bd39
Compare
…ti-format-support
1fa1037
to
df1b444
Compare
df1b444
to
2585b4e
Compare
@@ -32,31 +36,18 @@ class RuleSetFactory | |||
/** |
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 calls is getting a bit heavy on pulling out mixed variables and casting them to various types. This is likely going to trigger a lot of unsafe operations on higher PHPStan levels.
Lots of things going on in one PR, most of it is nice, but a bit hard to review and comment on individual things with it all there. |
In theory bcmul can go even above 64 bits, but I wonder if it has a real interest in practice for npath (and also why it would be the only one using big number). BTW it also possible to go above by using float (which is automatic in PHP), it just loose a bit of precision but I'm not sure it's an actual problem, if you have billion npath, you probably care about order of magnitude, not an exact value. |
i wold normally just use it if decimal fractional rounding is important, I have a hard time imagining the need for values that high. |
I'm also unsatisfied about how it growth after re-basing. I will split. |
Type: feature
Breaking change: yes