Completed
Push — symfony-5 ( 5d6114...fa4e1a )
by Christian
03:47
created

CreateEncodingCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 18
cts 18
cp 1
rs 9.552
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the XabbuhPandaBundle package.
5
 *
6
 * (c) Christian Flothmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Xabbuh\PandaBundle\Command;
13
14
use Symfony\Component\Console\Input\InputArgument;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Input\InputOption;
17
use Symfony\Component\Console\Output\OutputInterface;
18
use Xabbuh\PandaClient\Model\Video;
19
20
/**
21
 * Command to create an encoding.
22
 *
23
 * @author Christian Flothmann <[email protected]>
24
 *
25
 * @final since 1.5
26
 */
27
class CreateEncodingCommand extends CloudCommand
28
{
29
    protected static $defaultName = 'panda:encoding:create';
30
31
    /**
32
     * {@inheritDoc}
33
     */
34 7
    protected function configure()
35
    {
36 7
        $this->setDescription('Create an encoding');
37 7
        $this->addArgument(
38 7
            'video-id',
39 7
            InputArgument::REQUIRED,
40 7
            'Id of the video being encoded'
41
        );
42 7
        $this->addOption(
43 7
            'profile-id',
44 7
            null,
45 7
            InputOption::VALUE_REQUIRED,
46 7
            'Id of the profile'
47
        );
48 7
        $this->addOption(
49 7
            'profile-name',
50 7
            null,
51 7
            InputOption::VALUE_REQUIRED,
52 7
            'A profile\'s name'
53
        );
54
55 7
        parent::configure();
56 7
    }
57
58
    /**
59
     * {@inheritDoc}
60
     */
61 6
    protected function doExecuteCommand(InputInterface $input, OutputInterface $output)
62
    {
63 6
        $profileId = $input->getOption('profile-id');
64 6
        $profileName = $input->getOption('profile-name');
65
66 6
        if (null !== $profileId && null === $profileName) {
67 3
            $video = new Video();
68 3
            $video->setId($input->getArgument('video-id'));
69 3
            $encoding = $this->getCloud($input)->createEncodingWithProfileId(
70 3
                $video,
71
                $profileId
72
            );
73 1
            $output->writeln(
74
                sprintf(
75 1
                    '<info>Successfully created encoding with id %s</info>',
76 1
                    $encoding->getId()
77
                )
78
            );
79 3
        } elseif (null === $profileId && null !== $profileName) {
80 1
            $video = new Video();
81 1
            $video->setId($input->getArgument('video-id'));
82 1
            $encoding = $this->getCloud($input)->createEncodingWithProfileName(
83 1
                $video,
84
                $profileName
85
            );
86 1
            $output->writeln(
87
                sprintf(
88 1
                    '<info>Successfully created encoding with id %s</info>',
89 1
                    $encoding->getId()
90
                )
91
            );
92
        } else {
93 2
            $output->writeln(
94 2
                '<error>Exactly one option of --profile-id or --profile-name must be given.</error>'
95
            );
96
        }
97 4
    }
98
}
99