Created
July 26, 2024 10:03
-
-
Save NeilMasters/a38356930554c89b63f7d713eb8aae48 to your computer and use it in GitHub Desktop.
PHPMD Pretty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
/** | |
* A very simple and basic utility that can be used to pipe phpmd errors and format | |
* in a cleaner way. This suits MY requirements and you will probably want line numbers | |
* etc so edit as you see fit. | |
* | |
* Example use: | |
* vendor/bin/phpmd ./src xml ./ruleset.xml | bin/phpmd-pretty | |
*/ | |
$data = stream_get_contents(STDIN); | |
$xmlDom = simplexml_load_string( | |
$data, | |
"SimpleXMLElement", LIBXML_NOCDATA | |
); | |
foreach ($xmlDom->file as $file) { | |
echo sprintf( | |
"%s %s", | |
trim($file->attributes()->name->__toString()), | |
PHP_EOL | |
); | |
foreach ($file->violation as $violation) { | |
echo sprintf( | |
"%s %s", | |
trim($violation->__toString()), | |
PHP_EOL | |
); | |
} | |
echo PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want a message when no violations are found instead of nothing being displayed add this above the foreach.