TagConflictException.php 1012 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. declare(strict_types=1);
  3. namespace Shlinkio\Shlink\Core\Exception;
  4. use Fig\Http\Message\StatusCodeInterface;
  5. use Mezzio\ProblemDetails\Exception\CommonProblemDetailsExceptionTrait;
  6. use Mezzio\ProblemDetails\Exception\ProblemDetailsExceptionInterface;
  7. use function sprintf;
  8. class TagConflictException extends RuntimeException implements ProblemDetailsExceptionInterface
  9. {
  10. use CommonProblemDetailsExceptionTrait;
  11. private const TITLE = 'Tag conflict';
  12. private const TYPE = 'TAG_CONFLICT';
  13. public static function fromExistingTag(string $oldName, string $newName): self
  14. {
  15. $e = new self(sprintf('You cannot rename tag %s to %s, because it already exists', $oldName, $newName));
  16. $e->detail = $e->getMessage();
  17. $e->title = self::TITLE;
  18. $e->type = self::TYPE;
  19. $e->status = StatusCodeInterface::STATUS_CONFLICT;
  20. $e->additional = [
  21. 'oldName' => $oldName,
  22. 'newName' => $newName,
  23. ];
  24. return $e;
  25. }
  26. }