From 00de098bae6f9fdcca9e4ffe3b299c78af2a42b5 Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Fri, 10 Mar 2023 11:08:16 +0100 Subject: [PATCH] code adjust Signed-off-by: Jan Kowalleck --- .../DOM/Normalizers/BomNormalizer.php | 33 +++++++++---------- .../ComponentEvidenceNormalizer.php | 5 ++- .../DOM/Normalizers/ComponentNormalizer.php | 27 ++++++++------- .../ComponentRepositoryNormalizer.php | 2 +- .../Normalizers/DependenciesNormalizer.php | 2 +- .../ExternalReferenceNormalizer.php | 11 +++---- .../ExternalReferenceRepositoryNormalizer.php | 2 +- .../Normalizers/HashDictionaryNormalizer.php | 2 +- .../DOM/Normalizers/HashNormalizer.php | 4 +-- .../DOM/Normalizers/LicenseNormalizer.php | 10 +++--- .../LicenseRepositoryNormalizer.php | 2 +- .../DOM/Normalizers/MetadataNormalizer.php | 16 ++++----- .../DOM/Normalizers/PropertyNormalizer.php | 7 ++-- .../PropertyRepositoryNormalizer.php | 2 +- .../DOM/Normalizers/ToolNormalizer.php | 12 +++---- .../Normalizers/ToolRepositoryNormalizer.php | 2 +- .../JSON/Normalizers/BomNormalizer.php | 20 +++++------ .../ComponentEvidenceNormalizer.php | 2 +- .../JSON/Normalizers/ComponentNormalizer.php | 14 ++++---- .../ComponentRepositoryNormalizer.php | 2 +- .../ExternalReferenceNormalizer.php | 6 ++-- .../ExternalReferenceRepositoryNormalizer.php | 2 +- .../Normalizers/HashDictionaryNormalizer.php | 2 +- .../JSON/Normalizers/HashNormalizer.php | 2 +- .../JSON/Normalizers/LicenseNormalizer.php | 4 +-- .../LicenseRepositoryNormalizer.php | 2 +- .../JSON/Normalizers/MetadataNormalizer.php | 8 ++--- .../PropertyRepositoryNormalizer.php | 2 +- .../JSON/Normalizers/ToolNormalizer.php | 6 ++-- .../Normalizers/ToolRepositoryNormalizer.php | 2 +- src/Core/Validation/BaseValidator.php | 2 ++ 31 files changed, 107 insertions(+), 108 deletions(-) diff --git a/src/Core/Serialization/DOM/Normalizers/BomNormalizer.php b/src/Core/Serialization/DOM/Normalizers/BomNormalizer.php index d39f7924..f7744ba7 100644 --- a/src/Core/Serialization/DOM/Normalizers/BomNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/BomNormalizer.php @@ -41,11 +41,10 @@ class BomNormalizer extends _BaseNormalizer public function normalize(Bom $bom): DOMElement { - $factory = $this->getNormalizerFactory(); - $document = $factory->getDocument(); + $factory = $this->normalizerFactory; - $element = $document->createElementNS( - sprintf(self::XML_NAMESPACE_PATTERN, $factory->getSpec()->getVersion()->value), + $element = $factory->document->createElementNS( + sprintf(self::XML_NAMESPACE_PATTERN, $factory->spec->getVersion()->value), 'bom' // no namespace = defaultNS - so children w/o NS fall under this NS ); SimpleDOM::setAttributes( @@ -74,19 +73,19 @@ public function normalize(Bom $bom): DOMElement private function normalizeComponents(ComponentRepository $components): DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; return SimpleDOM::appendChildren( - $factory->getDocument()->createElement('components'), + $factory->document->createElement('components'), $factory->makeForComponentRepository()->normalize($components) ); } private function normalizeMetadata(Metadata $metadata): ?DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; - if (false === $factory->getSpec()->supportsMetadata()) { + if (false === $factory->spec->supportsMetadata()) { return null; } @@ -99,11 +98,11 @@ private function normalizeMetadata(Metadata $metadata): ?DOMElement private function normalizeExternalReferences(Bom $bom): ?DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; $extRefs = $bom->getExternalReferences(); - if (false === $factory->getSpec()->supportsMetadata()) { + if (false === $factory->spec->supportsMetadata()) { // prevent possible information loss: metadata cannot be rendered -> put it to bom $mcr = $bom->getMetadata()->getComponent()?->getExternalReferences(); if (null !== $mcr) { @@ -121,16 +120,16 @@ private function normalizeExternalReferences(Bom $bom): ?DOMElement return 0 === \count($refs) ? null : SimpleDOM::appendChildren( - $factory->getDocument()->createElement('externalReferences'), + $factory->document->createElement('externalReferences'), $refs ); } private function normalizeDependencies(Bom $bom): ?DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; - if (false === $factory->getSpec()->supportsDependencies()) { + if (false === $factory->spec->supportsDependencies()) { return null; } @@ -139,22 +138,22 @@ private function normalizeDependencies(Bom $bom): ?DOMElement return empty($deps) ? null : SimpleDOM::appendChildren( - $factory->getDocument()->createElement('dependencies'), + $factory->document->createElement('dependencies'), $deps ); } private function normalizeProperties(PropertyRepository $properties): ?DOMElement { - if (false === $this->getNormalizerFactory()->getSpec()->supportsBomProperties(Format::XML)) { + if (false === $this->normalizerFactory->spec->supportsBomProperties(Format::XML)) { return null; } return 0 === \count($properties) ? null : SimpleDOM::appendChildren( - $this->getNormalizerFactory()->getDocument()->createElement('properties'), - $this->getNormalizerFactory()->makeForPropertyRepository()->normalize($properties) + $this->normalizerFactory->document->createElement('properties'), + $this->normalizerFactory->makeForPropertyRepository()->normalize($properties) ); } } diff --git a/src/Core/Serialization/DOM/Normalizers/ComponentEvidenceNormalizer.php b/src/Core/Serialization/DOM/Normalizers/ComponentEvidenceNormalizer.php index b6ec1e9e..71e13098 100644 --- a/src/Core/Serialization/DOM/Normalizers/ComponentEvidenceNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/ComponentEvidenceNormalizer.php @@ -35,8 +35,7 @@ class ComponentEvidenceNormalizer extends _BaseNormalizer { public function normalize(ComponentEvidence $evidence): DOMElement { - $factory = $this->getNormalizerFactory(); - $document = $factory->getDocument(); + $document = $this->normalizerFactory->document; $licenses = $evidence->getLicenses(); $copyright = $evidence->getCopyright(); @@ -48,7 +47,7 @@ public function normalize(ComponentEvidence $evidence): DOMElement ? null : SimpleDOM::appendChildren( $document->createElement('licenses'), - $this->getNormalizerFactory()->makeForLicenseRepository()->normalize($licenses) + $this->normalizerFactory->makeForLicenseRepository()->normalize($licenses) ), 0 === \count($copyright) ? null diff --git a/src/Core/Serialization/DOM/Normalizers/ComponentNormalizer.php b/src/Core/Serialization/DOM/Normalizers/ComponentNormalizer.php index 3cf1f8c4..f80ad272 100644 --- a/src/Core/Serialization/DOM/Normalizers/ComponentNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/ComponentNormalizer.php @@ -49,8 +49,7 @@ public function normalize(Component $component): DOMElement $group = $component->getGroup(); $version = $component->getVersion(); - $factory = $this->getNormalizerFactory(); - $spec = $factory->getSpec(); + $spec = $this->normalizerFactory->spec; $type = $component->getType(); if (false === $spec->isSupportedComponentType($type)) { @@ -68,7 +67,7 @@ public function normalize(Component $component): DOMElement ? $component->getEvidence() : null; - $document = $factory->getDocument(); + $document = $this->normalizerFactory->document; return SimpleDOM::appendChildren( SimpleDOM::setAttributes( @@ -106,31 +105,31 @@ public function normalize(Component $component): DOMElement // components null === $evidence ? null - : $this->getNormalizerFactory()->makeForComponentEvidence()->normalize($evidence), + : $this->normalizerFactory->makeForComponentEvidence()->normalize($evidence), ] ); } private function normalizeLicenses(LicenseRepository $licenses): ?DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; return 0 === \count($licenses) ? null : SimpleDOM::appendChildren( - $factory->getDocument()->createElement('licenses'), + $factory->document->createElement('licenses'), $factory->makeForLicenseRepository()->normalize($licenses) ); } private function normalizeHashes(HashDictionary $hashes): ?DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; return 0 === \count($hashes) ? null : SimpleDOM::appendChildren( - $factory->getDocument()->createElement('hashes'), + $factory->document->createElement('hashes'), $factory->makeForHashDictionary()->normalize($hashes) ); } @@ -140,7 +139,7 @@ private function normalizePurl(?PackageUrl $purl): ?DOMElement return null === $purl ? null : SimpleDOM::makeSafeTextElement( - $this->getNormalizerFactory()->getDocument(), + $this->normalizerFactory->document, 'purl', XML::encodeAnyUriBE((string) $purl) ); @@ -148,27 +147,27 @@ private function normalizePurl(?PackageUrl $purl): ?DOMElement private function normalizeExternalReferences(ExternalReferenceRepository $extRefs): ?DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; return 0 === \count($extRefs) ? null : SimpleDOM::appendChildren( - $factory->getDocument()->createElement('externalReferences'), + $factory->document->createElement('externalReferences'), $factory->makeForExternalReferenceRepository()->normalize($extRefs) ); } private function normalizeProperties(PropertyRepository $properties): ?DOMElement { - if (false === $this->getNormalizerFactory()->getSpec()->supportsComponentProperties()) { + if (false === $this->normalizerFactory->spec->supportsComponentProperties()) { return null; } return 0 === \count($properties) ? null : SimpleDOM::appendChildren( - $this->getNormalizerFactory()->getDocument()->createElement('properties'), - $this->getNormalizerFactory()->makeForPropertyRepository()->normalize($properties) + $this->normalizerFactory->document->createElement('properties'), + $this->normalizerFactory->makeForPropertyRepository()->normalize($properties) ); } } diff --git a/src/Core/Serialization/DOM/Normalizers/ComponentRepositoryNormalizer.php b/src/Core/Serialization/DOM/Normalizers/ComponentRepositoryNormalizer.php index 6f2b99ec..91c777a0 100644 --- a/src/Core/Serialization/DOM/Normalizers/ComponentRepositoryNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/ComponentRepositoryNormalizer.php @@ -39,7 +39,7 @@ class ComponentRepositoryNormalizer extends _BaseNormalizer */ public function normalize(ComponentRepository $repo): array { - $normalizer = $this->getNormalizerFactory()->makeForComponent(); + $normalizer = $this->normalizerFactory->makeForComponent(); $components = []; foreach ($repo->getItems() as $component) { diff --git a/src/Core/Serialization/DOM/Normalizers/DependenciesNormalizer.php b/src/Core/Serialization/DOM/Normalizers/DependenciesNormalizer.php index f9335b8c..03ad8a32 100644 --- a/src/Core/Serialization/DOM/Normalizers/DependenciesNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/DependenciesNormalizer.php @@ -79,7 +79,7 @@ private function normalizeDependency(BomRef $componentRef, BomRef ...$dependency return null; } - $doc = $this->getNormalizerFactory()->getDocument(); + $doc = $this->normalizerFactory->document; $dependency = SimpleDOM::setAttributes( $doc->createElement('dependency'), diff --git a/src/Core/Serialization/DOM/Normalizers/ExternalReferenceNormalizer.php b/src/Core/Serialization/DOM/Normalizers/ExternalReferenceNormalizer.php index 8bf0cb2f..373f09a7 100644 --- a/src/Core/Serialization/DOM/Normalizers/ExternalReferenceNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/ExternalReferenceNormalizer.php @@ -48,8 +48,7 @@ public function normalize(ExternalReference $externalReference): DOMElement $anyURI = XML::encodeAnyUriBE($refURI) ?? throw new UnexpectedValueException("unable to make 'anyURI' from: $refURI"); - $factory = $this->getNormalizerFactory(); - $spec = $factory->getSpec(); + $spec = $this->normalizerFactory->spec; $type = $externalReference->getType(); if (false === $spec->isSupportedExternalReferenceType($type)) { @@ -60,7 +59,7 @@ public function normalize(ExternalReference $externalReference): DOMElement } } - $doc = $factory->getDocument(); + $doc = $this->normalizerFactory->document; return SimpleDOM::appendChildren( SimpleDOM::setAttributes( @@ -83,13 +82,13 @@ private function normalizeHashes(HashDictionary $hashes): ?DOMElement return null; } - $factory = $this->getNormalizerFactory(); - if (false === $factory->getSpec()->supportsExternalReferenceHashes()) { + $factory = $this->normalizerFactory; + if (false === $factory->spec->supportsExternalReferenceHashes()) { return null; } return SimpleDOM::appendChildren( - $factory->getDocument()->createElement('hashes'), + $factory->document->createElement('hashes'), $factory->makeForHashDictionary()->normalize($hashes) ); } diff --git a/src/Core/Serialization/DOM/Normalizers/ExternalReferenceRepositoryNormalizer.php b/src/Core/Serialization/DOM/Normalizers/ExternalReferenceRepositoryNormalizer.php index ee1f0ed7..854779c5 100644 --- a/src/Core/Serialization/DOM/Normalizers/ExternalReferenceRepositoryNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/ExternalReferenceRepositoryNormalizer.php @@ -41,7 +41,7 @@ class ExternalReferenceRepositoryNormalizer extends _BaseNormalizer */ public function normalize(ExternalReferenceRepository $repo): array { - $normalizer = $this->getNormalizerFactory()->makeForExternalReference(); + $normalizer = $this->normalizerFactory->makeForExternalReference(); $externalReferences = []; foreach ($repo->getItems() as $externalReference) { diff --git a/src/Core/Serialization/DOM/Normalizers/HashDictionaryNormalizer.php b/src/Core/Serialization/DOM/Normalizers/HashDictionaryNormalizer.php index 073ee301..27a90165 100644 --- a/src/Core/Serialization/DOM/Normalizers/HashDictionaryNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/HashDictionaryNormalizer.php @@ -41,7 +41,7 @@ public function normalize(HashDictionary $repo): array { $hashes = []; - $hashNormalizer = $this->getNormalizerFactory()->makeForHash(); + $hashNormalizer = $this->normalizerFactory->makeForHash(); foreach ($repo->getItems() as [$algorithm , $content]) { try { $hashes[] = $hashNormalizer->normalize($algorithm, $content); diff --git a/src/Core/Serialization/DOM/Normalizers/HashNormalizer.php b/src/Core/Serialization/DOM/Normalizers/HashNormalizer.php index 415febd5..b7f24eea 100644 --- a/src/Core/Serialization/DOM/Normalizers/HashNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/HashNormalizer.php @@ -39,7 +39,7 @@ class HashNormalizer extends _BaseNormalizer */ public function normalize(HashAlgorithm $algorithm, string $content): DOMElement { - $spec = $this->getNormalizerFactory()->getSpec(); + $spec = $this->normalizerFactory->spec; if (false === $spec->isSupportedHashAlgorithm($algorithm)) { throw new DomainException("Invalid hash algorithm: $algorithm->name", 1); } @@ -48,7 +48,7 @@ public function normalize(HashAlgorithm $algorithm, string $content): DOMElement } $element = SimpleDOM::makeSafeTextElement( - $this->getNormalizerFactory()->getDocument(), + $this->normalizerFactory->document, 'hash', $content ); diff --git a/src/Core/Serialization/DOM/Normalizers/LicenseNormalizer.php b/src/Core/Serialization/DOM/Normalizers/LicenseNormalizer.php index ea0a4319..a1fcad25 100644 --- a/src/Core/Serialization/DOM/Normalizers/LicenseNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/LicenseNormalizer.php @@ -46,10 +46,10 @@ public function normalize(LicenseExpression|SpdxLicense|NamedLicense $license): private function normalizeExpression(LicenseExpression $license): DOMElement { // TODO: IMPLEMENTED IF NEEDED: may throw, if not supported by the spec - // $this->getNormalizerFactory()->getSpec()->supportsLicenseExpression() + // $this->normalizerFactory->spec->supportsLicenseExpression() $element = SimpleDOM::makeSafeTextElement( - $this->getNormalizerFactory()->getDocument(), + $this->normalizerFactory->document, 'expression', $license->getExpression() ); @@ -63,17 +63,17 @@ private function normalizeExpression(LicenseExpression $license): DOMElement */ private function normalizeDisjunctive(SpdxLicense|NamedLicense $license): DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; [$id, $name] = $license instanceof SpdxLicense ? [$license->getId(), null] : [null, $license->getName()]; - if (null !== $id && !$factory->getSpec()->isSupportedLicenseIdentifier($id)) { + if (null !== $id && !$factory->spec->isSupportedLicenseIdentifier($id)) { [$id, $name] = [null, $id]; } - $document = $factory->getDocument(); + $document = $factory->document; return SimpleDOM::appendChildren( $document->createElement('license'), diff --git a/src/Core/Serialization/DOM/Normalizers/LicenseRepositoryNormalizer.php b/src/Core/Serialization/DOM/Normalizers/LicenseRepositoryNormalizer.php index d3f4952a..bc9e07c4 100644 --- a/src/Core/Serialization/DOM/Normalizers/LicenseRepositoryNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/LicenseRepositoryNormalizer.php @@ -40,7 +40,7 @@ class LicenseRepositoryNormalizer extends _BaseNormalizer public function normalize(LicenseRepository $repo): array { return array_map( - $this->getNormalizerFactory()->makeForLicense()->normalize(...), + $this->normalizerFactory->makeForLicense()->normalize(...), $repo->getItems() ); } diff --git a/src/Core/Serialization/DOM/Normalizers/MetadataNormalizer.php b/src/Core/Serialization/DOM/Normalizers/MetadataNormalizer.php index 222482fe..2e27d695 100644 --- a/src/Core/Serialization/DOM/Normalizers/MetadataNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/MetadataNormalizer.php @@ -42,7 +42,7 @@ class MetadataNormalizer extends _BaseNormalizer public function normalize(Metadata $metadata): DOMElement { return SimpleDOM::appendChildren( - $this->getNormalizerFactory()->getDocument()->createElement('metadata'), + $this->normalizerFactory->document->createElement('metadata'), [ $this->normalizeTimestamp($metadata->getTimestamp()), $this->normalizeTools($metadata->getTools()), @@ -66,7 +66,7 @@ private function normalizeTimestamp(?DateTimeInterface $timestamp): ?DOMElement ->format('Y-m-d\\TH:i:sp'); return SimpleDOM::makeSafeTextElement( - $this->getNormalizerFactory()->getDocument(), + $this->normalizerFactory->document, 'timestamp', $dtZulu ); @@ -77,8 +77,8 @@ private function normalizeTools(ToolRepository $tools): ?DOMElement return 0 === \count($tools) ? null : SimpleDOM::appendChildren( - $this->getNormalizerFactory()->getDocument()->createElement('tools'), - $this->getNormalizerFactory()->makeForToolRepository()->normalize($tools) + $this->normalizerFactory->document->createElement('tools'), + $this->normalizerFactory->makeForToolRepository()->normalize($tools) ); } @@ -89,7 +89,7 @@ private function normalizeComponent(?Component $component): ?DOMElement } try { - return $this->getNormalizerFactory()->makeForComponent()->normalize($component); + return $this->normalizerFactory->makeForComponent()->normalize($component); } catch (\DomainException) { return null; } @@ -97,15 +97,15 @@ private function normalizeComponent(?Component $component): ?DOMElement private function normalizeProperties(PropertyRepository $properties): ?DOMElement { - if (false === $this->getNormalizerFactory()->getSpec()->supportsMetadataProperties()) { + if (false === $this->normalizerFactory->spec->supportsMetadataProperties()) { return null; } return 0 === \count($properties) ? null : SimpleDOM::appendChildren( - $this->getNormalizerFactory()->getDocument()->createElement('properties'), - $this->getNormalizerFactory()->makeForPropertyRepository()->normalize($properties) + $this->normalizerFactory->document->createElement('properties'), + $this->normalizerFactory->makeForPropertyRepository()->normalize($properties) ); } } diff --git a/src/Core/Serialization/DOM/Normalizers/PropertyNormalizer.php b/src/Core/Serialization/DOM/Normalizers/PropertyNormalizer.php index ec8b173b..7ab99bd6 100644 --- a/src/Core/Serialization/DOM/Normalizers/PropertyNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/PropertyNormalizer.php @@ -39,15 +39,16 @@ class PropertyNormalizer extends _BaseNormalizer */ public function normalize(Property $property): DOMElement { - $doc = $this->getNormalizerFactory()->getDocument(); - $name = $property->getName(); if ('' === $name) { // this implementation detail is optional throw new DomainException('empty name'); } - $element = SimpleDOM::makeSafeTextElement($doc, 'property', $property->getValue(), false); + $element = SimpleDOM::makeSafeTextElement( + $this->normalizerFactory->document, + 'property', + $property->getValue(), false); \assert(null !== $element); return SimpleDOM::setAttributes( diff --git a/src/Core/Serialization/DOM/Normalizers/PropertyRepositoryNormalizer.php b/src/Core/Serialization/DOM/Normalizers/PropertyRepositoryNormalizer.php index 3f7e6d09..72baadf6 100644 --- a/src/Core/Serialization/DOM/Normalizers/PropertyRepositoryNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/PropertyRepositoryNormalizer.php @@ -39,7 +39,7 @@ class PropertyRepositoryNormalizer extends _BaseNormalizer */ public function normalize(PropertyRepository $repo): array { - $normalizer = $this->getNormalizerFactory()->makeForProperty(); + $normalizer = $this->normalizerFactory->makeForProperty(); $properties = []; foreach ($repo->getItems() as $property) { diff --git a/src/Core/Serialization/DOM/Normalizers/ToolNormalizer.php b/src/Core/Serialization/DOM/Normalizers/ToolNormalizer.php index 3440c79b..91f4491f 100644 --- a/src/Core/Serialization/DOM/Normalizers/ToolNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/ToolNormalizer.php @@ -37,7 +37,7 @@ class ToolNormalizer extends _BaseNormalizer { public function normalize(Tool $tool): DOMElement { - $doc = $this->getNormalizerFactory()->getDocument(); + $doc = $this->normalizerFactory->document; return SimpleDOM::appendChildren( $doc->createElement('tool'), @@ -53,28 +53,28 @@ public function normalize(Tool $tool): DOMElement private function normalizeHashes(HashDictionary $hashes): ?DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; return 0 === \count($hashes) ? null : SimpleDOM::appendChildren( - $factory->getDocument()->createElement('hashes'), + $factory->document->createElement('hashes'), $factory->makeForHashDictionary()->normalize($hashes) ); } private function normalizeExternalReferences(ExternalReferenceRepository $extRefs): ?DOMElement { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; - if (false === $factory->getSpec()->supportsToolExternalReferences()) { + if (false === $factory->spec->supportsToolExternalReferences()) { return null; } return 0 === \count($extRefs) ? null : SimpleDOM::appendChildren( - $factory->getDocument()->createElement('externalReferences'), + $factory->document->createElement('externalReferences'), $factory->makeForExternalReferenceRepository()->normalize($extRefs) ); } diff --git a/src/Core/Serialization/DOM/Normalizers/ToolRepositoryNormalizer.php b/src/Core/Serialization/DOM/Normalizers/ToolRepositoryNormalizer.php index 778c7544..7e86c5e5 100644 --- a/src/Core/Serialization/DOM/Normalizers/ToolRepositoryNormalizer.php +++ b/src/Core/Serialization/DOM/Normalizers/ToolRepositoryNormalizer.php @@ -39,7 +39,7 @@ class ToolRepositoryNormalizer extends _BaseNormalizer */ public function normalize(ToolRepository $repo): array { - $normalizer = $this->getNormalizerFactory()->makeForTool(); + $normalizer = $this->normalizerFactory->makeForTool(); $tools = []; foreach ($repo->getItems() as $tool) { diff --git a/src/Core/Serialization/JSON/Normalizers/BomNormalizer.php b/src/Core/Serialization/JSON/Normalizers/BomNormalizer.php index 5abe7ef8..54c6df13 100644 --- a/src/Core/Serialization/JSON/Normalizers/BomNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/BomNormalizer.php @@ -54,8 +54,8 @@ private function getSchema(Version $version): ?string */ public function normalize(Bom $bom): array { - $factory = $this->getNormalizerFactory(); - $specVersion = $factory->getSpec()->getVersion(); + $factory = $this->normalizerFactory; + $specVersion = $factory->spec->getVersion(); return array_filter( [ @@ -80,9 +80,9 @@ public function normalize(Bom $bom): array private function normalizeMetadata(Metadata $metadata): ?array { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; - if (false === $factory->getSpec()->supportsMetadata()) { + if (false === $factory->spec->supportsMetadata()) { return null; } @@ -95,11 +95,11 @@ private function normalizeMetadata(Metadata $metadata): ?array private function normalizeExternalReferences(Bom $bom): ?array { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; $extRefs = $bom->getExternalReferences(); - if (false === $factory->getSpec()->supportsMetadata()) { + if (false === $factory->spec->supportsMetadata()) { // prevent possible information loss: metadata cannot be rendered -> put it to bom $mcr = $bom->getMetadata()->getComponent()?->getExternalReferences(); if (null !== $mcr) { @@ -121,9 +121,9 @@ private function normalizeExternalReferences(Bom $bom): ?array private function normalizeDependencies(Bom $bom): ?array { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; - if (false === $factory->getSpec()->supportsDependencies()) { + if (false === $factory->spec->supportsDependencies()) { return null; } @@ -136,12 +136,12 @@ private function normalizeDependencies(Bom $bom): ?array private function normalizeProperties(PropertyRepository $properties): ?array { - if (false === $this->getNormalizerFactory()->getSpec()->supportsBomProperties(Format::JSON)) { + if (false === $this->normalizerFactory->spec->supportsBomProperties(Format::JSON)) { return null; } return 0 === \count($properties) ? null - : $this->getNormalizerFactory()->makeForPropertyRepository()->normalize($properties); + : $this->normalizerFactory->makeForPropertyRepository()->normalize($properties); } } diff --git a/src/Core/Serialization/JSON/Normalizers/ComponentEvidenceNormalizer.php b/src/Core/Serialization/JSON/Normalizers/ComponentEvidenceNormalizer.php index e1604b7d..49ac9986 100644 --- a/src/Core/Serialization/JSON/Normalizers/ComponentEvidenceNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/ComponentEvidenceNormalizer.php @@ -40,7 +40,7 @@ public function normalize(ComponentEvidence $evidence): array return array_filter([ 'licenses' => 0 === \count($license) ? null - : $this->getNormalizerFactory()->makeForLicenseRepository()->normalize($license), + : $this->normalizerFactory->makeForLicenseRepository()->normalize($license), 'copyright' => 0 === \count($copyright) ? null : array_map( diff --git a/src/Core/Serialization/JSON/Normalizers/ComponentNormalizer.php b/src/Core/Serialization/JSON/Normalizers/ComponentNormalizer.php index 04a0f63f..ba04db35 100644 --- a/src/Core/Serialization/JSON/Normalizers/ComponentNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/ComponentNormalizer.php @@ -43,7 +43,7 @@ class ComponentNormalizer extends _BaseNormalizer */ public function normalize(Component $component): array { - $spec = $this->getNormalizerFactory()->getSpec(); + $spec = $this->normalizerFactory->spec; $name = $component->getName(); $group = $component->getGroup(); @@ -80,7 +80,7 @@ public function normalize(Component $component): array 'copyright' => $component->getCopyright(), 'evidence' => null === $evidence ? null - : $this->getNormalizerFactory()->makeForComponentEvidence()->normalize($evidence), + : $this->normalizerFactory->makeForComponentEvidence()->normalize($evidence), 'hashes' => $this->normalizeHashes($component->getHashes()), 'purl' => $this->normalizePurl($component->getPackageUrl()), 'externalReferences' => $this->normalizeExternalReferences($component->getExternalReferences()), @@ -94,14 +94,14 @@ private function normalizeLicenses(LicenseRepository $licenses): ?array { return 0 === \count($licenses) ? null - : $this->getNormalizerFactory()->makeForLicenseRepository()->normalize($licenses); + : $this->normalizerFactory->makeForLicenseRepository()->normalize($licenses); } private function normalizeHashes(HashDictionary $hashes): ?array { return 0 === \count($hashes) ? null - : $this->getNormalizerFactory()->makeForHashDictionary()->normalize($hashes); + : $this->normalizerFactory->makeForHashDictionary()->normalize($hashes); } private function normalizePurl(?PackageUrl $purl): ?string @@ -115,17 +115,17 @@ private function normalizeExternalReferences(ExternalReferenceRepository $extRef { return 0 === \count($extRefs) ? null - : $this->getNormalizerFactory()->makeForExternalReferenceRepository()->normalize($extRefs); + : $this->normalizerFactory->makeForExternalReferenceRepository()->normalize($extRefs); } private function normalizeProperties(PropertyRepository $properties): ?array { - if (false === $this->getNormalizerFactory()->getSpec()->supportsComponentProperties()) { + if (false === $this->normalizerFactory->spec->supportsComponentProperties()) { return null; } return 0 === \count($properties) ? null - : $this->getNormalizerFactory()->makeForPropertyRepository()->normalize($properties); + : $this->normalizerFactory->makeForPropertyRepository()->normalize($properties); } } diff --git a/src/Core/Serialization/JSON/Normalizers/ComponentRepositoryNormalizer.php b/src/Core/Serialization/JSON/Normalizers/ComponentRepositoryNormalizer.php index 8c585a45..89ea95de 100644 --- a/src/Core/Serialization/JSON/Normalizers/ComponentRepositoryNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/ComponentRepositoryNormalizer.php @@ -38,7 +38,7 @@ public function normalize(ComponentRepository $repo): array { $components = []; - $normalizer = $this->getNormalizerFactory()->makeForComponent(); + $normalizer = $this->normalizerFactory->makeForComponent(); foreach ($repo->getItems() as $component) { try { $components[] = $normalizer->normalize($component); diff --git a/src/Core/Serialization/JSON/Normalizers/ExternalReferenceNormalizer.php b/src/Core/Serialization/JSON/Normalizers/ExternalReferenceNormalizer.php index 083637f8..ce20ed9b 100644 --- a/src/Core/Serialization/JSON/Normalizers/ExternalReferenceNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/ExternalReferenceNormalizer.php @@ -50,7 +50,7 @@ public function normalize(ExternalReference $externalReference): array throw new UnexpectedValueException("invalid to format 'IriReference': $url"); } - $spec = $this->getNormalizerFactory()->getSpec(); + $spec = $this->normalizerFactory->spec; $type = $externalReference->getType(); if (false === $spec->isSupportedExternalReferenceType($type)) { // prevent information-loss -> try transfer to OTHER @@ -73,9 +73,9 @@ public function normalize(ExternalReference $externalReference): array private function normalizeHashes(HashDictionary $hashes): ?array { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; - if (false === $factory->getSpec()->supportsExternalReferenceHashes()) { + if (false === $factory->spec->supportsExternalReferenceHashes()) { return null; } diff --git a/src/Core/Serialization/JSON/Normalizers/ExternalReferenceRepositoryNormalizer.php b/src/Core/Serialization/JSON/Normalizers/ExternalReferenceRepositoryNormalizer.php index 07ddafca..cc934b2b 100644 --- a/src/Core/Serialization/JSON/Normalizers/ExternalReferenceRepositoryNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/ExternalReferenceRepositoryNormalizer.php @@ -40,7 +40,7 @@ class ExternalReferenceRepositoryNormalizer extends _BaseNormalizer */ public function normalize(ExternalReferenceRepository $repo): array { - $normalizer = $this->getNormalizerFactory()->makeForExternalReference(); + $normalizer = $this->normalizerFactory->makeForExternalReference(); $externalReferences = []; foreach ($repo->getItems() as $externalReference) { diff --git a/src/Core/Serialization/JSON/Normalizers/HashDictionaryNormalizer.php b/src/Core/Serialization/JSON/Normalizers/HashDictionaryNormalizer.php index 61d5d5ac..1dbeeb05 100644 --- a/src/Core/Serialization/JSON/Normalizers/HashDictionaryNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/HashDictionaryNormalizer.php @@ -35,7 +35,7 @@ public function normalize(HashDictionary $repo): array { $hashes = []; - $normalizer = $this->getNormalizerFactory()->makeForHash(); + $normalizer = $this->normalizerFactory->makeForHash(); foreach ($repo->getItems() as [$algorithm , $content]) { try { $hashes[] = $normalizer->normalize($algorithm, $content); diff --git a/src/Core/Serialization/JSON/Normalizers/HashNormalizer.php b/src/Core/Serialization/JSON/Normalizers/HashNormalizer.php index 53b699cf..7efef0e9 100644 --- a/src/Core/Serialization/JSON/Normalizers/HashNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/HashNormalizer.php @@ -37,7 +37,7 @@ class HashNormalizer extends _BaseNormalizer */ public function normalize(HashAlgorithm $algorithm, string $content): array { - $spec = $this->getNormalizerFactory()->getSpec(); + $spec = $this->normalizerFactory->spec; if (false === $spec->isSupportedHashAlgorithm($algorithm)) { throw new DomainException("Invalid hash algorithm: $algorithm->name", 1); } diff --git a/src/Core/Serialization/JSON/Normalizers/LicenseNormalizer.php b/src/Core/Serialization/JSON/Normalizers/LicenseNormalizer.php index b2f6b942..ac8befc5 100644 --- a/src/Core/Serialization/JSON/Normalizers/LicenseNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/LicenseNormalizer.php @@ -45,7 +45,7 @@ public function normalize(LicenseExpression|SpdxLicense|NamedLicense $license): private function normalizeExpression(LicenseExpression $license): array { // TODO: IMPLEMENTED IF NEEDED: may throw, if not supported by the spec - // $this->getNormalizerFactory()->getSpec()->supportsLicenseExpression() + // $this->normalizerFactory->spec->supportsLicenseExpression() return ['expression' => $license->getExpression()]; } @@ -59,7 +59,7 @@ private function normalizeDisjunctive(SpdxLicense|NamedLicense $license): array [$id, $name] = $license instanceof SpdxLicense ? [$license->getId(), null] : [null, $license->getName()]; - if (null !== $id && !$this->getNormalizerFactory()->getSpec()->isSupportedLicenseIdentifier($id)) { + if (null !== $id && !$this->normalizerFactory->spec->isSupportedLicenseIdentifier($id)) { [$id, $name] = [null, $id]; } diff --git a/src/Core/Serialization/JSON/Normalizers/LicenseRepositoryNormalizer.php b/src/Core/Serialization/JSON/Normalizers/LicenseRepositoryNormalizer.php index b40bc8be..516c918f 100644 --- a/src/Core/Serialization/JSON/Normalizers/LicenseRepositoryNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/LicenseRepositoryNormalizer.php @@ -34,7 +34,7 @@ class LicenseRepositoryNormalizer extends _BaseNormalizer public function normalize(LicenseRepository $repo): array { return array_map( - $this->getNormalizerFactory()->makeForLicense()->normalize(...), + $this->normalizerFactory->makeForLicense()->normalize(...), $repo->getItems() ); } diff --git a/src/Core/Serialization/JSON/Normalizers/MetadataNormalizer.php b/src/Core/Serialization/JSON/Normalizers/MetadataNormalizer.php index aa0e990d..f0cea23e 100644 --- a/src/Core/Serialization/JSON/Normalizers/MetadataNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/MetadataNormalizer.php @@ -69,7 +69,7 @@ private function normalizeTools(ToolRepository $tools): ?array { return 0 === \count($tools) ? null - : $this->getNormalizerFactory()->makeForToolRepository()->normalize($tools); + : $this->normalizerFactory->makeForToolRepository()->normalize($tools); } private function normalizeComponent(?Component $component): ?array @@ -79,7 +79,7 @@ private function normalizeComponent(?Component $component): ?array } try { - return $this->getNormalizerFactory()->makeForComponent()->normalize($component); + return $this->normalizerFactory->makeForComponent()->normalize($component); } catch (\DomainException) { return null; } @@ -87,12 +87,12 @@ private function normalizeComponent(?Component $component): ?array private function normalizeProperties(PropertyRepository $properties): ?array { - if (false === $this->getNormalizerFactory()->getSpec()->supportsMetadataProperties()) { + if (false === $this->normalizerFactory->spec->supportsMetadataProperties()) { return null; } return 0 === \count($properties) ? null - : $this->getNormalizerFactory()->makeForPropertyRepository()->normalize($properties); + : $this->normalizerFactory->makeForPropertyRepository()->normalize($properties); } } diff --git a/src/Core/Serialization/JSON/Normalizers/PropertyRepositoryNormalizer.php b/src/Core/Serialization/JSON/Normalizers/PropertyRepositoryNormalizer.php index 20575726..da0f21ea 100644 --- a/src/Core/Serialization/JSON/Normalizers/PropertyRepositoryNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/PropertyRepositoryNormalizer.php @@ -33,7 +33,7 @@ class PropertyRepositoryNormalizer extends _BaseNormalizer { public function normalize(PropertyRepository $repo): array { - $normalizer = $this->getNormalizerFactory()->makeForProperty(); + $normalizer = $this->normalizerFactory->makeForProperty(); $properties = []; foreach ($repo->getItems() as $property) { diff --git a/src/Core/Serialization/JSON/Normalizers/ToolNormalizer.php b/src/Core/Serialization/JSON/Normalizers/ToolNormalizer.php index 1ed357ea..818922d5 100644 --- a/src/Core/Serialization/JSON/Normalizers/ToolNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/ToolNormalizer.php @@ -52,14 +52,14 @@ private function normalizeHashes(HashDictionary $hashes): ?array { return 0 === \count($hashes) ? null - : $this->getNormalizerFactory()->makeForHashDictionary()->normalize($hashes); + : $this->normalizerFactory->makeForHashDictionary()->normalize($hashes); } private function normalizeExternalReferences(ExternalReferenceRepository $extRefs): ?array { - $factory = $this->getNormalizerFactory(); + $factory = $this->normalizerFactory; - if (false === $factory->getSpec()->supportsToolExternalReferences()) { + if (false === $factory->spec->supportsToolExternalReferences()) { return null; } diff --git a/src/Core/Serialization/JSON/Normalizers/ToolRepositoryNormalizer.php b/src/Core/Serialization/JSON/Normalizers/ToolRepositoryNormalizer.php index 9f413faf..8e306c56 100644 --- a/src/Core/Serialization/JSON/Normalizers/ToolRepositoryNormalizer.php +++ b/src/Core/Serialization/JSON/Normalizers/ToolRepositoryNormalizer.php @@ -38,7 +38,7 @@ class ToolRepositoryNormalizer extends _BaseNormalizer */ public function normalize(ToolRepository $repo): array { - $normalizer = $this->getNormalizerFactory()->makeForTool(); + $normalizer = $this->normalizerFactory->makeForTool(); $tools = []; foreach ($repo->getItems() as $tool) { diff --git a/src/Core/Validation/BaseValidator.php b/src/Core/Validation/BaseValidator.php index 72bb24a6..bdadd7b7 100644 --- a/src/Core/Validation/BaseValidator.php +++ b/src/Core/Validation/BaseValidator.php @@ -26,6 +26,8 @@ use CycloneDX\Core\Spec\Spec; /** + * @internal as this class may be affected by breaking changes without notice + * * @author jkowalleck */ abstract class BaseValidator implements Validator