Test Failed
Push — master ( 628e98...a0d58b )
by Pieter
03:08
created

Search   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 84
Duplicated Lines 11.9 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 2
dl 10
loc 84
c 0
b 0
f 0
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A latitude() 0 6 1
A longitude() 0 6 1
A query() 0 6 1
A ip() 0 6 1
A granularity() 10 10 2
A accuracy() 0 6 1
A amount() 0 6 1
A containedWithin() 0 6 1
A streetAddress() 0 6 1
A callback() 0 6 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 declare(strict_types=1);
2
3
namespace PeeHaa\AsyncTwitter\Api\Request\Geo;
4
5
use PeeHaa\AsyncTwitter\Api\Request\BaseRequest;
6
7
class Search extends BaseRequest
8
{
9
    const METHOD   = 'GET';
10
    const ENDPOINT = '/geo/search.json';
11
12
    public function __construct()
13
    {
14
        parent::__construct(self::METHOD, self::ENDPOINT);
15
    }
16
17
    public function latitude(string $latitude): Search
18
    {
19
        $this->parameters['lat'] = $latitude;
20
21
        return $this;
22
    }
23
24
    public function longitude(string $longitude): Search
25
    {
26
        $this->parameters['long'] = $longitude;
27
28
        return $this;
29
    }
30
31
    public function query(string $query): Search
32
    {
33
        $this->parameters['query'] = $query;
34
35
        return $this;
36
    }
37
38
    public function ip(string $ip): Search
39
    {
40
        $this->parameters['ip'] = $ip;
41
42
        return $this;
43
    }
44
45 View Code Duplication
    public function granularity(string $granularity): Search
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...
46
    {
47
        if (!in_array($granularity, ['poi', 'neighborhood', 'city', 'admin', 'county'], true)) {
48
            throw new InvalidGranularityException();
49
        }
50
51
        $this->parameters['granularity'] = $granularity;
52
53
        return $this;
54
    }
55
56
    public function accuracy(string $accuracy): Search
57
    {
58
        $this->parameters['accuracy'] = $accuracy;
59
60
        return $this;
61
    }
62
63
    public function amount(int $amount): Search
64
    {
65
        $this->parameters['max_results'] = (string) $amount;
66
67
        return $this;
68
    }
69
70
    public function containedWithin(string $placeId): Search
71
    {
72
        $this->parameters['contained_within'] = $placeId;
73
74
        return $this;
75
    }
76
77
    public function streetAddress(string $address): Search
78
    {
79
        $this->parameters['attribute:street_address'] = $address;
80
81
        return $this;
82
    }
83
84
    public function callback(string $callback): Search
85
    {
86
        $this->parameters['callback'] = $callback;
87
88
        return $this;
89
    }
90
}
91