Completed
Pull Request — develop (#13)
by Oguzhan
06:06 queued 02:55
created

SearchArtistCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
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
    protected function configure()
30
    {
31
        $this
32
            ->addArgument('artist', InputArgument::REQUIRED, 'Artist Name')
33
            ->addArgument('service', InputArgument::OPTIONAL, 'Service to use, default to all configured', null);
34
35
        parent::configure(); // TODO: Change the autogenerated stub
36
    }
37
38
    /**
39
     * @param InputInterface  $input
40
     * @param OutputInterface $output
41
     */
42
    protected function execute(InputInterface $input, OutputInterface $output)
43
    {
44
        $service = ($input->getArgument('service') != '') ? $input->getArgument('service') : null;
45
46
        $searchResults = $this->musicInfo->doSearch($input->getArgument('artist'), 'artist', $service);
47
48
        $resultsTable = $this->generateTableForSearchResult($searchResults, [
49
            'id'    => 'ID',
50
            'name'  => 'Name',
51
            'image' => 'Image URL',
52
            'type'  => 'Type',
53
            'dataSource' => 'Source',
54
            'uri'   => 'URL'
55
        ], new Table($output));
56
57
        $resultsTable->render();
58
    }
59
60
    /**
61
     * Set Music info property
62
     *
63
     * @param MusicInfo $musicInfo
64
     */
65
    public function setMusicInfo(MusicInfo $musicInfo)
66
    {
67
        $this->musicInfo = $musicInfo;
68
    }
69
}