Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ListPandaDocTemplatesCommand
0.00% covered (danger)
0.00%
0 / 12
0.00% covered (danger)
0.00%
0 / 3
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 configure
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3declare(strict_types=1);
4
5namespace App\Console;
6
7use App\Domain\Document\Service\PandaDocClientInterface;
8use Symfony\Component\Console\Command\Command;
9use Symfony\Component\Console\Input\InputInterface;
10use Symfony\Component\Console\Output\OutputInterface;
11
12/**
13 * List PandaDoc templates available in the workspace.
14 *
15 * Usage:
16 *   php bin/console.php pandadoc:list-templates
17 */
18final class ListPandaDocTemplatesCommand extends Command
19{
20    public function __construct(
21        private readonly PandaDocClientInterface $pandaDocClient,
22    ) {
23        parent::__construct();
24    }
25
26    protected function configure(): void
27    {
28        parent::configure();
29
30        $this->setName('pandadoc:list-templates');
31        $this->setDescription('List PandaDoc templates available to the current API key');
32    }
33
34    protected function execute(InputInterface $input, OutputInterface $output): int
35    {
36        $templates = $this->pandaDocClient->listTemplates();
37
38        if ($templates === []) {
39            $output->writeln('<comment>No templates found.</comment>');
40
41            return Command::SUCCESS;
42        }
43
44        $output->writeln(sprintf('<info>Found %d template(s):</info>', count($templates)));
45        foreach ($templates as $id => $name) {
46            $output->writeln(sprintf('  %s  %s', $id, $name));
47        }
48
49        return Command::SUCCESS;
50    }
51}