phpmd / phpmd

PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD. PHPMD can be seen as an user friendly frontend application for the raw metrics stream measured by PHP Depend.
https://phpmd.org
BSD 3-Clause "New" or "Revised" License
2.34k stars 347 forks source link

Enforce own rules to the codebase #812

Open Morgy93 opened 4 years ago

Morgy93 commented 4 years ago

Description

Hello,

it would be awesome if you could enforce your own rules to your own code, because people could then have a look at it for reference. I just opened up the very first file I came across and immediately saw multiple rule violations:

https://phpmd.org/rules/cleancode.html#elseexpression https://github.com/phpmd/phpmd/blob/master/src/bin/phpmd#L25 https://github.com/phpmd/phpmd/blob/master/src/bin/phpmd#L48

https://phpmd.org/rules/design.html#exitexpression https://github.com/phpmd/phpmd/blob/master/src/bin/phpmd#L55 https://github.com/phpmd/phpmd/blob/master/src/bin/phpmd#L61

"If they don't care about their rules, why should I" - would probably be the first thought for many. 😄

Checks before submitting

tvbeek commented 4 years ago

@Morgy93 thanks for your issue.

There are indeed parts of the code that need to be changed to follow the rules. There are only some things to think about.

The rules aren't holy (else there shouldn't be a way to suppress them see: https://phpmd.org/documentation/suppress-warnings.html )

And there are situations where there a rule isn't possible to use without loosing functionality. Like the exit expressions that you point out. We could return 1; instead of exit(1); but that result in a different exit code and doesn't make it clear for a pipeline that it failed.

Feel free to create a PR fixing (some off) the parts where PHPMD doesn't follow its own rules. Or annotate the suppressing of the places where it is impossible to follow the rules.