From d61cf62b41717ea1f3f14381035bfe9272fe7b74 Mon Sep 17 00:00:00 2001 From: Jordi Kroon Date: Thu, 23 Apr 2026 23:52:09 +0200 Subject: [PATCH 1/2] feat: add configurable severity levels for sniffs Change default violation severity from WARNING to ERROR and add support for overriding severity via sniff properties. The severity level is now resolved from configuration using Severity::tryFrom() with validation that throws LogicException if an invalid severity is configured. Add missing Severity use statements and document the exception in PHPDoc comments across all affected sniffs. --- src/Sniff/AbstractSniff.php | 6 ++++-- src/Sniff/AttributeOrderSniff.php | 4 ++++ src/Sniff/ExceptionNameSniff.php | 3 +++ src/Sniff/SimparaSniff.php | 3 +++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Sniff/AbstractSniff.php b/src/Sniff/AbstractSniff.php index 34cb185..89dc576 100644 --- a/src/Sniff/AbstractSniff.php +++ b/src/Sniff/AbstractSniff.php @@ -22,18 +22,20 @@ protected function getProperty(string $name, string $default = ''): string return $this->properties[$name] ?? $default; } + /** @throws \LogicException if an invalid severity level is configured */ protected function createViolation( string $filePath, int $line, string $message, - Severity $severity = Severity::WARNING, + Severity $severity = Severity::ERROR, ): Violation { return new Violation( sniffCode: $this->getCode(), filePath: $filePath, line: $line, message: $message, - severity: $severity, + severity: Severity::tryFrom($this->getProperty('severity', $severity->value)) + ?: throw new \LogicException('Invalid severity level configured for ExceptionNameSniff.'), ); } } diff --git a/src/Sniff/AttributeOrderSniff.php b/src/Sniff/AttributeOrderSniff.php index 97baf57..a407a1d 100644 --- a/src/Sniff/AttributeOrderSniff.php +++ b/src/Sniff/AttributeOrderSniff.php @@ -4,6 +4,8 @@ namespace DocbookCS\Sniff; +use DocbookCS\Report\Severity; + /** * Ensures that when an element has both xml:id and xmlns (or xmlns:*) * attributes, xml:id appears first. @@ -18,6 +20,7 @@ public function getCode(): string return 'DocbookCS.AttributeOrder'; } + /** @throws \LogicException if an invalid severity level is configured */ public function process(\DOMDocument $document, string $content, string $filePath): array { $violations = []; @@ -51,6 +54,7 @@ public function process(\DOMDocument $document, string $content, string $filePat /** * @param list<\DocbookCS\Report\Violation> &$violations + * @throws \LogicException if an invalid severity level is configured */ private function checkAttributes( string $tagName, diff --git a/src/Sniff/ExceptionNameSniff.php b/src/Sniff/ExceptionNameSniff.php index 412eb53..7981dde 100644 --- a/src/Sniff/ExceptionNameSniff.php +++ b/src/Sniff/ExceptionNameSniff.php @@ -4,6 +4,8 @@ namespace DocbookCS\Sniff; +use DocbookCS\Report\Severity; + /** * Detects exception/error class names wrapped in that * should use instead. @@ -28,6 +30,7 @@ public function getCode(): string return 'DocbookCS.ExceptionName'; } + /** @throws \LogicException if an invalid severity level is configured */ public function process(\DOMDocument $document, string $content, string $filePath): array { $violations = []; diff --git a/src/Sniff/SimparaSniff.php b/src/Sniff/SimparaSniff.php index 5ad518e..57e5eb9 100644 --- a/src/Sniff/SimparaSniff.php +++ b/src/Sniff/SimparaSniff.php @@ -4,6 +4,8 @@ namespace DocbookCS\Sniff; +use DocbookCS\Report\Severity; + final class SimparaSniff extends AbstractSniff { private const array SIMPARA_ALLOWED = [ @@ -101,6 +103,7 @@ public function getCode(): string return 'DocbookCS.Simpara'; } + /** @throws \LogicException if an invalid severity level is configured */ public function process(\DOMDocument $document, string $content, string $filePath): array { $violations = []; From 4e859ae5d35919d35ea9939f2969266bada1fa9f Mon Sep 17 00:00:00 2001 From: Jordi Kroon Date: Fri, 24 Apr 2026 00:07:42 +0200 Subject: [PATCH 2/2] refactor: remove unused Severity imports Remove unused imports of DocbookCS\Report\Severity from three sniff classes that no longer reference this class. --- src/Sniff/AttributeOrderSniff.php | 2 -- src/Sniff/ExceptionNameSniff.php | 2 -- src/Sniff/SimparaSniff.php | 2 -- 3 files changed, 6 deletions(-) diff --git a/src/Sniff/AttributeOrderSniff.php b/src/Sniff/AttributeOrderSniff.php index a407a1d..b4d03eb 100644 --- a/src/Sniff/AttributeOrderSniff.php +++ b/src/Sniff/AttributeOrderSniff.php @@ -4,8 +4,6 @@ namespace DocbookCS\Sniff; -use DocbookCS\Report\Severity; - /** * Ensures that when an element has both xml:id and xmlns (or xmlns:*) * attributes, xml:id appears first. diff --git a/src/Sniff/ExceptionNameSniff.php b/src/Sniff/ExceptionNameSniff.php index 7981dde..2ff14ce 100644 --- a/src/Sniff/ExceptionNameSniff.php +++ b/src/Sniff/ExceptionNameSniff.php @@ -4,8 +4,6 @@ namespace DocbookCS\Sniff; -use DocbookCS\Report\Severity; - /** * Detects exception/error class names wrapped in that * should use instead. diff --git a/src/Sniff/SimparaSniff.php b/src/Sniff/SimparaSniff.php index 57e5eb9..e86d1bd 100644 --- a/src/Sniff/SimparaSniff.php +++ b/src/Sniff/SimparaSniff.php @@ -4,8 +4,6 @@ namespace DocbookCS\Sniff; -use DocbookCS\Report\Severity; - final class SimparaSniff extends AbstractSniff { private const array SIMPARA_ALLOWED = [