From 60ccbbe11d1a7a8196a00c73c044ee0fa96ac80a Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Fri, 10 Mar 2023 13:30:26 +0100 Subject: [PATCH] slack interfaces/protocols (#253) Signed-off-by: Jan Kowalleck --- HISTORY.md | 6 +++++- src/Core/Serialization/BaseSerializer.php | 2 -- src/Core/Serialization/Serializer.php | 8 +++----- src/Core/Serialization/XmlSerializer.php | 3 +-- src/Core/Validation/Validator.php | 9 --------- src/Core/Validation/Validators/JsonValidator.php | 2 -- src/Core/Validation/Validators/XmlValidator.php | 4 ---- 7 files changed, 9 insertions(+), 25 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index b0bdbe45..4ae798a8 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -140,7 +140,8 @@ All notable changes to this project will be documented in this file. * BREAKING: renamed namespace to `Serialization` ([#5] via [#146]) * `SerializerInterface` interface * BREAKING: renamed to `Serializer` ([#133] via [#155]) - * BREAKING: existing method `serialize()` got a new optional parameter `$prettyPrint` (via [#155]) + * BREAKING: method `serialize()` got a new optional parameter `$prettyPrint` (via [#155]) + * BREAKING: method `serialize()` may throw `\Throwable`, was `\Exception` (via [#253]) * `BaseSerializer` abstract class * BREAKING: complete redesign (via [#155]) * `{Json,Xml}Serializer` class @@ -187,6 +188,8 @@ All notable changes to this project will be documented in this file. * BREAKING: removed deprecated method `setSpec()` (via [#144]) * `ValidatorInterface` interface * BREAKING: renamed interface to `Validator` ([#133] via [#143]) + * Removed specification of constructor `__construct()` (via [#253]) + * Removed specification of method `getSpec()` (via [#253]) * `Validators\{Json,Xml}Validator` classes * Added support for CycloneDX v1.4 ([#57] via [#65]) * `Validators\JsonValidator` classes @@ -241,6 +244,7 @@ All notable changes to this project will be documented in this file. [#241]: https://github.com/CycloneDX/cyclonedx-php-library/pull/241 [#247]: https://github.com/CycloneDX/cyclonedx-php-library/issues/247 [#249]: https://github.com/CycloneDX/cyclonedx-php-library/pull/249 +[#253]: https://github.com/CycloneDX/cyclonedx-php-library/pull/253 ## 1.6.3 - 2022-09-15 diff --git a/src/Core/Serialization/BaseSerializer.php b/src/Core/Serialization/BaseSerializer.php index ccd8286c..cbed099c 100644 --- a/src/Core/Serialization/BaseSerializer.php +++ b/src/Core/Serialization/BaseSerializer.php @@ -111,8 +111,6 @@ abstract protected function realNormalize(Bom $bom) /* : TNormalizedBom */; * * @throws Exception * - * @psalm-return non-empty-string - * * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ abstract protected function realSerialize(/* TNormalizedBom */ $normalizedBom, ?bool $prettyPrint): string; diff --git a/src/Core/Serialization/Serializer.php b/src/Core/Serialization/Serializer.php index 6c253f65..ff6ec068 100644 --- a/src/Core/Serialization/Serializer.php +++ b/src/Core/Serialization/Serializer.php @@ -24,7 +24,7 @@ namespace CycloneDX\Core\Serialization; use CycloneDX\Core\Models\Bom; -use Exception; +use Throwable; /** * @author jkowalleck @@ -32,14 +32,12 @@ interface Serializer { /** - * Serialize a {@see \CycloneDX\Core\Models\Bom} to {@see string}. + * Serialize a {@see \CycloneDX\Core\Models\Bom} to string. * * @param Bom $bom the BOM to serialize * @param bool $prettyPrint whether to beatify the resulting string. A `null` value means no preference. * - * @throws Exception - * - * @psalm-return non-empty-string + * @throws Throwable * * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ diff --git a/src/Core/Serialization/XmlSerializer.php b/src/Core/Serialization/XmlSerializer.php index 78b36a13..ffe69c7a 100644 --- a/src/Core/Serialization/XmlSerializer.php +++ b/src/Core/Serialization/XmlSerializer.php @@ -74,10 +74,9 @@ protected function realSerialize(/* DOMElement */ $normalizedBom, ?bool $prettyP $document->formatOutput = $prettyPrint; } - // option LIBXML_NOEMPTYTAG might lead to errors in consumers + // option LIBXML_NOEMPTYTAG might lead to errors in consumers, do not use it. $xml = $document->saveXML(); \assert(false !== $xml); - \assert('' !== $xml); return $xml; } diff --git a/src/Core/Validation/Validator.php b/src/Core/Validation/Validator.php index 6400fe7a..3a387869 100644 --- a/src/Core/Validation/Validator.php +++ b/src/Core/Validation/Validator.php @@ -23,19 +23,10 @@ namespace CycloneDX\Core\Validation; -use CycloneDX\Core\Spec\Spec; - /** * @author jkowalleck */ interface Validator { - public function __construct(Spec $spec); - - public function getSpec(): Spec; - - /** - * @psalm-param non-empty-string $string - */ public function validateString(string $string): ?ValidationError; } diff --git a/src/Core/Validation/Validators/JsonValidator.php b/src/Core/Validation/Validators/JsonValidator.php index af3f42b0..56bcb4ed 100644 --- a/src/Core/Validation/Validators/JsonValidator.php +++ b/src/Core/Validation/Validators/JsonValidator.php @@ -55,8 +55,6 @@ protected static function listSchemaFiles(): array } /** - * @psalm-param non-empty-string $string - * * @throws FailedLoadingSchemaException if schema file unknown or not readable * @throws JsonException if loading the JSON failed */ diff --git a/src/Core/Validation/Validators/XmlValidator.php b/src/Core/Validation/Validators/XmlValidator.php index e50f323f..2dfa84f4 100644 --- a/src/Core/Validation/Validators/XmlValidator.php +++ b/src/Core/Validation/Validators/XmlValidator.php @@ -53,8 +53,6 @@ protected static function listSchemaFiles(): array } /** - * @psalm-param non-empty-string $string - * * @throws FailedLoadingSchemaException if schema file unknown or not readable * @throws DOMException if loading the DOM failed */ @@ -99,8 +97,6 @@ private function validateDomWithSchema(DOMDocument $doc): ?LibXMLError } /** - * @psalm-param non-empty-string $xml - * * @throws DOMException if loading the DOM failed */ private function loadDomFromXml(string $xml): DOMDocument