Skip to content

Commit df10768

Browse files
committed
Simplify EntityHfdController
1 parent 17b69de commit df10768

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

app/Http/Controllers/EntityHfdController.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ public function update(Entity $entity): RedirectResponse
2525

2626
$entity = DB::transaction(function () use ($entity) {
2727
$entity->hfd = ! $entity->hfd;
28-
$xml_document = HfdTag::update($entity);
29-
if ($xml_document) {
30-
$entity->xml_file = $xml_document;
31-
$entity->update();
32-
}
28+
$entity->xml_file = HfdTag::update($entity);
29+
$entity->update();
3330

3431
return $entity;
3532
});

app/Services/HfdTagService.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,33 @@ public function createFromXml(string $xml_document): false|string
4242
return $dom->saveXML();
4343
}
4444

45-
public function delete(Entity $entity): false|string
45+
public function delete(Entity $entity): string
4646
{
4747
$dom = $this->createDOM($entity->xml_file);
4848
$xPath = $this->createXPath($dom);
49-
$this->deleteByXpath($xPath);
49+
$xpathQuery = $this->buildXPathQuery($this->value);
50+
$this->DeleteAllTags($xpathQuery, $xPath);
5051
$dom->normalize();
5152

5253
return $dom->saveXML();
5354
}
5455

55-
public function deleteByXpath(DOMXPath $xPath): void
56-
{
57-
$xpathQuery = $this->buildXPathQuery($this->value);
58-
$this->DeleteAllTags($xpathQuery, $xPath);
59-
}
60-
61-
public function update(Entity $entity): false|string
56+
public function update(Entity $entity): string
6257
{
6358
try {
6459
if ($entity->hfd) {
6560
if (! $this->hasTagInDocument($entity->xml_file, $this->value)) {
6661
return $this->create($entity);
6762
}
63+
64+
return $entity->xml_file;
6865
} else {
6966
if ($this->hasTagInDocument($entity->xml_file, $this->value)) {
7067
return $this->delete($entity);
7168
}
72-
}
7369

74-
return false;
70+
return $entity->xml_file;
71+
}
7572
} catch (Exception $e) {
7673
Log::critical("Exception occurred in {$entity->id}}: {$e->getMessage()}");
7774
throw $e;

0 commit comments

Comments
 (0)