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

ReverseGeoCode   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 21.74 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A accuracy() 0 6 1
A granularity() 10 10 2
A amount() 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 ReverseGeoCode extends BaseRequest
8
{
9
    const METHOD   = 'GET';
10
    const ENDPOINT = '/geo/reverse_geocode.json';
11
12
    // we use string type declaration instead of float, because of precision platform independence
13
    public function __construct(string $latitude, string $longitude)
14
    {
15
        parent::__construct(self::METHOD, self::ENDPOINT);
16
17
        $this->parameters['lat']  = $latitude;
18
        $this->parameters['long'] = $longitude;
19
    }
20
21
    public function accuracy(string $accuracy): ReverseGeoCode
22
    {
23
        $this->parameters['accuracy'] = $accuracy;
24
25
        return $this;
26
    }
27
28 View Code Duplication
    public function granularity(string $granularity): ReverseGeoCode
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...
29
    {
30
        if (!in_array($granularity, ['poi', 'neighborhood', 'city', 'admin', 'county'], true)) {
31
            throw new InvalidGranularityException();
32
        }
33
34
        $this->parameters['granularity'] = $granularity;
35
36
        return $this;
37
    }
38
39
    public function amount(int $amount): ReverseGeoCode
40
    {
41
        $this->parameters['max_results'] = (string) $amount;
42
43
        return $this;
44
    }
45
46
    public function callback(string $callback): ReverseGeoCode
47
    {
48
        $this->parameters['callback'] = $callback;
49
50
        return $this;
51
    }
52
}
53