Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
89.47% |
17 / 19 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| DefaultObjectInteractor | |
89.47% |
17 / 19 |
|
50.00% |
1 / 2 |
5.03 | |
0.00% |
0 / 1 |
| supports | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| interactWith | |
88.89% |
16 / 18 |
|
0.00% |
0 / 1 |
4.02 | |||
| 1 | <?php |
| 2 | namespace Apie\Console\Helpers; |
| 3 | |
| 4 | use Apie\Console\ApieInputHelper; |
| 5 | use Apie\Console\Output\IndentedOutputDecorator; |
| 6 | use Apie\Core\Context\ApieContext; |
| 7 | use Apie\Core\Metadata\CompositeMetadata; |
| 8 | use Apie\Core\Metadata\MetadataInterface; |
| 9 | use Apie\TypeConverter\ReflectionTypeFactory; |
| 10 | use Symfony\Component\Console\Helper\HelperSet; |
| 11 | use Symfony\Component\Console\Input\InputInterface; |
| 12 | use Symfony\Component\Console\Output\OutputInterface; |
| 13 | |
| 14 | class DefaultObjectInteractor implements InputInteractorInterface |
| 15 | { |
| 16 | public function supports(MetadataInterface $metadata): bool |
| 17 | { |
| 18 | return $metadata instanceof CompositeMetadata; |
| 19 | } |
| 20 | public function interactWith( |
| 21 | MetadataInterface $metadata, |
| 22 | HelperSet $helperSet, |
| 23 | InputInterface $input, |
| 24 | OutputInterface $output, |
| 25 | ApieContext $context |
| 26 | ): mixed { |
| 27 | $apieInputHelper = $helperSet->get('apie'); |
| 28 | assert($apieInputHelper instanceof ApieInputHelper); |
| 29 | assert($metadata instanceof CompositeMetadata); |
| 30 | |
| 31 | $result = []; |
| 32 | foreach ($metadata->getHashmap() as $field => $fieldMeta) { |
| 33 | if (!$fieldMeta->isField()) { |
| 34 | continue; |
| 35 | } |
| 36 | $output->writeln('Field: ' . $field); |
| 37 | $typehint = $fieldMeta->getTypehint(); |
| 38 | if (!$typehint) { |
| 39 | $typehint = ReflectionTypeFactory::createReflectionType('mixed'); |
| 40 | } |
| 41 | $result[$field] = $apieInputHelper->interactUsingTypehint( |
| 42 | $typehint, |
| 43 | $input, |
| 44 | new IndentedOutputDecorator($output, 4), |
| 45 | $context |
| 46 | ); |
| 47 | } |
| 48 | return $result; |
| 49 | } |
| 50 | } |