Endpoint   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 96
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A makeRequestUrl() 0 4 1
A getAll() 0 10 1
A getById() 0 10 1
A headers() 0 7 1
A withOrganization() 0 6 1
endpoint() 0 1 ?
1
<?php
2
3
namespace seregazhuk\Favro\Api\Endpoints;
4
5
use seregazhuk\Favro\Contracts\HttpClient;
6
7
abstract class Endpoint
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $rateLimitInfo;
13
14
    /**
15
     * @var array
16
     */
17
    protected $headers = [];
18
19
    /**
20
     * @var HttpClient
21
     */
22
    protected $http;
23
24
    /**
25
     * @var string
26
     */
27
    protected $organizationId;
28
29
    /**
30
     * @param HttpClient $http
31
     */
32
    public function __construct(HttpClient $http)
33
    {
34
        $this->http = $http;
35
    }
36
37
    /**
38
     * @param string $verb
39
     * @return string
40
     */
41
    public function makeRequestUrl($verb = '')
42
    {
43
        return "https://favro.com/api/v1/{$this->endpoint()}/$verb";
44
    }
45
46
    /**
47
     * @param array $params
48
     * @return array
49
     */
50
    public function getAll(array $params = [])
51
    {
52
        return $this
53
            ->http
54
            ->get(
55
                $this->makeRequestUrl(),
56
                $params,
57
                $this->headers()
58
            );
59
    }
60
61
    /**
62
     * @param string $id
63
     * @return array
64
     */
65
    public function getById($id)
66
    {
67
        return $this
68
            ->http
69
            ->get(
70
                $this->makeRequestUrl($id),
71
                [],
72
                $this->headers()
73
            );
74
    }
75
76
    /**
77
     * @return array
78
     */
79
    protected function headers()
80
    {
81
        return array_merge(
82
            ['organizationId' => $this->organizationId],
83
            $this->headers
84
        );
85
    }
86
87
    /**
88
     * @param string $organizationId
89
     * @return $this
90
     */
91
    public function withOrganization($organizationId)
92
    {
93
        $this->organizationId = $organizationId;
94
95
        return $this;
96
    }
97
98
    /**
99
     * @return string
100
     */
101
    abstract public function endpoint();
102
}
103