Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daVitekPL committed Nov 13, 2024
1 parent db1cea4 commit aacc208
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Helpers/MargeFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ class MargeFiles
private string $hash;
private string $patch;
private string $fileType;
private ?string $prefix;

public function __construct(?array $filesArray = null, ?string $fileType = null, ?string $patch = null)
{
$this->arrayFiles = $filesArray ?? [];
$this->fileType = $fileType ?? 'txt';
$this->patch = $patch ?? storage_path();
$this->hash = $this->getHash();
$this->prefix = env('AWS_URL', null);
}

public function setFileType(string $fileType): void
Expand All @@ -46,8 +48,7 @@ public function getHash(): string
{
$hash = [];
foreach ($this->arrayFiles as $file) {
$name = env('AWS_URL', null) ? Str::after($file, env('AWS_URL')) : $file;
$hash[] = hash('md5', Storage::get($name));
$hash[] = hash('md5', Storage::get($this->getNameAfterPrefix($file)));
}

return md5(serialize($hash));
Expand Down Expand Up @@ -97,7 +98,7 @@ private function createFile(string $fileName): bool
fwrite($stream, $contents . PHP_EOL);
}
rewind($stream);
Storage::put(Str::after($fileName, env('AWS_URL')), $stream);
Storage::put($this->getNameAfterPrefix($fileName), $stream);
fclose($stream);

return true;
Expand All @@ -111,7 +112,7 @@ private function createFile(string $fileName): bool
*/
private function getContent(string $path): string
{
$folderPath = Str::after($path, env('AWS_URL'));
$folderPath = $this->getNameAfterPrefix($path);
if (Storage::exists($folderPath)) {
return Storage::get($folderPath);
}
Expand All @@ -122,4 +123,9 @@ private function getContent(string $path): string

throw new Exception("File: '".$path."' do not exist");
}

private function getNameAfterPrefix(string $fileName): string
{
return $this->prefix ? Str::after($fileName, $this->prefix) : $fileName;
}
}

0 comments on commit aacc208

Please sign in to comment.