Client   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 22.39 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 15
loc 67
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getClient() 0 13 2
A search() 8 8 1
A curated() 7 7 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
2
3
namespace Glooby\Pexels;
4
5
/**
6
 * @author Emil Kilhage <[email protected]>
7
 */
8
class Client
9
{
10
    /**
11
     * @var string
12
     */
13
    private $token;
14
15
    /**
16
     * @var \GuzzleHttp\Client
17
     */
18
    private $client;
19
20
    /**
21
     * @param string $token
22
     */
23
    public function __construct($token)
24
    {
25
        $this->token = $token;
26
    }
27
28
    /**
29
     * @return \GuzzleHttp\Client
30
     */
31
    private function getClient()
32
    {
33
        if (null === $this->client) {
34
            $this->client = new \GuzzleHttp\Client([
35
              'base_uri' => 'https://api.pexels.com/v1/',
36
              'headers' => [
37
                'Authorization' => $this->token
38
              ]
39
            ]);
40
        }
41
42
        return $this->client;
43
    }
44
45
    /**
46
     * @param string $query
47
     * @param int $size
48
     * @param int $page
49
     *
50
     * @return \GuzzleHttp\Message\ResponseInterface
51
     */
52 View Code Duplication
    public function search($query, $size = 15, $page = 1)
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...
53
    {
54
        return $this->getClient()->get('search?'.http_build_query([
55
            'query' => $query,
56
            'per_page' => $size,
57
            'page' => $page
58
          ]));
59
    }
60
61
    /**
62
     * @param int $size
63
     * @param int $page
64
     *
65
     * @return \GuzzleHttp\Message\ResponseInterface
66
     */
67 View Code Duplication
    public function curated($size = 15, $page = 1)
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...
68
    {
69
        return $this->getClient()->get('curated?'.http_build_query([
70
            'per_page' => $size,
71
            'page' => $page
72
          ]));
73
    }
74
}
75