Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| InspectPandaDocTemplateCommand | |
0.00% |
0 / 39 |
|
0.00% |
0 / 3 |
182 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| configure | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| execute | |
0.00% |
0 / 34 |
|
0.00% |
0 / 1 |
132 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Console; |
| 6 | |
| 7 | use App\Domain\Document\Service\PandaDocClientInterface; |
| 8 | use Symfony\Component\Console\Command\Command; |
| 9 | use Symfony\Component\Console\Input\InputArgument; |
| 10 | use Symfony\Component\Console\Input\InputInterface; |
| 11 | use Symfony\Component\Console\Output\OutputInterface; |
| 12 | |
| 13 | /** |
| 14 | * Inspect a PandaDoc template and print its fields, tokens, and roles. |
| 15 | * |
| 16 | * Usage: |
| 17 | * php bin/console.php pandadoc:inspect-template <templateId> |
| 18 | */ |
| 19 | final class InspectPandaDocTemplateCommand extends Command |
| 20 | { |
| 21 | public function __construct( |
| 22 | private readonly PandaDocClientInterface $pandaDocClient, |
| 23 | ) { |
| 24 | parent::__construct(); |
| 25 | } |
| 26 | |
| 27 | protected function configure(): void |
| 28 | { |
| 29 | parent::configure(); |
| 30 | |
| 31 | $this->setName('pandadoc:inspect-template'); |
| 32 | $this->setDescription('List the fields, tokens, and roles defined in a PandaDoc template'); |
| 33 | $this->addArgument('templateId', InputArgument::REQUIRED, 'The PandaDoc template UUID'); |
| 34 | } |
| 35 | |
| 36 | protected function execute(InputInterface $input, OutputInterface $output): int |
| 37 | { |
| 38 | /** @var string $templateId */ |
| 39 | $templateId = $input->getArgument('templateId'); |
| 40 | |
| 41 | $details = $this->pandaDocClient->inspectTemplate($templateId); |
| 42 | |
| 43 | $output->writeln(sprintf('<info>Template:</info> %s', $details->name)); |
| 44 | $output->writeln(sprintf('<info>ID:</info> %s', $details->id)); |
| 45 | $output->writeln(''); |
| 46 | |
| 47 | $output->writeln('<info>Recipient Roles</info>'); |
| 48 | if ($details->roles === []) { |
| 49 | $output->writeln(' (none defined)'); |
| 50 | } else { |
| 51 | foreach ($details->roles as $role) { |
| 52 | $output->writeln(' - ' . $role); |
| 53 | } |
| 54 | } |
| 55 | $output->writeln(''); |
| 56 | |
| 57 | $output->writeln(sprintf('<info>Tokens</info> (%d)', count($details->tokens))); |
| 58 | if ($details->tokens === []) { |
| 59 | $output->writeln(' (none defined)'); |
| 60 | } else { |
| 61 | foreach ($details->tokens as $token) { |
| 62 | $default = $token->defaultValue !== null && $token->defaultValue !== '' |
| 63 | ? sprintf(' = "%s"', $token->defaultValue) |
| 64 | : ''; |
| 65 | $output->writeln(sprintf(' - [%s]%s', $token->name, $default)); |
| 66 | } |
| 67 | } |
| 68 | $output->writeln(''); |
| 69 | |
| 70 | $output->writeln(sprintf('<info>Fields</info> (%d)', count($details->fields))); |
| 71 | if ($details->fields === []) { |
| 72 | $output->writeln(' (none defined)'); |
| 73 | } else { |
| 74 | foreach ($details->fields as $field) { |
| 75 | $assigned = $field->assignedTo !== null |
| 76 | ? sprintf(' [%s]', $field->assignedTo) |
| 77 | : ''; |
| 78 | $output->writeln(sprintf( |
| 79 | ' - %s (%s)%s', |
| 80 | $field->name !== '' ? $field->name : '(unnamed)', |
| 81 | $field->type, |
| 82 | $assigned, |
| 83 | )); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | return Command::SUCCESS; |
| 88 | } |
| 89 | } |