Closed llaville closed 4 months ago
My SARIF PHP SDK has an upcoming version 1.4.0 that will add PHPMD (PHP Mess Detector) to support SARIF.
Even if PHPMD has already a native support, my version gave more informations, and is not maintained by authors of PHPMD.
This is the goal of my proposal here. No need to maintained a SARIF output format, because I'll do if you accept this POC !
I've just published https://github.com/llaville/sarif-php-sdk/releases/tag/1.4.0 that support PHPMD !
Do you want to be the next one on list ?
Any feedback will be greatly appreciated ?
Hello,
As author of the SARIF PHP binding solution https://github.com/llaville/sarif-php-sdk I would like to propose a SARIF support.
For audience that don't know yet what is SARIF (Static Analysis Results Interchange Format), I suggest to read :
But my proposal is not limited to SARIF. With it we could add support to other formats not yet supported.
That will include, for example :
And whatever else we will need !
Now that introduction is opened, here is in details my proposal !
A
Povils\PHPMND\Printer\Custom
class that implements the standardPovils\PHPMND\Printer\Printer
contract and inspired by https://github.com/phpmd/phpmd/blob/2.15.0/src/main/php/PHPMD/TextUI/CommandLineOptions.php#L780CLI options will be only :
And remove old
--xml-ouptut
optionHere are some use cases :
Console (default output)
No change because this is the default. (Option to write/redirect results to a file with
--output
option)SARIF format
source code
```phpCheckstyle format
Now a version of CheckStyle implementation we can have :
source code
```php groupDetectionResultPerFile($detections); $document = new DOMDocument('1.0', 'UTF-8'); $document->formatOutput = true; $rootElement = $document->createElement('checkstyle'); $document->appendChild($rootElement); foreach ($groupedList as $path => $detectionResults) { $fileNode = $document->createElement('file'); $fileNode->setAttribute('name', $path); $rootElement->appendChild($fileNode); foreach ($detectionResults as $detectionResult) { $snippet = $this->getSnippet( $detectionResult->getFile()->getContents(), $detectionResult->getLine(), $detectionResult->getValue() ); $errorNode = $document->createElement('error'); $errorNode->setAttribute('line', (string) $detectionResult->getLine()); $errorNode->setAttribute('column', (string) $snippet['col']); $errorNode->setAttribute('severity', 'error'); $errorNode->setAttribute( 'message', sprintf('Magic Number: %s', $detectionResult->getValue()) ); $fileNode->appendChild($errorNode); } $rootElement->appendChild($fileNode); } $xmlString = $document->saveXML(); if (is_string($xmlString)) { $output->write($xmlString); } } /** * @param arrayI'll propose a POC PR (not optimized, because we can do better, but essential are available) and link to this feature request just after.