Skip to content

Commit 8c31441

Browse files
committed
Use NonEmptyStringValidator
1 parent d7c1773 commit 8c31441

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Command/AddArticle.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Symfony\Component\Console\Question\ChoiceQuestion;
1313
use Symfony\Component\Console\Question\ConfirmationQuestion;
1414
use Symfony\Component\Console\Question\Question;
15+
use thofman\KnowledgeBase\Domain\Question\Validation\NonEmptyStringValidator;
1516
use thofman\KnowledgeBase\Tag\Tag;
1617

1718
#[AsCommand(name: 'app:add-article', description: 'Add an article')]
@@ -24,7 +25,9 @@ public function execute(InputInterface $input, OutputInterface $output): int
2425
$authorQuestion = new Question('Please enter the name of the author: ', '');
2526
$authorQuestion->setValidator(
2627
static function (string $value): string {
27-
if (trim($value) === '') {
28+
$nonEmptyStringValidator = new NonEmptyStringValidator();
29+
$validationResult = $nonEmptyStringValidator->validate($value);
30+
if (!$validationResult->isValid) {
2831
throw new RuntimeException('Author cannot be empty');
2932
}
3033

@@ -36,7 +39,9 @@ static function (string $value): string {
3639
$titleQuestion = new Question('Please enter the title of the article: ', '');
3740
$titleQuestion->setValidator(
3841
static function (string $value): string {
39-
if (trim($value) === '') {
42+
$nonEmptyStringValidator = new NonEmptyStringValidator();
43+
$validationResult = $nonEmptyStringValidator->validate($value);
44+
if (!$validationResult->isValid) {
4045
throw new RuntimeException('Title cannot be empty');
4146
}
4247

@@ -48,7 +53,9 @@ static function (string $value): string {
4853
$urlQuestion = new Question('Please enter the URL of the article: ', '');
4954
$urlQuestion->setValidator(
5055
static function (string $value): string {
51-
if (trim($value) === '') {
56+
$nonEmptyStringValidator = new NonEmptyStringValidator();
57+
$validationResult = $nonEmptyStringValidator->validate($value);
58+
if (!$validationResult->isValid) {
5259
throw new RuntimeException('URL cannot be empty');
5360
}
5461

0 commit comments

Comments
 (0)