Skip to content

Commit

Permalink
Better message handling in ZugferdKositValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
HorstOeko committed Nov 12, 2024
1 parent bacbe67 commit 7d8f01d
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/ZugferdKositValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use DOMDocument;
use DOMXPath;
use Exception;
use horstoeko\stringmanagement\FileUtils;
use horstoeko\stringmanagement\PathUtils;
use horstoeko\stringmanagement\StringUtils;
Expand Down Expand Up @@ -403,7 +402,7 @@ private function clearMessageBag(): void
/**
* Add message to error bag
*
* @param string|Exception|Throwable $error
* @param string|Throwable $error
* @return void
*/
private function addToMessageBag($error, string $messageType = ""): void
Expand All @@ -412,8 +411,6 @@ private function addToMessageBag($error, string $messageType = ""): void

if (is_string($error)) {
$this->messageBag[] = ["type" => $messageType, "message" => $error];
} elseif ($error instanceof Exception) {
$this->messageBag[] = ["type" => $messageType, "message" => $error->getMessage()];
} elseif ($error instanceof Throwable) {
$this->messageBag[] = ["type" => $messageType, "message" => $error->getMessage()];
}
Expand Down Expand Up @@ -605,10 +602,12 @@ private function checkRequirements(): bool
private function downloadRequiredFiles(): bool
{
if (!$this->runFileDownload($this->validatorDownloadUrl, $this->resolveAppZipFilename())) {
$this->addToMessageBag(sprintf("Unable to download from %s containing the JAVA-Application", $this->validatorDownloadUrl));
return false;
}

if (!$this->runFileDownload($this->validatorScenarioDownloadUrl, $this->resolveScenatioZipFilename())) {
$this->addToMessageBag(sprintf("Unable to download from %s containing the validation scenarios", $this->validatorScenarioDownloadUrl));
return false;
}

Expand All @@ -626,12 +625,12 @@ private function unpackRequiredFiles(): bool
$validatorScenarioFile = $this->resolveScenatioZipFilename();

if ($this->unpackRequiredFile($validatorAppFile) !== true) {
$this->addToMessageBag("Unable to unpack archive $validatorAppFile containing the JAVA-Application");
$this->addToMessageBag(sprintf("Unable to unpack archive %s containing the JAVA-Application", $validatorAppFile));
return false;
}

if ($this->unpackRequiredFile($validatorScenarioFile) !== true) {
$this->addToMessageBag("Unable to unpack archive $validatorScenarioFile containing the validation scenarios");
$this->addToMessageBag(sprintf("Unable to unpack archive %s containing the validation scenarios", $validatorScenarioFile));
return false;
}

Expand All @@ -649,6 +648,7 @@ private function unpackRequiredFile(string $filename): bool
$zip = new ZipArchive();

if ($zip->open($filename) !== true) {
$this->addToMessageBag(sprintf("Failed to open ZIP archive %s", $filename));
return false;
}

Expand All @@ -668,6 +668,7 @@ private function unpackRequiredFile(string $filename): bool

if ($zip->extractTo($this->resolveBaseDirectory()) !== true) {
$zip->close();
$this->addToMessageBag(sprintf("Failed to extract ZIP archive %s", $filename));
return false;
}

Expand Down Expand Up @@ -832,9 +833,6 @@ private function runValidationApplication(array $command, string $workingdirecto
}
return false;
}
} catch (Exception $e) {
$this->addToMessageBag($e, static::MSG_TYPE_VALIDATIONERROR);
return false;
} catch (Throwable $e) {
$this->addToMessageBag($e, static::MSG_TYPE_VALIDATIONERROR);
return false;
Expand All @@ -858,9 +856,6 @@ private function runFileDownload(string $url, string $toFilePath, bool $forceOve
return true;
}
file_put_contents($toFilePath, file_get_contents($url));
} catch (Exception $e) {
$this->addToMessageBag($e);
return false;
} catch (Throwable $e) {
$this->addToMessageBag($e);
return false;
Expand Down

0 comments on commit 7d8f01d

Please sign in to comment.