Reduce duplicated code when parsing short codes and domains from CLI

This commit is contained in:
Alejandro Celaya
2024-03-03 10:10:39 +01:00
parent a45550b0c6
commit c346fd0602
9 changed files with 89 additions and 65 deletions

View File

@@ -6,7 +6,6 @@ namespace Shlinkio\Shlink\Core\ShortUrl\Model;
use Psr\Http\Message\ServerRequestInterface;
use Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl;
use Symfony\Component\Console\Input\InputInterface;
use function sprintf;
@@ -32,18 +31,6 @@ final readonly class ShortUrlIdentifier
return new self($shortCode, $domain);
}
public static function fromCli(InputInterface $input): self
{
// Using getArguments and getOptions instead of getArgument(...) and getOption(...) because
// the later throw an exception if requested options are not defined
/** @var string $shortCode */
$shortCode = $input->getArguments()['shortCode'] ?? '';
/** @var string|null $domain */
$domain = $input->getOptions()['domain'] ?? null;
return new self($shortCode, $domain);
}
public static function fromShortUrl(ShortUrl $shortUrl): self
{
$domain = $shortUrl->getDomain();