Skip to content

Commit

Permalink
chore: add check if key file exists
Browse files Browse the repository at this point in the history
This may avoid warnings when using file_get_contents() with a non-existing file.
  • Loading branch information
brotkrueml committed Aug 21, 2024
1 parent 54ca19d commit d11f2c4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Classes/Service/Crypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace JobRouter\AddOn\Typo3Connector\Service;

use JobRouter\AddOn\Typo3Connector\Exception\CryptException;
use JobRouter\AddOn\Typo3Connector\Exception\KeyFileException;

/**
* @internal
Expand Down Expand Up @@ -79,7 +80,18 @@ public function generateKey(): string

private function getKey(): string
{
$key = \file_get_contents($this->fileService->getAbsoluteKeyPath());
$filePath = $this->fileService->getAbsoluteKeyPath();
if (! \is_file($filePath)) {
throw new KeyFileException(
\sprintf(
'File with path "%s" does not exist',
$filePath,
),
1724241293,
);
}

$key = \file_get_contents($filePath);
if ($key === false) {
throw new CryptException(
'The key could not be retrieved!',
Expand Down

0 comments on commit d11f2c4

Please sign in to comment.