Completed
Push — master ( c6a286...b1bd72 )
by Sergey
07:08
created

Endpoint::setOrganizationId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace seregazhuk\Favro\Api\Endpoints;
4
5
use seregazhuk\Favro\Contracts\HttpClient;
6
7
class Endpoint
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $allowedMethods = [
13
        'getById',
14
        'getAll',
15
        'create',
16
        'update',
17
        'delete',
18
    ];
19
20
    /**
21
     * @var string
22
     */
23
    protected $endpoint;
24
25
    /**
26
     * @var array
27
     */
28
    protected $headers = [];
29
30
    /**
31
     * @var HttpClient
32
     */
33
    protected $http;
34
35
    /**
36
     * @var string
37
     */
38
    protected $organizationId;
39
40
    /**
41
     * @param HttpClient $http
42
     */
43
    public function __construct(HttpClient $http)
44
    {
45
        $this->http = $http;
46
    }
47
48
    /**
49
     * @param string $verb
50
     * @return string
51
     */
52
    public function makeRequestUrl($verb = '')
53
    {
54
        return "https://favro.com/api/v1/{$this->endpoint}/$verb";
55
    }
56
57
    /**
58
     * @param string $method
59
     * @return bool
60
     */
61
    public function isMethodAllowed($method)
62
    {
63
        return in_array($method, $this->allowedMethods);
64
    }
65
66
    /**
67
     * @return HttpClient
68
     */
69
    public function getHttp()
70
    {
71
        return $this->http;
72
    }
73
74
    /**
75
     * @param array $params
76
     * @return array
77
     */
78
    public function getAll(array $params = [])
79
    {
80
        return $this->getHttp()->get(
81
            $this->makeRequestUrl(), $params, $this->getHeaders()
82
        );
83
    }
84
85
    /**
86
     * @param string $id
87
     * @return array
88
     */
89
    public function getById($id)
90
    {
91
        return $this->getHttp()->get(
92
            $this->makeRequestUrl($id), [], $this->getHeaders()
93
        );
94
    }
95
96
    /**
97
     * @return array
98
     */
99
    protected function getHeaders()
100
    {
101
        return array_merge(
102
            $this->headers,
103
            ['organizationId' => $this->organizationId]
104
        );
105
    }
106
107
    /**
108
     * @param int $organizationId
109
     * @return $this
110
     */
111
    public function setOrganizationId($organizationId)
112
    {
113
        $this->organizationId = $organizationId;
0 ignored issues
show
Documentation Bug introduced by
The property $organizationId was declared of type string, but $organizationId is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
114
115
        return $this;
116
    }
117
}