Skip to content

Commit

Permalink
Improve handling of empty values in validators
Browse files Browse the repository at this point in the history
  • Loading branch information
jskowronski39 committed Jan 7, 2024
1 parent 9ba4259 commit 663b938
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Form/Dlc/Dto/DlcFormDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class DlcFormDto extends AbstractFormDto
#[Assert\Length(min: 1, max: 255)]
protected ?string $description = null;

#[Assert\NotBlank]
protected ?string $url = null;

#[Assert\NotBlank]
Expand Down
3 changes: 3 additions & 0 deletions src/Validator/Dlc/SteamStoreArma3DlcUrlValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public function validate(mixed $value, Constraint $constraint): void
}

$url = $value->getUrl();
if ('' === $url || null === $url) {
return;
}

try {
$appId = SteamHelper::appUrlToAppId($url);
Expand Down
6 changes: 5 additions & 1 deletion src/Validator/Dlc/UniqueDirectoryDlcValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ public function validate(mixed $value, Constraint $constraint): void
}

$directory = $value->getDirectory();
if ('' === $directory || null === $directory) {
return;
}

$id = $value->getId();
if (!$directory || $this->isColumnValueUnique(Dlc::class, ['directory' => $directory], $id)) {
if ($this->isColumnValueUnique(Dlc::class, ['directory' => $directory], $id)) {
return;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Validator/Mod/UniqueDirectoryModValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ public function validate(mixed $value, Constraint $constraint): void
}

$directory = $value->getDirectory();
if ('' === $directory || null === $directory) {
return;
}

$id = $value->getId();
if (!$directory || $this->isColumnValueUnique(DirectoryMod::class, ['directory' => $directory], $id)) {
if ($this->isColumnValueUnique(DirectoryMod::class, ['directory' => $directory], $id)) {
return;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Validator/ModGroup/UniqueModGroupNameValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ public function validate(mixed $value, Constraint $constraint): void
}

$name = $value->getName();
if ('' === $name || null === $name) {
return;
}

$id = $value->getId();
if (!$name || $this->isColumnValueUnique(ModGroup::class, ['name' => $name], $id)) {
if ($this->isColumnValueUnique(ModGroup::class, ['name' => $name], $id)) {
return;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Validator/ModList/UniqueModListNameValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ public function validate(mixed $value, Constraint $constraint): void
}

$name = $value->getName();
if ('' === $name || null === $name) {
return;
}

$id = $value->getId();
if (!$name || $this->isColumnValueUnique(ModList::class, ['name' => $name], $id)) {
if ($this->isColumnValueUnique(ModList::class, ['name' => $name], $id)) {
return;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Validator/User/UniqueUserSteamIdValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ public function validate(mixed $value, Constraint $constraint): void
}

$steamId = $value->getSteamId();
if (null === $steamId) {
return;
}

$id = $value->getId();
if (!$steamId || $this->isColumnValueUnique(User::class, ['steamId' => $steamId], $id)) {
if ($this->isColumnValueUnique(User::class, ['steamId' => $steamId], $id)) {
return;
}

Expand Down
6 changes: 5 additions & 1 deletion src/Validator/UserGroup/UniqueUserGroupNameValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ public function validate(mixed $value, Constraint $constraint): void
}

$name = $value->getName();
if ('' === $name || null === $name) {
return;
}

$id = $value->getId();
if (!$name || $this->isColumnValueUnique(UserGroup::class, ['name' => $name], $id)) {
if ($this->isColumnValueUnique(UserGroup::class, ['name' => $name], $id)) {
return;
}

Expand Down

0 comments on commit 663b938

Please sign in to comment.