Passed
Push — master ( 5731b9...6612be )
by Jared
02:33
created

JCRequest::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 7
loc 7
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 4
crap 1
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
use JC\Enums\Method;
15
16
class JCRequest implements iJCRequest
17
{
18 6
    public static function request($method, $url, $options)
19
    {
20 6
        return new JCResponse((new Client())->request($method, $url, $options));
21
    }
22
23
    /**
24
     * @param $url
25
     * @param array $headers
26
     * @param array $params
27
     * @param array $options
28
     * @return JCResponse
29
     */
30 1
    public static function get($url, $params = [], $headers = [], $options = [])
31
    {
32 1
        return static::request(Method::GET, static::manipulateUrl($url, $params), [
33
            'headers' => $headers
34 1
        ]);
35
    }
36
37 1 View Code Duplication
    public static function post($url, $params = [], $headers = [], $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...
38
    {
39 1
        return static::request(Method::POST, $url, [
40 1
            'headers' => $headers,
41
            'form_params' => $params
42 1
        ]);
43
    }
44
45 1 View Code Duplication
    public static function put($url, $params = [], $headers = [], $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...
46
    {
47 1
        return static::request(Method::PUT, $url, [
48 1
            'headers' => $headers,
49
            'form_params' => $params
50 1
        ]);
51
    }
52
53 1 View Code Duplication
    public static function patch($url, $params = [], $headers = [], $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...
54
    {
55 1
        return static::request(Method::PATCH, $url, [
56 1
            'headers' => $headers,
57
            'form_params' => $params
58 1
        ]);
59
    }
60
61 1 View Code Duplication
    public static function delete($url, $params = [], $headers = [], $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...
62
    {
63 1
        return static::request(Method::DELETE, $url, [
64 1
            'headers' => $headers,
65 1
            'form_params' => $params
66 1
        ]);
67
    }
68
69 1
    public static function head($url, $params = [], $headers = [], $options = [])
70
    {
71 1
        return static::request(Method::HEAD, $url, [
72 1
            'headers' => $headers,
73 1
        ]);
74
    }
75
76
    /**
77
     * @param string $url
78
     * @param array $params
79
     * @return string
80
     */
81 1
    protected static function manipulateUrl($url, $params = [])
82
    {
83 1
        $urlObject = Url::parse($url);
84 1
        $queryData = array_merge($urlObject->query->getData(), $params);
85 1
        $urlObject->query->setData($queryData);
86
87 1
        return $urlObject->getUrl();
88
    }
89
}