Created value object to wrap the renaming of a tag

This commit is contained in:
Alejandro Celaya
2021-01-06 13:11:28 +01:00
parent 041f231ff2
commit b5710f87e2
10 changed files with 102 additions and 32 deletions

View File

@@ -7,6 +7,7 @@ namespace Shlinkio\Shlink\Core\Exception;
use Fig\Http\Message\StatusCodeInterface;
use Mezzio\ProblemDetails\Exception\CommonProblemDetailsExceptionTrait;
use Mezzio\ProblemDetails\Exception\ProblemDetailsExceptionInterface;
use Shlinkio\Shlink\Core\Tag\Model\TagRenaming;
use function sprintf;
@@ -17,18 +18,15 @@ class TagConflictException extends RuntimeException implements ProblemDetailsExc
private const TITLE = 'Tag conflict';
private const TYPE = 'TAG_CONFLICT';
public static function fromExistingTag(string $oldName, string $newName): self
public static function forExistingTag(TagRenaming $renaming): self
{
$e = new self(sprintf('You cannot rename tag %s to %s, because it already exists', $oldName, $newName));
$e = new self(sprintf('You cannot rename tag %s, because it already exists', $renaming->toString()));
$e->detail = $e->getMessage();
$e->title = self::TITLE;
$e->type = self::TYPE;
$e->status = StatusCodeInterface::STATUS_CONFLICT;
$e->additional = [
'oldName' => $oldName,
'newName' => $newName,
];
$e->additional = $renaming->toArray();
return $e;
}