Passed
Push — master ( 4d1653...b0c9fc )
by Jared
03:43
created

JCRequest::patch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 1
nc 1
nop 4
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: jaredchu
5
 * Date: 31/05/2017
6
 * Time: 09:40
7
 */
8
9
namespace JC;
10
11
12
use GuzzleHttp\Client;
13
use Purl\Url;
14
15
class JCRequest implements iJCRequest
16
{
17
    /**
18
     * @param $url
19
     * @param array $headers
20
     * @param array $params
21
     * @param array $options
22
     * @return JCResponse
23
     */
24 View Code Duplication
    public static function get($url, $headers = [], $params = [], $options = [])
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...
25
    {
26
        $finalUrl = static::manipulateUrl($url, $params);
27
28
        $client = new Client();
29
        return new JCResponse($client->request('GET', $finalUrl, [
30
            'headers' => $headers
31
        ]));
32
    }
33
34 View Code Duplication
    public static function post($url, $headers = [], $params = [], $options = [])
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...
35
    {
36
        $client = new Client();
37
        return new JCResponse($client->request('POST', $url, [
38
            'headers' => $headers,
39
            'form_params' => $params
40
        ]));
41
    }
42
43
    public static function put($url, $headers, $params, $options)
44
    {
45
        // TODO: Implement put() method.
46
    }
47
48
    public static function head($url, $headers, $params, $options)
49
    {
50
        // TODO: Implement head() method.
51
    }
52
53
    public static function delete($url, $headers, $params, $options)
54
    {
55
        // TODO: Implement delete() method.
56
    }
57
58
59
    /**
60
     * @param string $url
61
     * @param array $params
62
     * @return string
63
     */
64
    protected static function manipulateUrl($url, $params = [])
65
    {
66
        $urlObject = Url::parse($url);
67
        $queryData = array_merge($urlObject->query->getData(), $params);
68
        $urlObject->query->setData($queryData);
69
70
        return $urlObject->getUrl();
71
    }
72
}