SearchArtistCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 31.48 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 17
loc 54
ccs 18
cts 21
cp 0.8571
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
A execute() 17 17 2
A setMusicInfo() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}