RequestApi   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 74
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A post() 0 9 1
A delete() 0 9 1
A put() 0 9 1
A __construct() 0 3 1
A get() 0 9 1
1
<?php
2
3
4
namespace CaioLandgraf\Api;
5
6
7
/**
8
 * Class RequestApi
9
 * @package CaioLandgraf\Api
10
 */
11
class RequestApi extends Core
12
{
13
14
    /**
15
     * RequestApi constructor.
16
     * @param string $apiUrl
17
     */
18
    public function __construct(string $apiUrl)
19
    {
20
        parent::__construct($apiUrl);
21
    }
22
23
    /**
24
     * @param array $fields
25
     * @param string $endpoint
26
     * @return RequestApi
27
     */
28
    public function post(array $fields, string $endpoint = ""): RequestApi
29
    {
30
        $this->request(
31
            "POST",
32
            $endpoint,
33
            $fields
34
        );
35
36
        return $this;
37
    }
38
39
    /**
40
     * @param array $fields
41
     * @param string $endpoint
42
     * @return RequestApi
43
     */
44
    public function get(array $fields, string $endpoint = ""): RequestApi
45
    {
46
        $this->request(
47
            "GET",
48
            $endpoint,
49
            $fields
50
        );
51
52
        return $this;
53
    }
54
55
    /**
56
     * @param array $fields
57
     * @param string $endpoint
58
     * @return RequestApi
59
     */
60
    public function put(array $fields, string $endpoint = ""): RequestApi
61
    {
62
        $this->request(
63
            "PUT",
64
            $endpoint,
65
            $fields
66
        );
67
68
        return $this;
69
    }
70
71
    /**
72
     * @param array $fields
73
     * @param string $endpoint
74
     * @return RequestApi
75
     */
76
    public function delete(array $fields, string $endpoint = ""): RequestApi
77
    {
78
        $this->request(
79
            "DELETE",
80
            $endpoint,
81
            $fields
82
        );
83
84
        return $this;
85
    }
86
}