Skip to content

Commit 8daaed6

Browse files
committed
code adjust
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent 928e479 commit 8daaed6

32 files changed

+107
-114
lines changed

src/Core/Serialization/DOM/Normalizers/BomNormalizer.php

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@ class BomNormalizer extends _BaseNormalizer
4141

4242
public function normalize(Bom $bom): DOMElement
4343
{
44-
$factory = $this->getNormalizerFactory();
45-
$document = $factory->getDocument();
44+
$factory = $this->normalizerFactory;
4645

47-
$element = $document->createElementNS(
48-
sprintf(self::XML_NAMESPACE_PATTERN, $factory->getSpec()->getVersion()->value),
46+
$element = $factory->document->createElementNS(
47+
sprintf(self::XML_NAMESPACE_PATTERN, $factory->spec->getVersion()->value),
4948
'bom' // no namespace = defaultNS - so children w/o NS fall under this NS
5049
);
5150
SimpleDOM::setAttributes(
@@ -74,19 +73,19 @@ public function normalize(Bom $bom): DOMElement
7473

7574
private function normalizeComponents(ComponentRepository $components): DOMElement
7675
{
77-
$factory = $this->getNormalizerFactory();
76+
$factory = $this->normalizerFactory;
7877

7978
return SimpleDOM::appendChildren(
80-
$factory->getDocument()->createElement('components'),
79+
$factory->document->createElement('components'),
8180
$factory->makeForComponentRepository()->normalize($components)
8281
);
8382
}
8483

8584
private function normalizeMetadata(Metadata $metadata): ?DOMElement
8685
{
87-
$factory = $this->getNormalizerFactory();
86+
$factory = $this->normalizerFactory;
8887

89-
if (false === $factory->getSpec()->supportsMetadata()) {
88+
if (false === $factory->spec->supportsMetadata()) {
9089
return null;
9190
}
9291

@@ -99,11 +98,11 @@ private function normalizeMetadata(Metadata $metadata): ?DOMElement
9998

10099
private function normalizeExternalReferences(Bom $bom): ?DOMElement
101100
{
102-
$factory = $this->getNormalizerFactory();
101+
$factory = $this->normalizerFactory;
103102

104103
$extRefs = $bom->getExternalReferences();
105104

106-
if (false === $factory->getSpec()->supportsMetadata()) {
105+
if (false === $factory->spec->supportsMetadata()) {
107106
// prevent possible information loss: metadata cannot be rendered -> put it to bom
108107
$mcr = $bom->getMetadata()->getComponent()?->getExternalReferences();
109108
if (null !== $mcr) {
@@ -121,16 +120,16 @@ private function normalizeExternalReferences(Bom $bom): ?DOMElement
121120
return 0 === \count($refs)
122121
? null
123122
: SimpleDOM::appendChildren(
124-
$factory->getDocument()->createElement('externalReferences'),
123+
$factory->document->createElement('externalReferences'),
125124
$refs
126125
);
127126
}
128127

129128
private function normalizeDependencies(Bom $bom): ?DOMElement
130129
{
131-
$factory = $this->getNormalizerFactory();
130+
$factory = $this->normalizerFactory;
132131

133-
if (false === $factory->getSpec()->supportsDependencies()) {
132+
if (false === $factory->spec->supportsDependencies()) {
134133
return null;
135134
}
136135

@@ -139,22 +138,22 @@ private function normalizeDependencies(Bom $bom): ?DOMElement
139138
return empty($deps)
140139
? null
141140
: SimpleDOM::appendChildren(
142-
$factory->getDocument()->createElement('dependencies'),
141+
$factory->document->createElement('dependencies'),
143142
$deps
144143
);
145144
}
146145

147146
private function normalizeProperties(PropertyRepository $properties): ?DOMElement
148147
{
149-
if (false === $this->getNormalizerFactory()->getSpec()->supportsBomProperties(Format::XML)) {
148+
if (false === $this->normalizerFactory->spec->supportsBomProperties(Format::XML)) {
150149
return null;
151150
}
152151

153152
return 0 === \count($properties)
154153
? null
155154
: SimpleDOM::appendChildren(
156-
$this->getNormalizerFactory()->getDocument()->createElement('properties'),
157-
$this->getNormalizerFactory()->makeForPropertyRepository()->normalize($properties)
155+
$this->normalizerFactory->document->createElement('properties'),
156+
$this->normalizerFactory->makeForPropertyRepository()->normalize($properties)
158157
);
159158
}
160159
}

src/Core/Serialization/DOM/Normalizers/ComponentEvidenceNormalizer.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ class ComponentEvidenceNormalizer extends _BaseNormalizer
3535
{
3636
public function normalize(ComponentEvidence $evidence): DOMElement
3737
{
38-
$factory = $this->getNormalizerFactory();
39-
$document = $factory->getDocument();
38+
$document = $this->normalizerFactory->document;
4039

4140
$licenses = $evidence->getLicenses();
4241
$copyright = $evidence->getCopyright();
@@ -48,7 +47,7 @@ public function normalize(ComponentEvidence $evidence): DOMElement
4847
? null
4948
: SimpleDOM::appendChildren(
5049
$document->createElement('licenses'),
51-
$this->getNormalizerFactory()->makeForLicenseRepository()->normalize($licenses)
50+
$this->normalizerFactory->makeForLicenseRepository()->normalize($licenses)
5251
),
5352
0 === \count($copyright)
5453
? null

src/Core/Serialization/DOM/Normalizers/ComponentNormalizer.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ public function normalize(Component $component): DOMElement
4949
$group = $component->getGroup();
5050
$version = $component->getVersion();
5151

52-
$factory = $this->getNormalizerFactory();
53-
$spec = $factory->getSpec();
52+
$spec = $this->normalizerFactory->spec;
5453

5554
$type = $component->getType();
5655
if (false === $spec->isSupportedComponentType($type)) {
@@ -68,7 +67,7 @@ public function normalize(Component $component): DOMElement
6867
? $component->getEvidence()
6968
: null;
7069

71-
$document = $factory->getDocument();
70+
$document = $this->normalizerFactory->document;
7271

7372
return SimpleDOM::appendChildren(
7473
SimpleDOM::setAttributes(
@@ -106,31 +105,31 @@ public function normalize(Component $component): DOMElement
106105
// components
107106
null === $evidence
108107
? null
109-
: $this->getNormalizerFactory()->makeForComponentEvidence()->normalize($evidence),
108+
: $this->normalizerFactory->makeForComponentEvidence()->normalize($evidence),
110109
]
111110
);
112111
}
113112

114113
private function normalizeLicenses(LicenseRepository $licenses): ?DOMElement
115114
{
116-
$factory = $this->getNormalizerFactory();
115+
$factory = $this->normalizerFactory;
117116

118117
return 0 === \count($licenses)
119118
? null
120119
: SimpleDOM::appendChildren(
121-
$factory->getDocument()->createElement('licenses'),
120+
$factory->document->createElement('licenses'),
122121
$factory->makeForLicenseRepository()->normalize($licenses)
123122
);
124123
}
125124

126125
private function normalizeHashes(HashDictionary $hashes): ?DOMElement
127126
{
128-
$factory = $this->getNormalizerFactory();
127+
$factory = $this->normalizerFactory;
129128

130129
return 0 === \count($hashes)
131130
? null
132131
: SimpleDOM::appendChildren(
133-
$factory->getDocument()->createElement('hashes'),
132+
$factory->document->createElement('hashes'),
134133
$factory->makeForHashDictionary()->normalize($hashes)
135134
);
136135
}
@@ -140,35 +139,35 @@ private function normalizePurl(?PackageUrl $purl): ?DOMElement
140139
return null === $purl
141140
? null
142141
: SimpleDOM::makeSafeTextElement(
143-
$this->getNormalizerFactory()->getDocument(),
142+
$this->normalizerFactory->document,
144143
'purl',
145144
XML::encodeAnyUriBE((string) $purl)
146145
);
147146
}
148147

149148
private function normalizeExternalReferences(ExternalReferenceRepository $extRefs): ?DOMElement
150149
{
151-
$factory = $this->getNormalizerFactory();
150+
$factory = $this->normalizerFactory;
152151

153152
return 0 === \count($extRefs)
154153
? null
155154
: SimpleDOM::appendChildren(
156-
$factory->getDocument()->createElement('externalReferences'),
155+
$factory->document->createElement('externalReferences'),
157156
$factory->makeForExternalReferenceRepository()->normalize($extRefs)
158157
);
159158
}
160159

161160
private function normalizeProperties(PropertyRepository $properties): ?DOMElement
162161
{
163-
if (false === $this->getNormalizerFactory()->getSpec()->supportsComponentProperties()) {
162+
if (false === $this->normalizerFactory->spec->supportsComponentProperties()) {
164163
return null;
165164
}
166165

167166
return 0 === \count($properties)
168167
? null
169168
: SimpleDOM::appendChildren(
170-
$this->getNormalizerFactory()->getDocument()->createElement('properties'),
171-
$this->getNormalizerFactory()->makeForPropertyRepository()->normalize($properties)
169+
$this->normalizerFactory->document->createElement('properties'),
170+
$this->normalizerFactory->makeForPropertyRepository()->normalize($properties)
172171
);
173172
}
174173
}

src/Core/Serialization/DOM/Normalizers/ComponentRepositoryNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ComponentRepositoryNormalizer extends _BaseNormalizer
3939
*/
4040
public function normalize(ComponentRepository $repo): array
4141
{
42-
$normalizer = $this->getNormalizerFactory()->makeForComponent();
42+
$normalizer = $this->normalizerFactory->makeForComponent();
4343

4444
$components = [];
4545
foreach ($repo->getItems() as $component) {

src/Core/Serialization/DOM/Normalizers/DependenciesNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private function normalizeDependency(BomRef $componentRef, BomRef ...$dependency
7979
return null;
8080
}
8181

82-
$doc = $this->getNormalizerFactory()->getDocument();
82+
$doc = $this->normalizerFactory->document;
8383

8484
$dependency = SimpleDOM::setAttributes(
8585
$doc->createElement('dependency'),

src/Core/Serialization/DOM/Normalizers/ExternalReferenceNormalizer.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ public function normalize(ExternalReference $externalReference): DOMElement
4848
$anyURI = XML::encodeAnyUriBE($refURI)
4949
?? throw new UnexpectedValueException("unable to make 'anyURI' from: $refURI");
5050

51-
$factory = $this->getNormalizerFactory();
52-
$spec = $factory->getSpec();
51+
$spec = $this->normalizerFactory->spec;
5352

5453
$type = $externalReference->getType();
5554
if (false === $spec->isSupportedExternalReferenceType($type)) {
@@ -60,7 +59,7 @@ public function normalize(ExternalReference $externalReference): DOMElement
6059
}
6160
}
6261

63-
$doc = $factory->getDocument();
62+
$doc = $this->normalizerFactory->document;
6463

6564
return SimpleDOM::appendChildren(
6665
SimpleDOM::setAttributes(
@@ -83,13 +82,13 @@ private function normalizeHashes(HashDictionary $hashes): ?DOMElement
8382
return null;
8483
}
8584

86-
$factory = $this->getNormalizerFactory();
87-
if (false === $factory->getSpec()->supportsExternalReferenceHashes()) {
85+
$factory = $this->normalizerFactory;
86+
if (false === $factory->spec->supportsExternalReferenceHashes()) {
8887
return null;
8988
}
9089

9190
return SimpleDOM::appendChildren(
92-
$factory->getDocument()->createElement('hashes'),
91+
$factory->document->createElement('hashes'),
9392
$factory->makeForHashDictionary()->normalize($hashes)
9493
);
9594
}

src/Core/Serialization/DOM/Normalizers/ExternalReferenceRepositoryNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ExternalReferenceRepositoryNormalizer extends _BaseNormalizer
4141
*/
4242
public function normalize(ExternalReferenceRepository $repo): array
4343
{
44-
$normalizer = $this->getNormalizerFactory()->makeForExternalReference();
44+
$normalizer = $this->normalizerFactory->makeForExternalReference();
4545

4646
$externalReferences = [];
4747
foreach ($repo->getItems() as $externalReference) {

src/Core/Serialization/DOM/Normalizers/HashDictionaryNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function normalize(HashDictionary $repo): array
4141
{
4242
$hashes = [];
4343

44-
$hashNormalizer = $this->getNormalizerFactory()->makeForHash();
44+
$hashNormalizer = $this->normalizerFactory->makeForHash();
4545
foreach ($repo->getItems() as [$algorithm , $content]) {
4646
try {
4747
$hashes[] = $hashNormalizer->normalize($algorithm, $content);

src/Core/Serialization/DOM/Normalizers/HashNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class HashNormalizer extends _BaseNormalizer
3939
*/
4040
public function normalize(HashAlgorithm $algorithm, string $content): DOMElement
4141
{
42-
$spec = $this->getNormalizerFactory()->getSpec();
42+
$spec = $this->normalizerFactory->spec;
4343
if (false === $spec->isSupportedHashAlgorithm($algorithm)) {
4444
throw new DomainException("Invalid hash algorithm: $algorithm->name", 1);
4545
}
@@ -48,7 +48,7 @@ public function normalize(HashAlgorithm $algorithm, string $content): DOMElement
4848
}
4949

5050
$element = SimpleDOM::makeSafeTextElement(
51-
$this->getNormalizerFactory()->getDocument(),
51+
$this->normalizerFactory->document,
5252
'hash',
5353
$content
5454
);

src/Core/Serialization/DOM/Normalizers/LicenseNormalizer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ public function normalize(LicenseExpression|SpdxLicense|NamedLicense $license):
4646
private function normalizeExpression(LicenseExpression $license): DOMElement
4747
{
4848
// TODO: IMPLEMENTED IF NEEDED: may throw, if not supported by the spec
49-
// $this->getNormalizerFactory()->getSpec()->supportsLicenseExpression()
49+
// $this->normalizerFactory->spec->supportsLicenseExpression()
5050

5151
$element = SimpleDOM::makeSafeTextElement(
52-
$this->getNormalizerFactory()->getDocument(),
52+
$this->normalizerFactory->document,
5353
'expression',
5454
$license->getExpression()
5555
);
@@ -63,17 +63,17 @@ private function normalizeExpression(LicenseExpression $license): DOMElement
6363
*/
6464
private function normalizeDisjunctive(SpdxLicense|NamedLicense $license): DOMElement
6565
{
66-
$factory = $this->getNormalizerFactory();
66+
$factory = $this->normalizerFactory;
6767

6868
[$id, $name] = $license instanceof SpdxLicense
6969
? [$license->getId(), null]
7070
: [null, $license->getName()];
7171

72-
if (null !== $id && !$factory->getSpec()->isSupportedLicenseIdentifier($id)) {
72+
if (null !== $id && !$factory->spec->isSupportedLicenseIdentifier($id)) {
7373
[$id, $name] = [null, $id];
7474
}
7575

76-
$document = $factory->getDocument();
76+
$document = $factory->document;
7777

7878
return SimpleDOM::appendChildren(
7979
$document->createElement('license'),

0 commit comments

Comments
 (0)