Completed
Push — master ( f20be9...689c32 )
by Christian
08:52
created

CreateEncodingCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 6

Test Coverage

Coverage 95.56%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
cbo 6
dl 0
loc 71
ccs 43
cts 45
cp 0.9556
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B configure() 0 24 1
B doExecuteCommand() 0 37 5
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
class CreateEncodingCommand extends CloudCommand
26
{
27
    /**
28
     * {@inheritDoc}
29
     */
30 7
    protected function configure()
31
    {
32 7
        $this->setName('panda:encoding:create');
33 7
        $this->setDescription('Create an encoding');
34 7
        $this->addArgument(
35 7
            'video-id',
36 7
            InputArgument::REQUIRED,
37 7
            'Id of the video being encoded'
38
        );
39 7
        $this->addOption(
40 7
            'profile-id',
41 7
            null,
42 7
            InputOption::VALUE_REQUIRED,
43 7
            'Id of the profile'
44
        );
45 7
        $this->addOption(
46 7
            'profile-name',
47 7
            null,
48 7
            InputOption::VALUE_REQUIRED,
49 7
            'A profile\'s name'
50
        );
51
52 7
        parent::configure();
53 7
    }
54
55
    /**
56
     * {@inheritDoc}
57
     */
58 6
    protected function doExecuteCommand(InputInterface $input, OutputInterface $output)
59
    {
60 6
        $profileId = $input->getOption('profile-id');
61 6
        $profileName = $input->getOption('profile-name');
62
63 6
        if (null !== $profileId && null === $profileName) {
64 3
            $video = new Video();
65 3
            $video->setId($input->getArgument('video-id'));
66 3
            $encoding = $this->getCloud($input)->createEncodingWithProfileId(
67
                $video,
68 3
                $profileId
69
            );
70 1
            $output->writeln(
71 1
                sprintf(
72 1
                    '<info>Successfully created encoding with id %s</info>',
73 1
                    $encoding->getId()
74
                )
75
            );
76 3
        } elseif (null === $profileId && null !== $profileName) {
77 1
            $video = new Video();
78 1
            $video->setId($input->getArgument('video-id'));
79 1
            $encoding = $this->getCloud($input)->createEncodingWithProfileName(
80
                $video,
81 1
                $profileName
82
            );
83 1
            $output->writeln(
84 1
                sprintf(
85 1
                    '<info>Successfully created encoding with id %s</info>',
86 1
                    $encoding->getId()
87
                )
88
            );
89
        } else {
90 2
            $output->writeln(
91 2
                '<error>Exactly one option of --profile-id or --profile-name must be given.</error>'
92
            );
93
        }
94 4
    }
95
}
96