Completed
Push — master ( 7bf519...7113e6 )
by Emil
14s queued 13s
created

Client::curated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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