Skip to content

Commit

Permalink
Extract helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jun 25, 2024
1 parent 3d05b2f commit b2d3282
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class ParseException extends RuntimeException

public function __construct(string $file = '', ?Throwable $previous = null)
{
parent::__construct(rtrim(sprintf("Invalid %s in file: '%s' %s",
$this->getTypeLabel($file), $file, $this->getContext($previous))
), previous: $previous);
parent::__construct($this->formatMessage($file, $previous), previous: $previous);
}

protected function getTypeLabel(string $file): string
Expand All @@ -39,4 +37,9 @@ protected function getContext(?Throwable $previous): string
{
return ($previous && $previous->getMessage()) ? sprintf('(%s)', rtrim($previous->getMessage(), '.')) : '';
}

protected function formatMessage(string $file, ?Throwable $previous): string
{
return rtrim(sprintf("Invalid %s in file: '%s' %s", $this->getTypeLabel($file), $file, $this->getContext($previous)));
}
}

0 comments on commit b2d3282

Please sign in to comment.