Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
4.55% |
1 / 22 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ItemHashmapInteractor | |
4.55% |
1 / 22 |
|
50.00% |
1 / 2 |
10.83 | |
0.00% |
0 / 1 |
| supports | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| interactWith | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | namespace Apie\Console\Helpers; |
| 3 | |
| 4 | use Apie\Console\ApieInputHelper; |
| 5 | use Apie\Core\Context\ApieContext; |
| 6 | use Apie\Core\Metadata\ItemHashmapMetadata; |
| 7 | use Apie\Core\Metadata\MetadataInterface; |
| 8 | use Apie\TypeConverter\ReflectionTypeFactory; |
| 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\ConfirmationQuestion; |
| 14 | |
| 15 | class ItemHashmapInteractor implements InputInteractorInterface |
| 16 | { |
| 17 | public function supports(MetadataInterface $metadata): bool |
| 18 | { |
| 19 | return $metadata instanceof ItemHashmapMetadata; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * @param ItemHashmapMetadata $metadata |
| 24 | */ |
| 25 | public function interactWith( |
| 26 | MetadataInterface $metadata, |
| 27 | HelperSet $helperSet, |
| 28 | InputInterface $input, |
| 29 | OutputInterface $output, |
| 30 | ApieContext $context |
| 31 | ): mixed { |
| 32 | $helper = $helperSet->get('question'); |
| 33 | assert($helper instanceof QuestionHelper); |
| 34 | $apieInputHelper = $helperSet->get('apie'); |
| 35 | assert($apieInputHelper instanceof ApieInputHelper); |
| 36 | $question = new ConfirmationQuestion('Add a new item to the list? (yes/no): '); |
| 37 | $arrayType = $metadata->getArrayItemType(); |
| 38 | $result = []; |
| 39 | while ($helper->ask($input, $output, $question)) { |
| 40 | $key = $apieInputHelper->interactUsingTypehint( |
| 41 | ReflectionTypeFactory::createReflectionType('string'), |
| 42 | $input, |
| 43 | $output, |
| 44 | $context |
| 45 | ); |
| 46 | $result[$key] = $apieInputHelper->interactUsingMetadata( |
| 47 | $arrayType, |
| 48 | $input, |
| 49 | $output, |
| 50 | $context |
| 51 | ); |
| 52 | } |
| 53 | return $result; |
| 54 | } |
| 55 | } |