ArtistFilter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 28.85 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 15
loc 52
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntity() 0 4 1
B parseResponse() 15 15 5

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
namespace MusicBrainz\Filters;
4
5
use MusicBrainz\Artist;
6
use MusicBrainz\MusicBrainz;
7
8
/**
9
 * This is the artist filter and it contains
10
 * an array of valid argument types to be used
11
 * when querying the MusicBrainz web service.
12
 */
13
class ArtistFilter extends AbstractFilter implements FilterInterface
14
{
15
    /**
16
     * @var array
17
     */
18
    protected $validArgTypes = array(
19
        'arid',
20
        'artist',
21
        'artistaccent',
22
        'alias',
23
        'begin',
24
        'comment',
25
        'country',
26
        'end',
27
        'ended',
28
        'gender',
29
        'ipi',
30
        'sortname',
31
        'tag',
32
        'type'
33
    );
34
35
    /**
36
     * @return string
37
     */
38
    public function getEntity()
39
    {
40
        return 'artist';
41
    }
42
43
    /**
44
     * @param array       $response
45
     * @param MusicBrainz $brainz
46
     *
47
     * @return Artist[]
48
     */
49 View Code Duplication
    public function parseResponse(array $response, MusicBrainz $brainz)
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...
50
    {
51
        $artists = array();
52
        if (isset($response['artist'])) {
53
            foreach ($response['artist'] as $artist) {
54
                $artists[] = new Artist($artist, $brainz);
55
            }
56
        } elseif (isset($response['artists'])) {
57
            foreach ($response['artists'] as $artist) {
58
                $artists[] = new Artist($artist, $brainz);
59
            }
60
        }
61
62
        return $artists;
63
    }
64
}
65