Remove requirement of checker props in ShortUrlEdition

This commit is contained in:
Alejandro Celaya
2026-05-10 12:08:36 +02:00
parent 8341ae3d8b
commit 2482dabdc3
5 changed files with 10 additions and 28 deletions
@@ -60,10 +60,7 @@ final class ShortUrlDataInput
'validSinceWasProvided' => $this->validSince !== null,
'validUntilWasProvided' => $this->validUntil !== null,
'maxVisitsWasProvided' => $this->maxVisits !== null,
'tagsWereProvided' => $this->tags !== null,
'titleWasProvided' => $this->title !== null,
'crawlableWasProvided' => $this->crawlable !== null,
'forwardQueryWasProvided' => $this->noForwardQuery !== null,
];
}
}
+5 -5
View File
@@ -147,14 +147,14 @@ class ShortUrl extends AbstractEntity
if ($shortUrlEdit->maxVisitsWasProvided) {
$this->maxVisits = $shortUrlEdit->maxVisits;
}
if ($shortUrlEdit->longUrlWasProvided) {
$this->longUrl = $shortUrlEdit->longUrl ?? $this->longUrl;
if ($shortUrlEdit->longUrl !== null) {
$this->longUrl = $shortUrlEdit->longUrl;
}
if ($shortUrlEdit->tagsWereProvided) {
if ($shortUrlEdit->tags !== null) {
$relationResolver = $relationResolver ?? new SimpleShortUrlRelationResolver();
$this->tags = $relationResolver->resolveTags($shortUrlEdit->tags);
}
if ($shortUrlEdit->crawlableWasProvided) {
if ($shortUrlEdit->crawlable !== null) {
$this->crawlable = $shortUrlEdit->crawlable;
}
if (
@@ -165,7 +165,7 @@ class ShortUrl extends AbstractEntity
$this->title = $shortUrlEdit->title;
$this->titleWasAutoResolved = $shortUrlEdit->titleWasAutoResolved;
}
if ($shortUrlEdit->forwardQueryWasProvided) {
if ($shortUrlEdit->forwardQuery !== null) {
$this->forwardQuery = $shortUrlEdit->forwardQuery;
}
}
@@ -18,14 +18,8 @@ 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
* @param string[]|null $tags
*/
public function __construct(
#[LooseUriConverter]
@@ -36,17 +30,14 @@ final class ShortUrlEdition implements TitleResolutionModelInterface
DateTimeInterface|string|null $validUntil = null,
readonly public bool $maxVisitsWasProvided = false,
readonly public int|null $maxVisits = null,
readonly public bool $tagsWereProvided = false,
#[TagsConverter]
readonly public array $tags = [],
readonly public array|null $tags = null,
readonly public bool $titleWasProvided = false,
#[SubstringConverter(512)]
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,
readonly public bool|null $crawlable = null,
readonly public bool|null $forwardQuery = null,
) {
$this->validSince = normalizeOptionalDate($validSince);
$this->validUntil = normalizeOptionalDate($validUntil);
@@ -68,14 +59,11 @@ final class ShortUrlEdition implements TitleResolutionModelInterface
validUntil: $this->validUntil,
maxVisitsWasProvided: $this->maxVisitsWasProvided,
maxVisits: $this->maxVisits,
tagsWereProvided: $this->tagsWereProvided,
tags: $this->tags,
titleWasProvided: $this->titleWasProvided,
title: $title,
titleWasAutoResolved: true,
crawlableWasProvided: $this->crawlableWasProvided,
crawlable: $this->crawlable,
forwardQueryWasProvided: $this->forwardQueryWasProvided,
forwardQuery: $this->forwardQuery,
);
}
+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->longUrl !== null) {
$shortUrlEdit = $this->titleResolutionHelper->processTitle($shortUrlEdit);
}
@@ -37,10 +37,7 @@ class EditShortUrlAction extends AbstractRestAction
'validSinceWasProvided' => array_key_exists('validSince', $body),
'validUntilWasProvided' => array_key_exists('validUntil', $body),
'maxVisitsWasProvided' => array_key_exists('maxVisits', $body),
'tagsWereProvided' => array_key_exists('tags', $body),
'titleWasProvided' => array_key_exists('title', $body),
'crawlableWasProvided' => array_key_exists('crawlable', $body),
'forwardQueryWasProvided' => array_key_exists('forwardQuery', $body),
]);
$identifier = ShortUrlIdentifier::fromApiRequest($request);