GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( d9c91f...37a03c )
by Casper
01:54 queued 11s
created

LanguagesClient   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 61.9 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 39
loc 63
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 19 19 2
A search() 20 20 2

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 NStack\Clients;
4
5
use NStack\Exceptions\FailedToParseException;
6
use NStack\Models\Language;
7
8
/**
9
 * Class LanguagesClient
10
 *
11
 * @package NStack\Clients
12
 * @author  Tiago Araujo <[email protected]>
13
 */
14
class LanguagesClient extends NStackClient
15
{
16
    /** @var string */
17
    protected $path = 'geographic/languages';
18
19
    /**
20
     * index
21
     *
22
     * @param int $page
23
     * @param int $limit
24
     * @return array
25
     * @throws FailedToParseException
26
     */
27 1 View Code Duplication
    public function index($page = 1, $limit = 500): array
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...
28
    {
29 1
        $response = $this->client->get(
30 1
            $this->buildPath($this->path)
31 1
            . '/?page=' . $page
32 1
            . '&limit=' . $limit
33
        );
34
35 1
        $contents = $response->getBody()->getContents();
36
37 1
        $data = json_decode($contents, true);
38
39 1
        $array = [];
40 1
        foreach ($data['data'] as $object) {
41 1
            $array[] = new Language($object);
42
        }
43
44 1
        return $array;
45
    }
46
47
    /**
48
     * search
49
     *
50
     * @param String $term
51
     * @param int $page
52
     * @param int $limit
53
     * @return array
54
     * @throws FailedToParseException
55
     */
56 1 View Code Duplication
    public function search(String $term, $page = 1, $limit = 500): array
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...
57
    {
58 1
        $response = $this->client->get($this->buildPath(
59 1
            $this->path
60 1
            . '/?search=' . $term
61 1
            . '&page=' . $page
62 1
            . '&limit=' . $limit
63
        ));
64
65 1
        $contents = $response->getBody()->getContents();
66
67 1
        $data = json_decode($contents, true);
68
69 1
        $array = [];
70 1
        foreach ($data['data'] as $object) {
71 1
            $array[] = new Language($object);
72
        }
73
74 1
        return $array;
75
    }
76
}