Completed
Push — develop ( 149a62...e74e48 )
by Oguzhan
05:59 queued 02:54
created

SearchArtistCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 30.36 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 86.96%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 4
dl 17
loc 56
ccs 20
cts 23
cp 0.8696
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
A execute() 17 19 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(
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
    public function setMusicInfo(MusicInfo $musicInfo)
70
    {
71
        $this->musicInfo = $musicInfo;
72
    }
73
}
74