SearchArtistCommand::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 0
Metric Value
dl 17
loc 17
ccs 12
cts 12
cp 1
rs 9.7
c 0
b 0
f 0
cc 2
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
class SearchArtistCommand extends BaseCommand
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 View Code Duplication
    protected function execute(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Duplication introduced by
This method 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...
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($searchResults, [
51 2
            'id'    => 'ID',
52 2
            'name'  => 'Name',
53 2
            'image' => 'Image URL',
54 2
            'type'  => 'Type',
55 2
            'dataSource' => 'Source',
56
            'uri'   => 'URL'
57 2
        ], new Table($output));
58
59 2
        $resultsTable->render();
60 2
    }
61
62
    /**
63
     * Set Music info property
64
     *
65
     * @param MusicInfo $musicInfo
66
     */
67
    public function setMusicInfo(MusicInfo $musicInfo)
68
    {
69
        $this->musicInfo = $musicInfo;
70
    }
71
}