Skip to content

Commit

Permalink
IBX-8784: Added AbstractExceptionVisitor template
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveb-p committed Oct 11, 2024
1 parent f746d96 commit 3cbe21e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2890,11 +2890,6 @@ parameters:
count: 1
path: src/lib/Server/Output/ValueObjectVisitor/ContentFieldValidationException.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Output\\\\ValueObjectVisitor\\\\ContentFieldValidationException\\:\\:visit\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Server/Output/ValueObjectVisitor/ContentFieldValidationException.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Output\\\\ValueObjectVisitor\\\\ContentList\\:\\:visit\\(\\) has no return type specified\\.$#"
count: 1
Expand Down Expand Up @@ -3175,16 +3170,6 @@ parameters:
count: 1
path: src/lib/Server/Output/ValueObjectVisitor/DeletedUserSession.php

-
message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Output\\\\ValueObjectVisitor\\\\Exception\\:\\:visit\\(\\) has no return type specified\\.$#"
count: 1
path: src/lib/Server/Output/ValueObjectVisitor/Exception.php

-
message: "#^Property Ibexa\\\\Rest\\\\Server\\\\Output\\\\ValueObjectVisitor\\\\Exception\\:\\:\\$httpStatusCodes type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Server/Output/ValueObjectVisitor/Exception.php

-
message: "#^Property Ibexa\\\\Rest\\\\Server\\\\Output\\\\ValueObjectVisitor\\\\Exception\\:\\:\\$translator \\(Symfony\\\\Contracts\\\\Translation\\\\TranslatorInterface\\) does not accept Symfony\\\\Contracts\\\\Translation\\\\TranslatorInterface\\|null\\.$#"
count: 1
Expand Down
13 changes: 8 additions & 5 deletions src/contracts/Output/Exceptions/AbstractExceptionVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class AbstractExceptionVisitor extends ValueObjectVisitor
/**
* Mapping of HTTP status codes to their respective error messages.
*
* @var array
* @var array<int, string>
*/
protected static $httpStatusCodes = [
400 => 'Bad Request',
Expand Down Expand Up @@ -71,6 +71,8 @@ protected function getStatus()

/**
* @param \Exception $data
*
* @return void
*/
public function visit(Visitor $visitor, Generator $generator, $data)
{
Expand Down Expand Up @@ -119,16 +121,17 @@ protected function getErrorMessage(\Exception $data, int $statusCode): string

protected function getErrorDescription(\Exception $data, int $statusCode): string
{
$translator = $this->getTranslator();
if ($statusCode < 500 || $this->canDisplayExceptionMessage()) {
$errorDescription = $data instanceof Translatable && $this->translator
$errorDescription = $data instanceof Translatable && $translator
? /** @Ignore */
$this->translator->trans($data->getMessageTemplate(), $data->getParameters(), 'ibexa_repository_exceptions')
$translator->trans($data->getMessageTemplate(), $data->getParameters(), 'ibexa_repository_exceptions')
: $data->getMessage();
} else {
// Do not leak any file paths and sensitive data on production environments
$errorDescription = $this->translator
$errorDescription = $translator
? /** @Desc("An error has occurred. Please try again later or contact your Administrator.") */
$this->translator->trans('non_verbose_error', [], 'ibexa_repository_exceptions')
$translator->trans('non_verbose_error', [], 'ibexa_repository_exceptions')
: 'An error has occurred. Please try again later or contact your Administrator.';
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/Server/Output/ValueObjectVisitor/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Exception extends AbstractExceptionVisitor
*/
protected $debug = false;

/** @var \Symfony\Contracts\Translation\TranslatorInterface|null */
/** @var \Symfony\Contracts\Translation\TranslatorInterface */
protected $translator;

/**
Expand Down

0 comments on commit 3cbe21e

Please sign in to comment.