TestConnectionCommand::execute()   A
last analyzed

Complexity

Conditions 2
Paths 4

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 10
cts 10
cp 1
rs 9.584
c 0
b 0
f 0
cc 2
nc 4
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MovingImage\Bundle\VMProApiBundle\Command;
6
7
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
class TestConnectionCommand extends ContainerAwareCommand
12
{
13
    protected function configure(): void
14
    {
15
        $this
16 4
            ->setName('vmpro-api:test-connection')
17
            ->setDescription('Test connection with the Video Manager Pro API')
18 4
        ;
19 4
    }
20 4
21
    /**
22 4
     * Commandline utility to test whether the bundle can successfully
23
     * connect to the API.
24
     */
25
    protected function execute(InputInterface $input, OutputInterface $output): int
26
    {
27
        $container = $this->getContainer();
28
        $client = $container->get('vmpro_api.client');
29
        $vmId = $container->getParameter('vm_pro_api_default_vm_id');
30
31 4
        $output->writeln('');
32
33 4
        try {
34 4
            $client->getChannels($vmId)->getName();
35 4
            $output->writeln('<fg=green;options=bold> ✔ Connecting with the API succeeded.</>');
36
            $output->writeln('');
37 4
38
            return 0;
39
        } catch (\Exception $e) {
40 4
            $output->writeln('<bg=red;fg=white;options=bold> ✘ Connecting with the API failed..</>');
41 2
            $output->writeln('');
42 2
43
            return 1;
44 2
        }
45 2
    }
46
}
47