Remove requirement of longUrlWasProvided

This commit is contained in:
Alejandro Celaya
2026-05-10 10:45:32 +02:00
parent a4f39c18eb
commit 8341ae3d8b
6 changed files with 23 additions and 27 deletions
@@ -57,7 +57,6 @@ final class ShortUrlDataInput
return [
...array_filter(get_object_vars($this), static fn (mixed $value) => $value !== null),
'longUrl' => $longUrl,
'longUrlWasProvided' => $longUrl !== null,
'validSinceWasProvided' => $this->validSince !== null,
'validUntilWasProvided' => $this->validUntil !== null,
'maxVisitsWasProvided' => $this->maxVisits !== null,
+1 -1
View File
@@ -147,7 +147,7 @@ class ShortUrl extends AbstractEntity
if ($shortUrlEdit->maxVisitsWasProvided) {
$this->maxVisits = $shortUrlEdit->maxVisits;
}
if ($shortUrlEdit->longUrlWasProvided()) {
if ($shortUrlEdit->longUrlWasProvided) {
$this->longUrl = $shortUrlEdit->longUrl ?? $this->longUrl;
}
if ($shortUrlEdit->tagsWereProvided) {
@@ -13,35 +13,40 @@ use Shlinkio\Shlink\Core\ShortUrl\Helper\TitleResolutionModelInterface;
use function Shlinkio\Shlink\Common\normalizeOptionalDate;
final readonly class ShortUrlEdition implements TitleResolutionModelInterface
final class ShortUrlEdition implements TitleResolutionModelInterface
{
public Chronos|null $validSince;
public Chronos|null $validUntil;
// phpcs:disable PSR2.Classes.PropertyDeclaration.Multiple
public bool $longUrlWasProvided {
// phpcs:disable PSR2.Classes.PropertyDeclaration.ScopeMissing
get => $this->longUrl !== null;
}
/**
* @param string[] $tags
*/
public function __construct(
private bool $longUrlWasProvided = false,
#[LooseUriConverter]
public string|null $longUrl = null,
public bool $validSinceWasProvided = false,
readonly public string|null $longUrl = null,
readonly public bool $validSinceWasProvided = false,
DateTimeInterface|string|null $validSince = null,
public bool $validUntilWasProvided = false,
readonly public bool $validUntilWasProvided = false,
DateTimeInterface|string|null $validUntil = null,
public bool $maxVisitsWasProvided = false,
public int|null $maxVisits = null,
public bool $tagsWereProvided = false,
readonly public bool $maxVisitsWasProvided = false,
readonly public int|null $maxVisits = null,
readonly public bool $tagsWereProvided = false,
#[TagsConverter]
public array $tags = [],
public bool $titleWasProvided = false,
readonly public array $tags = [],
readonly public bool $titleWasProvided = false,
#[SubstringConverter(512)]
public string|null $title = null,
public bool $titleWasAutoResolved = false,
public bool $crawlableWasProvided = false,
public bool $crawlable = false,
public bool $forwardQueryWasProvided = false,
public bool $forwardQuery = true,
readonly public string|null $title = null,
readonly public bool $titleWasAutoResolved = false,
readonly public bool $crawlableWasProvided = false,
readonly public bool $crawlable = false,
readonly public bool $forwardQueryWasProvided = false,
readonly public bool $forwardQuery = true,
) {
$this->validSince = normalizeOptionalDate($validSince);
$this->validUntil = normalizeOptionalDate($validUntil);
@@ -56,7 +61,6 @@ final readonly class ShortUrlEdition implements TitleResolutionModelInterface
// ]);
return new self(
longUrlWasProvided: $this->longUrlWasProvided,
longUrl: $this->longUrl,
validSinceWasProvided: $this->validSinceWasProvided,
validSince: $this->validSince,
@@ -76,11 +80,6 @@ final readonly class ShortUrlEdition implements TitleResolutionModelInterface
);
}
public function longUrlWasProvided(): bool
{
return $this->longUrlWasProvided && $this->longUrl !== null;
}
public function hasTitle(): bool
{
return $this->titleWasProvided;
+1 -1
View File
@@ -31,7 +31,7 @@ readonly class ShortUrlService implements ShortUrlServiceInterface
ShortUrlEdition $shortUrlEdit,
ApiKey|null $apiKey = null,
): ShortUrl {
if ($shortUrlEdit->longUrlWasProvided()) {
if ($shortUrlEdit->longUrlWasProvided) {
$shortUrlEdit = $this->titleResolutionHelper->processTitle($shortUrlEdit);
}
@@ -85,7 +85,6 @@ class ShortUrlServiceTest extends TestCase
maxVisits: 5,
), null];
yield 'long URL and API key' => [new InvokedCount(1), new ShortUrlEdition(
longUrlWasProvided: true,
longUrl: 'https://modifiedLongUrl',
validSinceWasProvided: true,
validSince: Chronos::parse('2017-01-01 00:00:00'),
@@ -34,7 +34,6 @@ class EditShortUrlAction extends AbstractRestAction
$body = (array) $request->getParsedBody();
$shortUrlEdit = $this->treeMapper->map(ShortUrlEdition::class, [
...$body,
'longUrlWasProvided' => array_key_exists('longUrl', $body),
'validSinceWasProvided' => array_key_exists('validSince', $body),
'validUntilWasProvided' => array_key_exists('validUntil', $body),
'maxVisitsWasProvided' => array_key_exists('maxVisits', $body),