Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
11.11% |
1 / 9 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| EnumInteractor | |
11.11% |
1 / 9 |
|
50.00% |
1 / 2 |
4.81 | |
0.00% |
0 / 1 |
| supports | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| interactWith | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\Console\Helpers; |
| 3 | |
| 4 | use Apie\Core\Context\ApieContext; |
| 5 | use Apie\Core\Metadata\EnumMetadata; |
| 6 | use Apie\Core\Metadata\MetadataInterface; |
| 7 | use Apie\Core\Utils\EnumUtils; |
| 8 | use ReflectionEnum; |
| 9 | use Symfony\Component\Console\Helper\HelperSet; |
| 10 | use Symfony\Component\Console\Helper\QuestionHelper; |
| 11 | use Symfony\Component\Console\Input\InputInterface; |
| 12 | use Symfony\Component\Console\Output\OutputInterface; |
| 13 | use Symfony\Component\Console\Question\ChoiceQuestion; |
| 14 | |
| 15 | final class EnumInteractor implements InputInteractorInterface |
| 16 | { |
| 17 | public function supports(MetadataInterface $metadata): bool |
| 18 | { |
| 19 | return $metadata instanceof EnumMetadata; |
| 20 | } |
| 21 | public function interactWith( |
| 22 | MetadataInterface $metadata, |
| 23 | HelperSet $helperSet, |
| 24 | InputInterface $input, |
| 25 | OutputInterface $output, |
| 26 | ApieContext $context |
| 27 | ): mixed { |
| 28 | $helper = $helperSet->get('question'); |
| 29 | assert($helper instanceof QuestionHelper); |
| 30 | $class = $metadata->toClass(); |
| 31 | assert($class instanceof ReflectionEnum); |
| 32 | $question = new ChoiceQuestion('Pick a value: ', EnumUtils::getValues($class)); |
| 33 | $result = $helper->ask($input, $output, $question); |
| 34 | $output->writeln(''); |
| 35 | return $result; |
| 36 | } |
| 37 | } |