ReleaseFilter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 22.06 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 15
loc 68
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\MusicBrainz;
6
use MusicBrainz\Release;
7
8
/**
9
 * This is the release filter and it contains
10
 * an array of valid argument types to be used
11
 * when querying the MusicBrainz web service.
12
 */
13
class ReleaseFilter extends AbstractFilter implements FilterInterface
14
{
15
    /**
16
     * @var array
17
     */
18
    protected $validArgTypes = array(
19
        'arid',
20
        'artist',
21
        'artistname',
22
        'asin',
23
        'barcode',
24
        'catno',
25
        'comment',
26
        'country',
27
        'creditname',
28
        'date',
29
        'discids',
30
        'discidsmedium',
31
        'format',
32
        'laid',
33
        'label',
34
        'lang',
35
        'mediums',
36
        'primarytype',
37
        'puid',
38
        'reid',
39
        'release',
40
        'releaseaccent',
41
        'rgid',
42
        'script',
43
        'secondarytype',
44
        'status',
45
        'tag',
46
        'tracks',
47
        'tracksmedium',
48
        'type'
49
    );
50
51
    /**
52
     * @return string
53
     */
54
    public function getEntity()
55
    {
56
        return 'release';
57
    }
58
59
    /**
60
     * @param array       $response
61
     * @param MusicBrainz $brainz
62
     *
63
     * @return array
64
     */
65 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...
66
    {
67
        $releases = array();
68
        if (isset($response['release'])) {
69
            foreach ($response['release'] as $release) {
70
                $releases[] = new Release($release, $brainz);
71
            }
72
        } elseif (isset($response['releases'])) {
73
            foreach ($response['releases'] as $release) {
74
                $releases[] = new Release($release, $brainz);
75
            }
76
        }
77
78
        return $releases;
79
    }
80
}
81