ListEncodingsCommand   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
cbo 5
dl 0
loc 101
ccs 57
cts 57
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 30 1
B doExecuteCommand() 0 59 9
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\Helper\Table;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Input\InputOption;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
/**
20
 * Command for displaying lists of encodings.
21
 *
22
 * @author Christian Flothmann <[email protected]>
23
 */
24
final class ListEncodingsCommand extends CloudCommand
25
{
26
    protected static $defaultName = 'panda:encoding:list';
27
28
    /**
29
     * {@inheritDoc}
30
     */
31 7
    protected function configure()
32
    {
33 7
        $this->setDescription('Display a (optionally filtered) list of encodings');
34 7
        $this->addOption(
35 7
            'status',
36 7
            null,
37 7
            InputOption::VALUE_REQUIRED,
38 7
            'Filter by status (one of \'success\', \'fail\' or \'processing\')'
39
        );
40 7
        $this->addOption(
41 7
            'profile-id',
42 7
            null,
43 7
            InputOption::VALUE_REQUIRED,
44 7
            'Filter by a profile id'
45
        );
46 7
        $this->addOption(
47 7
            'profile-name',
48 7
            null,
49 7
            InputOption::VALUE_REQUIRED,
50 7
            'Filter by a profile name'
51
        );
52 7
        $this->addOption(
53 7
            'video-id',
54 7
            null,
55 7
            InputOption::VALUE_REQUIRED,
56 7
            'Filter by video id'
57
        );
58
59 7
        parent::configure();
60 7
    }
61
62
    /**
63
     * {@inheritDoc}
64
     */
65 6
    protected function doExecuteCommand(InputInterface $input, OutputInterface $output)
66
    {
67 6
        $filter = array();
68
69 6
        if (null !== $input->getOption('status')) {
70 1
            $filter['status'] = $input->getOption('status');
71
        }
72
73 6
        if (null !== $input->getOption('profile-id')) {
74 1
            $filter['profile_id'] = $input->getOption('profile-id');
75
        }
76
77 6
        if (null !== $input->getOption('profile-name')) {
78 1
            $filter['profile_name'] = $input->getOption('profile-name');
79
        }
80
81 6
        if (null !== $input->getOption('video-id')) {
82 1
            $filter['video_id'] = $input->getOption('video-id');
83
        }
84
85 6
        $encodings = $this->getCloud($input)->getEncodings($filter);
86
87 5
        if (count($encodings) > 0) {
88 5
            $table = new Table($output);
89 5
            $table->setHeaders(array(
90 5
                'encoding id',
91
                'video id',
92
                'profile id',
93
                'profile name',
94
                'encoding status',
95
            ));
96
97 5
            foreach ($encodings as $encoding) {
98 5
                if ($encoding->getStatus() == 'fail') {
99 5
                    $status = sprintf(
100 5
                        'fail (%s)',
101 5
                        $encoding->getErrorMessage()
102
                    );
103 5
                } elseif ($encoding->getStatus() == 'processing') {
104 5
                    $status = sprintf(
105 5
                        'processing (%d%%)',
106 5
                        $encoding->getEncodingProgress()
107
                    );
108
                } else {
109 5
                    $status = 'success';
110
                }
111
112 5
                $table->addRow(array(
113 5
                    $encoding->getId(),
114 5
                    $encoding->getVideoId(),
115 5
                    $encoding->getProfileId(),
116 5
                    $encoding->getProfileName(),
117 5
                    $status,
118
                ));
119
            }
120
121 5
            $table->render($output);
0 ignored issues
show
Unused Code introduced by
The call to Table::render() has too many arguments starting with $output.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
122
        }
123 5
    }
124
}
125