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

SearchArtistCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 13

Duplication

Lines 19
Ratio 100 %

Code Coverage

Tests 14
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 19
loc 19
ccs 14
cts 14
cp 1
rs 9.4285
cc 2
eloc 13
nc 2
nop 2
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: oguzu
5
 * Date: 27-3-2017
6
 * Time: 16:50
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 SearchArtistCommand 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:artist';
21
22
    const COMMAND_DESCRIPTION = 'Search an artist 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('artist', InputArgument::REQUIRED, 'Artist Name')
33 2
            ->addArgument('service', InputArgument::OPTIONAL, 'Service to use, default to all enabled', null);
34
35 2
        parent::configure();
36 2
    }
37
38
    /**
39
     * @param InputInterface  $input
40
     * @param OutputInterface $output
41
     *
42
     * @return void
43
     */
44 2
    protected function execute(InputInterface $input, OutputInterface $output)
45
    {
46 2
        $service = ($input->getArgument('service') != '') ? $input->getArgument('service') : null;
47
48 2
        $searchResults = $this->musicInfo->doSearch($input->getArgument('artist'), 'artist', $service);
49
50 2
        $resultsTable = $this->generateTableForSearchResult(
51 2
            $searchResults, [
52 2
            'id'    => 'ID',
53 2
            'name'  => 'Name',
54 2
            'image' => 'Image URL',
55 2
            'type'  => 'Type',
56 2
            'dataSource' => 'Source',
57
            'uri'   => 'URL'
58 2
            ], new Table($output)
59 2
        );
60
61 2
        $resultsTable->render();
62 2
    }
63
64
    /**
65
     * Set Music info property
66
     *
67
     * @param MusicInfo $musicInfo
68
     */
69 2
    public function setMusicInfo(MusicInfo $musicInfo)
70
    {
71 2
        $this->musicInfo = $musicInfo;
72 2
    }
73
}
74