1212use Symfony \Component \Console \Question \ChoiceQuestion ;
1313use Symfony \Component \Console \Question \ConfirmationQuestion ;
1414use Symfony \Component \Console \Question \Question ;
15+ use thofman \KnowledgeBase \Domain \Question \Validation \NonEmptyStringValidator ;
1516use 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