diff --git a/src/Console/Command/InspectMethodCommand.php b/src/Console/Command/InspectMethodCommand.php index 9e35314..80f6fe1 100644 --- a/src/Console/Command/InspectMethodCommand.php +++ b/src/Console/Command/InspectMethodCommand.php @@ -6,6 +6,7 @@ use Soap\Engine\Metadata\Model\Method; use Soap\Wsdl\Console\Helper\ConfiguredLoader; use Soap\WsdlReader\Formatter\LongMethodFormatter; +use Soap\WsdlReader\Formatter\MetaTableFormatter; use Soap\WsdlReader\Metadata\Wsdl1MetadataProvider; use Soap\WsdlReader\Wsdl1Reader; use Symfony\Component\Console\Command\Command; @@ -17,7 +18,6 @@ use Symfony\Component\Console\Style\SymfonyStyle; use function Psl\Type\non_empty_string; use function Psl\Vec\filter; -use function Psl\Vec\map; final class InspectMethodCommand extends Command { @@ -56,13 +56,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int return self::FAILURE; } - $style->info('Methods:'); - $style->writeln( - map( - $detectedMethods, - static fn (Method $method) => ' > '.(new LongMethodFormatter())($method) - ) - ); + foreach ($detectedMethods as $detectedMethod) { + $style->title($detectedMethod->getName()); + $style->writeln(['> '.(new LongMethodFormatter())($detectedMethod), '']); + (new MetaTableFormatter($output))($detectedMethod->getMeta())->render(); + } return self::SUCCESS; } diff --git a/src/Console/Command/InspectTypeCommand.php b/src/Console/Command/InspectTypeCommand.php index cad30a4..4daaeda 100644 --- a/src/Console/Command/InspectTypeCommand.php +++ b/src/Console/Command/InspectTypeCommand.php @@ -6,6 +6,7 @@ use Soap\Engine\Metadata\Model\Type; use Soap\Wsdl\Console\Helper\ConfiguredLoader; use Soap\WsdlReader\Formatter\LongTypeFormatter; +use Soap\WsdlReader\Formatter\MetaTableFormatter; use Soap\WsdlReader\Metadata\Wsdl1MetadataProvider; use Soap\WsdlReader\Wsdl1Reader; use Symfony\Component\Console\Command\Command; @@ -54,9 +55,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int return self::FAILURE; } - $style->writeln( - $detectedTypes->map(static fn (Type $type) => ' > '.(new LongTypeFormatter())($type)) - ); + foreach ($detectedTypes as $detectedType) { + $style->title($detectedType->getName()); + $style->writeln(['> '.(new LongTypeFormatter())($detectedType), '']); + (new MetaTableFormatter($output))($detectedType->getXsdType()->getMeta())->render(); + } return self::SUCCESS; } diff --git a/src/Formatter/LongMethodFormatter.php b/src/Formatter/LongMethodFormatter.php index a062665..4ba66a9 100644 --- a/src/Formatter/LongMethodFormatter.php +++ b/src/Formatter/LongMethodFormatter.php @@ -19,7 +19,7 @@ public function __construct() public function __invoke(Method $method): string { return format( - '%s(%s): %s%s', + '%s(%s): %s', $method->getName(), implode(', ', $method->getParameters()->map( fn (Parameter $parameter): string => format( @@ -28,8 +28,7 @@ public function __invoke(Method $method): string $parameter->getName() ) )), - ($this->xsdTypeFormatter)($method->getReturnType()), - PHP_EOL. ' '.print_r($method->getMeta(), true) + ($this->xsdTypeFormatter)($method->getReturnType()) ); } } diff --git a/src/Formatter/MetaTableFormatter.php b/src/Formatter/MetaTableFormatter.php new file mode 100644 index 0000000..70fad74 --- /dev/null +++ b/src/Formatter/MetaTableFormatter.php @@ -0,0 +1,66 @@ +output); + $table + ->setHeaders(['Meta', 'Value']) + ->setRows($this->buildKeyPairs($object)); + + return $table; + } + + /** + * @return list + */ + private function buildKeyPairs(object $object): array + { + $rc = new ReflectionClass($object); + + return filter_nulls( + map( + $rc->getProperties(), + /** @return array{0: non-empty-string, 1: string}|null */ + function (ReflectionProperty $prop) use ($object): ?array { + $value = $this->tryStringifyValue($prop->getValue($object)); + if ($value === null) { + return null; + } + + return [$prop->getName(), $value]; + } + ) + ); + } + + private function tryStringifyValue(mixed $value): ?string + { + try { + return match (true) { + is_array($value) => json_encode($value, JSON_PRETTY_PRINT), + is_bool($value) => $value ? 'true' : 'false', + is_scalar($value) => (string)$value, + default => null, + }; + } catch (\Throwable) { + return null; + } + } +}