Passed
Push — feature/code-quality ( b3f671...a899ee )
by Oguzhan
05:01 queued 02:25
created

SearchTrackCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 14

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 15
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 20
loc 20
ccs 15
cts 15
cp 1
rs 9.4285
cc 2
eloc 14
nc 2
nop 2
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: oguzu
5
 * Date: 29-3-2017
6
 * Time: 16:11
7
 */
8
9
namespace Pbxg33k\MusicInfo\Command;
10
11
12
use Pbxg33k\MusicInfo\MusicInfo;
13
use Symfony\Component\Console\Helper\Table;
14
use Symfony\Component\Console\Input\InputArgument;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18 View Code Duplication
class SearchTrackCommand extends BaseCommand
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
{
20
    const COMMAND_NAME = 'search:track';
21
22
    const COMMAND_DESCRIPTION = 'Search a track on one or more services';
23
24
    /**
25
     * @var MusicInfo
26
     */
27
    protected $musicInfo;
28
29 2
    protected function configure()
30
    {
31 2
        $this
32 2
            ->addArgument('track', InputArgument::REQUIRED, 'Artist Name')
33 2
            ->addArgument('service', InputArgument::OPTIONAL, 'Service to use, default to all enabled');
34
35 2
        parent::configure(); // TODO: Change the autogenerated stub
36 2
    }
37
38 2
    public function execute(InputInterface $input, OutputInterface $output)
39
    {
40 2
        $service = ($input->getArgument('service') != '') ? $input->getArgument('service') : null;
41
42 2
        $searchResults = $this->musicInfo->doSearch($input->getArgument('track'), 'track', $service);
43
44 2
        $resultsTable = $this->generateTableForSearchResult(
45 2
            $searchResults, [
46 2
            'id'    => 'ID',
47 2
            'name'  => 'Name',
48 2
            'image' => 'Image URL',
49 2
            'length'=> 'Duration',
50 2
            'type'  => 'Type',
51 2
            'dataSource' => 'Source',
52
            'uri'   => 'URL'
53 2
            ], new Table($output)
54 2
        );
55
56 2
        $resultsTable->render();
57 2
    }
58
59
    /**
60
     * Set Music info property
61
     *
62
     * @param MusicInfo $musicInfo
63
     */
64 2
    public function setMusicInfo(MusicInfo $musicInfo)
65
    {
66 2
        $this->musicInfo = $musicInfo;
67 2
    }
68
}
69