Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
cesargb committed Dec 6, 2021
1 parent 78f1df2 commit 3f31a9a
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions src/Rotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,16 @@ public function rotate(string $filename): bool
return false;
}

$fileNameTemp = $this->moveContentToTempFile($filename);
$filenameRotated = $this->runProcessor(
$filename,
$this->moveContentToTempFile($filename)
);

$filenameRotated = $this->runProcessor($filename, $fileNameTemp);
$filenameRotated = is_null($filenameRotated)
? $filenameRotated
: $this->runCompress($filenameRotated);

if ($filenameRotated && $this->_compress) {
$gz = new Gz();

try {
$filenameRotated = $gz->handler($filenameRotated);
} catch (Exception $error) {
$this->exception($error);

$filenameRotated = null;
}
}

if ($filenameRotated && $this->thenCallback) {
call_user_func($this->thenCallback, $filenameRotated, $filename);
}
$this->sucessfull($filename, $filenameRotated);

return !empty($filenameRotated);
}
Expand All @@ -130,6 +121,32 @@ private function runProcessor(string $filenameSource, ?string $filenameTarget):
return $this->processor->handler($filenameTarget);
}

private function runCompress(string $filename): ?string
{
if (!$this->_compress) {
return $filename;
}

$gz = new Gz();

try {
return $gz->handler($filename);
} catch (Exception $error) {
$this->exception($error);

return null;
}
}

private function sucessfull(string $filenameSource, ?string $filenameRotated): void
{
if (is_null($this->thenCallback) || is_null($filenameRotated)) {
return;
}

call_user_func($this->thenCallback, $filenameRotated, $filenameSource);
}

/**
* check if file need rotate.
*/
Expand Down

0 comments on commit 3f31a9a

Please sign in to comment.