Skip to content

Commit

Permalink
Fix Codacy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
markusweigelt committed Jan 22, 2025
1 parent b3bdb62 commit 2acf6cb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions Classes/Validation/DomDocumentUrlExistenceValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,22 @@
*/
class DomDocumentUrlExistenceValidator extends AbstractDlfValidator
{

/**
* Excluded host names separated by comma.
* @var array
*/
private array $excludeHosts;

public function __construct(array $configuration = [])
{
parent::__construct(DOMDocument::class);
$this->excludeHosts = isset($configuration["excludeHosts"]) ? explode(",", $configuration["excludeHosts"]) : [];
$this->excludeHosts = [];
if (isset($configuration["excludeHosts"])) {
$this->excludeHosts = explode(",", $configuration["excludeHosts"]);
}
}



protected function isValid($value): void
{
foreach ($this->getDocumentUrls($value) as $url) {
Expand All @@ -69,7 +75,8 @@ protected function isValid($value): void
*/
protected function getDocumentUrls(DOMDocument $document): array
{
$tempDocument = clone $document; // do not modify original document
// do not modify original document
$tempDocument = clone $document;
$urls = $this->getFileUrlAndRemoveFileGroups($tempDocument);

// get the urls of document without file group nodes
Expand Down Expand Up @@ -105,7 +112,8 @@ protected function getFileUrlAndRemoveFileGroups(DOMDocument $document): array
$urls[] = $url;
}
}
$hosts = []; // reset to check for every file group
// reset to check for every file group
$hosts = [];
$fileGroup->parentNode->removeChild($fileGroup);
}
return $urls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ protected function createValidator(): AbstractDlfValidator
{
// ignore all urls of fixture xml to test specifically
$excludeHosts = 'www.loc.gov,id.loc.gov,example.com,dfg-viewer.de,www.w3.org';
return new DomDocumentUrlExistenceValidator(array('excludeHosts' => $excludeHosts));
return new DomDocumentUrlExistenceValidator(['excludeHosts' => $excludeHosts]);
}
}

0 comments on commit 2acf6cb

Please sign in to comment.