From f07f64d0fa74eb64295f423b112f3b3be587baf3 Mon Sep 17 00:00:00 2001 From: Laurent Laville Date: Sat, 7 Dec 2024 09:02:42 +0000 Subject: [PATCH] upgrade SARIF output format (using bartlett/sarif-php-converters package) --- .changes/unreleased/Changed-20241207-090052.yaml | 3 +++ src/Output/SarifOutput.php | 8 +++++++- vendor-bin/sarif/composer.json | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changes/unreleased/Changed-20241207-090052.yaml create mode 100644 vendor-bin/sarif/composer.json diff --git a/.changes/unreleased/Changed-20241207-090052.yaml b/.changes/unreleased/Changed-20241207-090052.yaml new file mode 100644 index 00000000..60e57416 --- /dev/null +++ b/.changes/unreleased/Changed-20241207-090052.yaml @@ -0,0 +1,3 @@ +kind: Changed +body: upgrade SARIF output to support [PhpLintConverter](https://llaville.github.io/sarif-php-converters/1.0/converter/phplint/) of bartlett/sarif-php-converters package +time: 2024-12-07T09:00:52.188093881Z diff --git a/src/Output/SarifOutput.php b/src/Output/SarifOutput.php index 51546bb9..652fb227 100644 --- a/src/Output/SarifOutput.php +++ b/src/Output/SarifOutput.php @@ -20,6 +20,8 @@ use Symfony\Component\Console\Formatter\OutputFormatterInterface; use Symfony\Component\Console\Output\StreamOutput; +use function class_exists; +use function dirname; use function ob_get_clean; use function ob_start; @@ -38,8 +40,12 @@ public function __construct( ?OutputFormatterInterface $formatter = null, ?ConverterInterface $converter = null ) { + if (!class_exists(PhpLintConverter::class)) { + // use default Composer-Bin-Plugin autoloader to load Sarif-Php-Converters components + require_once dirname(__DIR__, 2) . '/vendor-bin/sarif/vendor/autoload.php'; + } parent::__construct($stream, $verbosity, $decorated, $formatter); - $this->converter = $converter ?? new PhpLintConverter(null, $this->isVerbose()); + $this->converter = $converter ?? new PhpLintConverter(['format_output' => $this->isVerbose()]); } public function getName(): string diff --git a/vendor-bin/sarif/composer.json b/vendor-bin/sarif/composer.json new file mode 100644 index 00000000..268aeb79 --- /dev/null +++ b/vendor-bin/sarif/composer.json @@ -0,0 +1,5 @@ +{ + "require-dev": { + "bartlett/sarif-php-converters": "^1.0" + } +}