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

SearchAlbumCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 50
ccs 22
cts 22
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
A execute() 0 19 2
A setMusicInfo() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: oguzu
5
 * Date: 1-4-2017
6
 * Time: 16:07
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 SearchAlbumCommand extends BaseCommand
19
{
20
    const COMMAND_NAME = 'search:album';
21
22
    const COMMAND_DESCRIPTION = 'Search an album 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('album', InputArgument::REQUIRED, 'Album name')
33 2
            ->addArgument('service', InputArgument::OPTIONAL, 'Service to use, default to all enabled');
34
35 2
        parent::configure();
36 2
    }
37
38 2
    protected function execute(InputInterface $input, OutputInterface $output)
39
    {
40 2
        $service = ($input->getArgument('service') != '') ? $input->getArgument('service') : null;
41
42 2
        $searchResult = $this->musicInfo->doSearch($input->getArgument('album'), 'album', $service);
43
44 2
        $resultsTable = $this->generateTableForSearchResult(
45 2
            $searchResult, [
46 2
            'id' => 'ID',
47 2
            'name' => 'Name',
48 2
            'type' => 'Type',
49 2
            'image' => 'Image',
50
            'dataSource' => 'Source'
51 2
            ], new Table($output)
52 2
        );
53
54 2
        $resultsTable->render();
55
56 2
    }
57
58
    /**
59
     * Set Music info property
60
     *
61
     * @param MusicInfo $musicInfo
62
     */
63 2
    public function setMusicInfo(MusicInfo $musicInfo)
64
    {
65 2
        $this->musicInfo = $musicInfo;
66 2
    }
67
}
68