Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
16 / 16 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ItemListInteractor | |
100.00% |
16 / 16 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| supports | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| interactWith | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\Console\Helpers; |
| 3 | |
| 4 | use Apie\Console\ApieInputHelper; |
| 5 | use Apie\Core\Context\ApieContext; |
| 6 | use Apie\Core\Metadata\ItemListMetadata; |
| 7 | use Apie\Core\Metadata\MetadataInterface; |
| 8 | use Symfony\Component\Console\Helper\HelperSet; |
| 9 | use Symfony\Component\Console\Helper\QuestionHelper; |
| 10 | use Symfony\Component\Console\Input\InputInterface; |
| 11 | use Symfony\Component\Console\Output\OutputInterface; |
| 12 | use Symfony\Component\Console\Question\ConfirmationQuestion; |
| 13 | |
| 14 | class ItemListInteractor implements InputInteractorInterface |
| 15 | { |
| 16 | public function supports(MetadataInterface $metadata): bool |
| 17 | { |
| 18 | return $metadata instanceof ItemListMetadata; |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * @param ItemListMetadata $metadata |
| 23 | */ |
| 24 | public function interactWith( |
| 25 | MetadataInterface $metadata, |
| 26 | HelperSet $helperSet, |
| 27 | InputInterface $input, |
| 28 | OutputInterface $output, |
| 29 | ApieContext $context |
| 30 | ): mixed { |
| 31 | $helper = $helperSet->get('question'); |
| 32 | assert($helper instanceof QuestionHelper); |
| 33 | $apieInputHelper = $helperSet->get('apie'); |
| 34 | assert($apieInputHelper instanceof ApieInputHelper); |
| 35 | $question = new ConfirmationQuestion('Add a new item to the list? (yes/no): '); |
| 36 | $arrayType = $metadata->getArrayItemType(); |
| 37 | $result = []; |
| 38 | while ($helper->ask($input, $output, $question)) { |
| 39 | $result[] = $apieInputHelper->interactUsingMetadata( |
| 40 | $arrayType, |
| 41 | $input, |
| 42 | $output, |
| 43 | $context |
| 44 | ); |
| 45 | } |
| 46 | return $result; |
| 47 | } |
| 48 | } |